1 <?php namespace rpf\extension;
2
3 require_once __DIR__ . '/../../extensionModule.php';
4
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
24 class invoiceTextExport extends extensionModule
25 {
26 27 28
29 private static $format = ['zeroString' => 'Inklusive', 'discountPattern' => '$priceDefault // Abzgl. $discount Rabatt'];
30
31 public function __construct(extension &$system)
32 {
33 parent::__construct($system);
34 }
35
36 37 38 39 40 41
42 public function setFormat ($name, $value)
43 {
44 $this->format[$name] = $value;
45 }
46
47
48 49 50 51 52
53 public function getAllOrders()
54 {
55 $result = $this->system->orders->loadAll(['accounting' => 1])->getData();
56 foreach ($result as $row)
57 {
58 $priceMonth = 0;
59 foreach ($row['dispositions'] as $dispo)
60 {
61
62
63 $priceMonth += round($dispo['price']['unit_net'],2) * $dispo['amount'];
64 }
65 if ($priceMonth > 0)
66 {
67
68 $return[$row['ordnr']]['customerDisplayName'] = isset($row['cus_company']) && !empty($row['cus_company']) ? "{$row['cus_company']}<br>({$row['cus_last_name']}, {$row['cus_first_name']})" : "{$row['cus_last_name']}, {$row['cus_first_name']}";
69 $return[$row['ordnr']]['priceYear'] = self::getPriceFormatted($priceMonth * 12);
70 $return[$row['ordnr']]['priceMonth'] = self::getPriceFormatted($priceMonth);
71 }
72 }
73 return $return;
74 }
75
76 77 78 79 80 81
82 public function getAddress($ordNr)
83 {
84 $address = $this->system->orders->load($ordNr)->getData()[$ordNr]['customer']['adress']['inv'];
85 $return['invoiceAddressBlock'] = !empty($address['company']) ? $address['company']."\n" : '';
86 $return['invoiceAddressBlock'] .= "{$address['first_name']} {$address['last_name']}\n";
87 $return['invoiceAddressBlock'] .= !empty($address['adress_1']) ? $address['adress_1']."\n" : '';
88 $return['invoiceAddressBlock'] .= !empty($address['adress_2']) ? $address['adress_2']."\n" : '';
89 $return['invoiceAddressBlock'] .= !empty($address['zip']) ? $address['zip']." " : '';
90 $return['invoiceAddressBlock'] .= !empty($address['city']) ? $address['city']."\n" : '';
91 return $return;
92 }
93
94 95 96 97 98 99 100 101
102 public function getTariff($ordNr)
103 {
104 $dispos = $this->system->orders->load($ordNr)->getData()[$ordNr]['dispositions'];
105 foreach ($dispos as $row)
106 {
107 if ($row['product']['norm'] == 'tariff')
108 {
109 $return['name'] = $row['product']['name'];
110 $return['desc'] = $row['product']['descr'];
111 $return['priceFormatted'] = self::getPriceFormatted($row['price']['unit_net'], $row['price']['default_net']);
112 return (array) $return;
113 }
114 }
115 throw new \Exception ("OrderNr $ordNr doesn't exists or doesn't has a tariff", 404);
116 }
117
118 119 120 121 122 123 124
125 public function getDomains($ordNr)
126 {
127 $dispos = $this->system->orders->load($ordNr)->getData()[$ordNr]['dispositions'];
128 $sumPrice = 0;
129 $sumPriceDefault = 0;
130 $return['item'] = array();
131
132 foreach ($dispos as $row)
133 {
134 if ($row['product']['norm'] == 'domain')
135 {
136
137
138
139 $item['name'] = $row['descr'];
140 $item['priceFormatted'] = self::getPriceFormatted($row['price']['unit_net'], $row['price']['default_net']);
141 $sumPrice += round($row['price']['unit_net'], 2);
142 $sumPriceDefault += round($row['price']['default_net'],2);
143
144 if ($row['price']['unit_net'] == 0)
145 {
146 $freeOnTop[$row['descr']] = $item;
147 }
148 else
149 {
150 $return['item'][$row['descr']] = $item;
151 }
152 }
153 }
154 if (!empty($return['item']))
155 {
156 asort($return['item']);
157 }
158
159 if (!empty($freeOnTop))
160 {
161 asort($freeOnTop);
162 $return['item'] = array_merge($freeOnTop, $return['item']);
163 }
164
165 $return['amount'] = count($return['item']);
166 $return['priceFormatted'] = self::getPriceFormatted($sumPrice, $sumPriceDefault);
167
168 if ($return['amount'] == 0) $return['title'] = "Keine Domains reserviert";
169 else if ($return['amount'] == 1) $return['title'] = "Domain";
170 else $return['title'] = "{$return['amount']} Domains";
171
172 return (array) $return;
173 }
174
175
176 177 178 179 180 181 182
183 public function getAddOns($ordNr)
184 {
185 $dispos = $this->system->orders->load($ordNr)->getData()[$ordNr]['dispositions'];
186 $sumPrice = 0;
187 $sumPriceDefault = 0;
188 $return['item'] = array();
189
190 foreach ($dispos as $row) {
191 if ($row['product']['norm'] == 'add-on') {
192 $item['name'] = !empty($row['descr']) ? $row['descr'] : $row['product']['name'];
193 $item['desc'] = $row['product']['descr'];
194 $item['amount'] = $row['amount'];
195 $item['title'] = $item['amount'] > 1 ? "{$row['amount']}x {$item['name']}" : $item['name'];
196
197
198
199 $item['priceFormatted'] = self::getPriceFormatted($row['price']['unit_net'] * $row['amount'], $row['price']['default_net'] * $row['amount'], $row['can_account']);
200 $sumPrice += $row['price']['unit_net'] * $row['amount'];
201 $sumPriceDefault += $row['price']['default_net'] * $row['amount'];
202
203
204
205
206 $return['item'][$row['product']['pronr'].$row['odid']] = $item;
207 }
208 }
209 asort($return['item']);
210 return (array) $return;
211 }
212
213 214 215 216 217 218 219
220 public function getCertificates($ordNr)
221 {
222 $disposition = $this->system->orders->loadDisposition($ordNr)->getDisposition($ordNr);
223
224
225 $sumPrice = 0;
226 $sumPriceDefault = 0;
227 $return = array();
228
229 foreach ($disposition as $row)
230 {
231
232
233
234
235
236 if ($row['product']['norm'] == 'ext' && strpos($row['product']['pronr'], 'SSL_') === 0)
237 {
238
239
240
241
242 $regEx = "/(\\S*\\.\\S*\\.\\S*)/";
243 preg_match($regEx, $row['descr'], $domain);
244 $domain = $domain[1];
245
246 $return[$row['product']['pronr']]['item'][$domain]['name'] = $domain;
247
248
249
250 $return[$row['product']['pronr']]['item'][$domain]['priceFormatted'] = self::getPriceFormatted($row['price']['unit_net'], $row['price']['default_net']);
251
252 $tmp[$row['product']['pronr']]['sumPrice'] += $row['price']['unit_net'];
253 $tmp[$row['product']['pronr']]['sumPriceDefault'] += $row['price']['default_net'];
254 $tmp[$row['product']['pronr']]['amount'] = count($return[$row['product']['pronr']]['item']);
255
256 $return[$row['product']['pronr']]['title'] = $tmp[$row['product']['pronr']]['amount'] > 1 ? "{$tmp[$row['product']['pronr']]['amount']}x {$row['product']['name']}" : $row['product']['name'];
257 $return[$row['product']['pronr']]['desc'] = $row['product']['descr'];
258 $return[$row['product']['pronr']]['priceFormatted'] = self::getPriceFormatted($tmp[$row['product']['pronr']]['sumPrice'], $tmp[$row['product']['pronr']]['sumPriceDefault']);
259
260 asort($return[$row['product']['pronr']]['item']);
261 }
262 }
263
264
265 asort($return);
266 return (array) $return;
267 }
268
269
270 271 272 273 274 275 276
277 public function getExchangeAccounts($ordNr)
278 {
279 $dispos = $this->system->orders->load($ordNr)->getData()[$ordNr]['dispositions'];
280
281 $sumPrice = 0;
282 $sumPriceDefault = 0;
283 $return = array();
284
285 foreach ($dispos as $row)
286 {
287
288
289
290
291
292 if ($row['product']['norm'] == 'ext' && strpos($row['product']['pronr'], 'EXCHANGE_') === 0)
293 {
294 $pk = $row['descr'];
295
296 $return[$row['product']['pronr']]['item'][$pk]['name'] = $pk;
297
298
299
300 $return[$row['product']['pronr']]['item'][$pk]['priceFormatted'] = self::getPriceFormatted($row['price']['unit_net'], $row['price']['default_net']);
301
302 $tmp[$row['product']['pronr']]['sumPrice'] += $row['price']['unit_net'];
303 $tmp[$row['product']['pronr']]['sumPriceDefault'] += $row['price']['default_net'];
304 $tmp[$row['product']['pronr']]['amount'] = count($return[$row['product']['pronr']]['item']);
305
306 $return[$row['product']['pronr']]['title'] = $tmp[$row['product']['pronr']]['amount'] > 1 ? "{$tmp[$row['product']['pronr']]['amount']}x {$row['product']['name']}" : $row['product']['name'];
307 $return[$row['product']['pronr']]['desc'] = $row['product']['descr'];
308 $return[$row['product']['pronr']]['priceFormatted'] = self::getPriceFormatted($tmp[$row['product']['pronr']]['sumPrice'], $tmp[$row['product']['pronr']]['sumPriceDefault']);
309
310 asort($return[$row['product']['pronr']]['item']);
311 }
312 }
313 asort($return);
314 return (array) $return;
315 }
316
317
318 319 320 321 322 323 324 325
326 static function getEuroFormatted($price, $zeroString = 'Inklusive')
327 {
328 $price = round($price, 2);
329 return $price > 0 ? str_replace(',00', ',-', number_format($price, 2, ',', '.')).' €' : $zeroString;
330 }
331
332 333 334 335 336 337 338 339 340 341
342 static function getPriceFormatted($price, $priceDefault = NULL, $activeAccounting = 1)
343 {
344 $suffix = $activeAccounting == 0 ? ' !!INAKTIV!!' : '';
345
346 if (round($price,2) >= round($priceDefault,2))
347 {
348 return self::getEuroFormatted($price, "Inklusive$suffix");
349 }
350 else
351 {
352 $percent = 100 - 100 / round($priceDefault,2) * round($price,2);
353 if ($percent == 100 | $percent == 75 | $percent == 50 | $percent == 25 | $percent == 20 | $percent == 10)
354 {
355 $discount = "$percent%";
356
357 }
358 else
359 {
360 $discount = self::getEuroFormatted($priceDefault-$price);
361 }
362 $priceDefault = self::getEuroFormatted($priceDefault);
363 return "$priceDefault | Abzgl. $discount Rabatt$suffix";
364 }
365 }
366
367 }