Subversion-Projekte lars-tiefland.ci

Revision

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