Subversion-Projekte lars-tiefland.ci

Revision

Revision 2314 | Revision 2316 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2243 lars 1
<?php
2
 
3
/**
4
 *
5
 * @package WebanOS CI
6
 * @author Lars Tiefland <ltiefland@gmail.com>
7
 * @copyright 2016
8
 * @version $Rev: 2315 $
9
 */
10
 
11
class Logistiker_model extends CI_Model
12
{
13
	public function __construct()
14
	{
15
		parent::__construct();
16
	}
17
 
18
	public function get_list($start = 0)
19
	{
2244 lars 20
		$sql = "SELECT
21
				*
22
			FROM
23
				logistiker
24
		";
2247 lars 25
		$res = $this->db->query($sql);
2244 lars 26
		while ($row = $res->unbuffered_row('array')) {
27
			$logistiker[] = $row;
28
		}
29
		return $logistiker;
2243 lars 30
	}
31
 
32
	public function get($id)
33
	{
2244 lars 34
		$sql = "SELECT
35
				*
36
			FROM
37
				logistiker
38
			WHERE
39
				id=" . $id . "
40
		";
2247 lars 41
		$res = $this->db->query($sql);
2244 lars 42
		$logistiker = $res->unbuffered_row('array');
43
		return $logistiker;
2243 lars 44
	}
45
 
46
	public function save()
47
	{
48
	}
2283 lars 49
 
2280 lars 50
	public function export($id)
51
	{
2309 lars 52
		$aColumns = array("exported");
2314 lars 53
		$sIndexColumn = "exported";
2313 lars 54
		$sLimit = $this->input->get('iDisplayStart') . "," . $this->input->get('iDisplayLength');
2286 lars 55
		$sQuery = "SELECT DISTINCT
56
                    exported
57
                FROM
58
                    artikel_to_Bestellung ab
59
                JOIN
60
                    bestellung_logistiker bl
61
                ON
62
                    bl.logistiker=$id
63
                AND
64
                    bl.bestellung = ab.Bestellung
65
                WHERE
66
                    exported
2283 lars 67
 
2314 lars 68
                " . $sWhere . "
69
                " . $sOrder . "
70
                LIMIT " . $sLimit . "
2286 lars 71
            ";
2310 lars 72
		trigger_error($sQuery);
2288 lars 73
		$rResult = $GLOBALS['order_db']->query($sQuery);
2286 lars 74
 
75
		/* Data set length after filtering */
76
		$sQuery = "
77
                        SELECT FOUND_ROWS() AS total
78
                ";
2288 lars 79
		$rResultFilterTotal = $GLOBALS['order_db']->query($sQuery);
2312 lars 80
		$aResultFilterTotal = $rResultFilterTotal->unbuffered_row('array');
2286 lars 81
		$iFilteredTotal = $aResultFilterTotal["total"];
82
 
83
		/* Total data set length */
84
		$sQuery = "
85
                        SELECT
86
                    COUNT(" . $sIndexColumn . ") AS total
87
                FROM
88
                    artikel_to_Bestellung ab
89
                JOIN
90
                    bestellung_logistiker bl
91
                ON
92
                    bl.logistiker=$id
93
                AND
94
                    bl.bestellung = ab.Bestellung
95
                WHERE
96
                    exported
97
                ";
2288 lars 98
		$rResultTotal = $GLOBALS['order_db']->query($sQuery);
2315 lars 99
		$aResultTotal = $rResultTotal->unbuffered_row('array');
2286 lars 100
		$iTotal = $aResultTotal["total"];
101
 
102
 
103
		/*
104
		* Output
105
		*/
106
		$output = array(
2310 lars 107
			"sEcho" => intval($ths->input->get('sEcho')),
2286 lars 108
			"iTotalRecords" => $iTotal,
109
			"iTotalDisplayRecords" => $iTotal,
110
			"aaData" => array());
111
 
112
		$sql = "SELECT
113
                    export_script
114
                FROM
115
                    logistiker
116
                WHERE
117
                    id = " . $id . "
118
            ";
2288 lars 119
		$res = $GLOBALS['order_db']->query($sql);
2286 lars 120
		$nrow = $res->unbuffered_row('array');
121
		if (strstr($nrow["export_script"], "=")) {
122
			$qs = explode(";", $nrow["export_script"]);
123
			foreach ($qs as $val) {
124
				list($key, $wert) = explode("=", $val);
125
				if ($key == "mode") {
126
					$qsArr[] = "mode=" . $wert;
127
				} elseif (is_null($wert)) {
128
					$script = $key;
129
				} elseif (!stristr($key, "status") && $wert) {
130
					$qsArr[] = "$key=" . $wert;
131
				}
132
			}
133
			$qs = implode("&", $qsArr);
134
		} else {
135
			list($script, $mode) = explode(";", $nrow["export_script"]);
136
			$qs = "mode=" . $mode;
137
		}
138
		while ($aRow = $rResult->unbuffered_row('array')) {
139
			$aRow['exported'] = '<a href="/Warenwirtschaft/' . $script . '?time=' . $aRow['exported'] .
140
				'&id=' . $id . '&' . $qs . '" target="_blank">' . date('d.m.Y H:i:s', strtotime
141
				($aRow['exported'])) . '</a>';
142
			$row = array();
143
			for ($i = 0; $i < count($aColumns); $i++) {
144
				if ($aColumns[$i] == "version") {
145
					/* Special output formatting for 'version' column */
146
					$row[] = ($aRow[$aColumns[$i]] == "0") ? '-' : $aRow[$aColumns[$i]];
147
				} else
148
					if ($aColumns[$i] != ' ') {
149
						/* General output */
150
						$row[] = $aRow[$aColumns[$i]];
151
					}
152
			}
153
			$output['aaData'][] = $row;
154
		}
155
 
156
		return json_encode($output);
2280 lars 157
	}
2283 lars 158
 
2280 lars 159
	public function tracking($id)
160
	{
2303 lars 161
		$aColumns = array(
162
			'paketnummer',
163
			'datum',
164
			'bestellung',
165
			);
2305 lars 166
		if (isset($_GET['iSortCol_0'])) {
167
			$sOrder = "ORDER BY  ";
168
			for ($i = 0; $i < intval($this->input->get('iSortingCols')); $i++) {
169
				if ($this->input->get('bSortable_' . intval($this->input->get('iSortCol_' . $i))) ==
170
					"true") {
171
					$sOrder .= $aColumns[intval($this->input->get('iSortCol_' . $i))] . "
2306 lars 172
                                    " . $this->input->get('sSortDir_' . $i) .
173
						", ";
2305 lars 174
				}
175
			}
176
 
177
			$sOrder = substr_replace($sOrder, "", -2);
178
			if ($sOrder == "ORDER BY") {
179
				$sOrder = "";
180
			}
181
		}
2285 lars 182
		$sWhere = "";
2287 lars 183
		if ($this->input->get('sSearch') != "") {
2285 lars 184
			$sWhere = "WHERE (";
185
			for ($i = 0; $i < count($aColumns); $i++) {
186
				if ($aColumns[$i] == "datum") {
187
					$a = " from_unixtime(datum) ";
2288 lars 188
					$sWhere .= $a . " LIKE '%" . $GLOBALS['order_db']->escape($this->input->get('sSearch')) .
2285 lars 189
						"%' OR ";
190
				} else {
2295 lars 191
					$sWhere .= $aColumns[$i] . " LIKE '%" . $GLOBALS['order_db']->escape($this->
192
						input->get('sSearch')) . "%' OR ";
2285 lars 193
				}
194
 
195
			}
196
			$sWhere = substr_replace($sWhere, "", -3);
197
			$sWhere .= ')';
2280 lars 198
		}
2285 lars 199
 
200
		/* Individual column filtering */
201
		for ($i = 0; $i < count($aColumns); $i++) {
2287 lars 202
			if ($this->input->get('bSearchable_' . $i) == "true" && $this->input->get('sSearch_' .
203
				$i) != '') {
2285 lars 204
				if ($sWhere == "") {
205
					$sWhere = "WHERE ";
206
				} else {
207
					$sWhere .= " AND ";
208
				}
209
				if ($aColumns[$i] == "datum") {
210
					$r = " from_unixtime(datum) ";
2288 lars 211
					$sWhere .= $r . " LIKE '%" . $GLOBALS['order_db']->escape($this->input->get('sSearch_' .
2287 lars 212
						$i)) . "%' ";
2285 lars 213
				} else {
2288 lars 214
					$sWhere .= $r . " LIKE '%" . $GLOBALS['order_db']->escape($this->input->get('sSearch_' .
2287 lars 215
						$i)) . "%' ";
2285 lars 216
				}
217
 
218
			}
219
		}
220
 
221
		if (empty($sWhere)) {
222
			$sWhere = " where bp.logistiker=l.id AND l.id = $id ";
223
		} else {
224
			$sWhere = " $sWhere and bp.logistiker=l.id AND l.id = $id ";
225
		}
2297 lars 226
		$sLimit = $this->input->get('iDisplayStart') . "," . $this->input->get('iDisplayLength');
2285 lars 227
		$sQuery = "SELECT
228
                    SQL_CALC_FOUND_ROWS
229
                    bp.*,
230
                    l.kname,
231
                    l.trackinglink
232
                FROM
233
                    logistiker l,
234
                    bestellung_paketnummern bp
2297 lars 235
                    " . $sWhere . "
236
                    " . $sOrder . "
2298 lars 237
					LIMIT " . $sLimit . "
2285 lars 238
                ";
239
		//echo $sQuery;
2288 lars 240
		$rResult = $GLOBALS['order_db']->query($sQuery);
2285 lars 241
 
242
		/* Data set length after filtering */
243
		$sQuery = "
244
                        SELECT FOUND_ROWS() AS total
245
                ";
2288 lars 246
		$rResultFilterTotal = $GLOBALS['order_db']->query($sQuery);
2289 lars 247
		$aResultFilterTotal = $rResultFilterTotal->unbuffered_row('array');
2285 lars 248
		$iFilteredTotal = $aResultFilterTotal["total"];
249
 
250
		/* Total data set length */
251
		$sQuery = "
252
                        SELECT
2292 lars 253
                    COUNT(bp.id) AS total
2285 lars 254
                FROM
255
                    logistiker l,
256
                    bestellung_paketnummern bp
257
                WHERE
258
                    bp.logistiker=l.id
259
                AND
260
                    l.id = $id
261
                ";
262
 
263
 
2288 lars 264
		$rResultTotal = $GLOBALS['order_db']->query($sQuery);
2294 lars 265
		$aResultTotal = $rResultTotal->unbuffered_row('array');
2285 lars 266
		$iTotal = $aResultTotal["total"];
267
 
268
 
269
		/*
270
		* Output
271
		*/
272
		$output = array(
2286 lars 273
			"sEcho" => intval($this->input->get('sEcho')),
2285 lars 274
			"iTotalRecords" => $iTotal,
275
			"iTotalDisplayRecords" => $iFilteredTotal,
276
			"aaData" => array());
277
 
278
		while ($aRow = $rResult->unbuffered_row('array')) {
279
			//$aRow['datum'] = strtotime($aRow['datum']);
280
			$aRow['datum'] = date('d.m.Y', $aRow['datum']);
2308 lars 281
			$aRow['bestellung'] = ' <a target="_blank" href="/backend/order/edit/' . $aRow['bestellung'] .
2307 lars 282
				'">zum Vorgang</a>';
2285 lars 283
 
284
			$url = $aRow["trackinglink"];
285
			if (stristr($url, "%")) {
286
				$tag = date("d", $row_p["datum"]);
287
				$monat = date("m", $row_p["datum"]);
288
				$jahr = date("Y", $row_p["datum"]);
289
				$url = str_replace("%tag%", $tag, $url);
290
				$url = str_replace("%monat%", $monat, $url);
291
				$url = str_replace("%jahr%", $jahr, $url);
292
				$url = str_replace("%trackingnr%", $aRow["paketnummer"], $url);
293
			} else {
294
				$url .= $aRow["paketnummer"];
295
			}
296
 
297
 
298
			$aRow["paketnummer"] = $aRow["kname"] . ': <a href=' . $url . ' target=_blank>' .
299
				$aRow["paketnummer"] . '</a>';
300
			$row = array();
301
			for ($i = 0; $i < count($aColumns); $i++)
302
				if ($aColumns[$i] == "version") {
303
					/* Special output formatting for 'version' column */
304
					$row[] = ($aRow[$aColumns[$i]] == "0") ? '-' : $aRow[$aColumns[$i]];
305
				} else
306
					if ($aColumns[$i] != ' ') {
307
						/* General output */
308
						$row[] = $aRow[$aColumns[$i]];
309
					}
2304 lars 310
			$output['aaData'][] = $row;
2285 lars 311
		}
312
 
313
		return json_encode($output);
2280 lars 314
	}
2285 lars 315
 
2243 lars 316
}
317
 
318
?>