Subversion-Projekte lars-tiefland.ci

Revision

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