Subversion-Projekte lars-tiefland.ci

Revision

Revision 2296 | Revision 2298 | 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: 2297 $
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 . "
215
					" . $sLimit . "
2285 lars 216
                ";
217
		//echo $sQuery;
2288 lars 218
		$rResult = $GLOBALS['order_db']->query($sQuery);
2285 lars 219
 
220
		/* Data set length after filtering */
221
		$sQuery = "
222
                        SELECT FOUND_ROWS() AS total
223
                ";
2288 lars 224
		$rResultFilterTotal = $GLOBALS['order_db']->query($sQuery);
2289 lars 225
		$aResultFilterTotal = $rResultFilterTotal->unbuffered_row('array');
2285 lars 226
		$iFilteredTotal = $aResultFilterTotal["total"];
227
 
228
		/* Total data set length */
229
		$sQuery = "
230
                        SELECT
2292 lars 231
                    COUNT(bp.id) AS total
2285 lars 232
                FROM
233
                    logistiker l,
234
                    bestellung_paketnummern bp
235
                WHERE
236
                    bp.logistiker=l.id
237
                AND
238
                    l.id = $id
239
                ";
240
 
241
 
2288 lars 242
		$rResultTotal = $GLOBALS['order_db']->query($sQuery);
2294 lars 243
		$aResultTotal = $rResultTotal->unbuffered_row('array');
2285 lars 244
		$iTotal = $aResultTotal["total"];
245
 
246
 
247
		/*
248
		* Output
249
		*/
250
		$output = array(
2286 lars 251
			"sEcho" => intval($this->input->get('sEcho')),
2285 lars 252
			"iTotalRecords" => $iTotal,
253
			"iTotalDisplayRecords" => $iFilteredTotal,
254
			"aaData" => array());
255
 
256
		while ($aRow = $rResult->unbuffered_row('array')) {
257
 
258
			//$aRow['datum'] = strtotime($aRow['datum']);
259
			$aRow['datum'] = date('d.m.Y', $aRow['datum']);
260
			$aRow['bestellung'] = ' <a href="/Warenwirtschaft/bestellungen.php?Bestellung=' .
261
				$aRow['bestellung'] . '">zum Vorgang</a>';
262
 
263
			$url = $aRow["trackinglink"];
264
			if (stristr($url, "%")) {
265
				$tag = date("d", $row_p["datum"]);
266
				$monat = date("m", $row_p["datum"]);
267
				$jahr = date("Y", $row_p["datum"]);
268
				$url = str_replace("%tag%", $tag, $url);
269
				$url = str_replace("%monat%", $monat, $url);
270
				$url = str_replace("%jahr%", $jahr, $url);
271
				$url = str_replace("%trackingnr%", $aRow["paketnummer"], $url);
272
			} else {
273
				$url .= $aRow["paketnummer"];
274
			}
275
 
276
 
277
			$aRow["paketnummer"] = $aRow["kname"] . ': <a href=' . $url . ' target=_blank>' .
278
				$aRow["paketnummer"] . '</a>';
279
			$row = array();
280
			for ($i = 0; $i < count($aColumns); $i++)
281
				if ($aColumns[$i] == "version") {
282
					/* Special output formatting for 'version' column */
283
					$row[] = ($aRow[$aColumns[$i]] == "0") ? '-' : $aRow[$aColumns[$i]];
284
				} else
285
					if ($aColumns[$i] != ' ') {
286
						/* General output */
287
						$row[] = $aRow[$aColumns[$i]];
288
					}
289
		}
290
		$output['aaData'][] = $row;
291
 
292
		return json_encode($output);
2280 lars 293
	}
2285 lars 294
 
2243 lars 295
}
296
 
297
?>