Overview
  • Namespace
  • Class

Namespaces

  • rpf
    • api
      • module
    • extension
      • module
    • system
      • module

Classes

  • rpf\api\api
  • rpf\api\apiModule
  • rpf\api\bbRpc
  • rpf\api\module\bbCustomer_getFreeOrdNr
  • rpf\api\module\bbCustomer_readAddress
  • rpf\api\module\bbCustomer_readDiscount
  • rpf\api\module\bbCustomer_readEntry
  • rpf\api\module\bbCustomer_readPayment
  • rpf\api\module\bbCustomer_readTitle
  • rpf\api\module\bbCustomer_saveAdress
  • rpf\api\module\bbCustomer_validateAddress
  • rpf\api\module\bbCustomer_validateEntry
  • rpf\api\module\bbCustomer_validatePayinfo
  • rpf\api\module\bbDomain_readEntry
  • rpf\api\module\bbDomain_readFrontpage
  • rpf\api\module\bbDomain_readHandles
  • rpf\api\module\bbDomain_readPhpini
  • rpf\api\module\bbDomain_readSettings
  • rpf\api\module\bbDomain_readSubdomain
  • rpf\api\module\bbDomain_readWebalizerSettings
  • rpf\api\module\bbDomain_searchEntry
  • rpf\api\module\bbEmail_readAccount
  • rpf\api\module\bbMysql_inuseEntry
  • rpf\api\module\bbMysql_makeBackup
  • rpf\api\module\bbMysql_readEntry
  • rpf\api\module\bbOrder_readAccountAddress
  • rpf\api\module\bbOrder_readAccountEntry
  • rpf\api\module\bbOrder_readDisposition
  • rpf\api\module\bbOrder_readEntry
  • rpf\api\module\bbQuota_readEntry
  • rpf\api\module\customer
  • rpf\api\module\email
  • rpf\api\module\order
  • rpf\api\module\placeholder
  • rpf\api\module\user
  • rpf\extension\extension
  • rpf\extension\extensionModule
  • rpf\extension\invoiceTextExport
  • rpf\extension\mailExport
  • rpf\extension\module\domainExport
  • rpf\extension\module\index
  • rpf\extension\module\mgntRatioExport
  • rpf\system\module
  • rpf\system\module\log
  • rpf\system\module\moduleManager
  • rpf\system\rpf

Exceptions

  • rpf\system\module\exception
  1 <?php namespace rpf\extension;
  2 
  3 require_once __DIR__ . '/../../extensionModule.php';
  4 
  5 /**
  6  * Class invoiceTextExport
  7  *
  8  * This class provides methods to list all orders, each with customer-name, turnover per month and turnover per year.
  9  * Additionally it's able to show the invoice-address, the tariff and all positions, each with turnover per month.
 10  *
 11  * It is build to provide a copy-and-paste interface for all dispositions to bill the rp2-data in an external
 12  * program.
 13  *
 14  * @author Andreas Doebeling <ad@1601.com>
 15  * @copyright 1601.production siegler&thuemmler ohg
 16  * @link https://github.com/ADoebeling
 17  * @link http://xing.doebeling.de
 18  * @link https://www.1601.com
 19  *
 20  * @TODO Use bbOrder::readDisposition instead of readEntry to get so_type and clean prices #5401975
 21  *
 22  * @package system\extension
 23  */
 24 class invoiceTextExport extends extensionModule
 25 {
 26     /**
 27      * @var array format-pattern
 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      * Set format-pattern
 38      *
 39      * @param string $name
 40      * @param string $value
 41      */
 42     public function setFormat ($name, $value)
 43     {
 44         $this->format[$name] = $value;
 45     }
 46 
 47 
 48     /**
 49      * Returns all orders
 50      *
 51      * @return array [ $ordNr[ customerDisplayName, priceMonth, priceYear)
 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                 // Workaround against RP2-API-Bug #5402189:
 62                 // unit_net is is calculated wrong: round($rp2UserInputPrice*1.19, 2)/1.19
 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      * Returns the Invoice-Address as formatted string.
 78      *
 79      * @param string $ordNr
 80      * @return array
 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      * Returns the ordered tariff
 96      * (Doesn't takes care of validity period)
 97      *
 98      * @param string $ordNr
 99      * @return array [name, desc, priceFormatted]
100      * @throws \Exception
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      * Returns the ordered domains
120      * (Doesn't takes care of validity period)
121      *
122      * @param string $ordNr
123      * @return array [ title, amount, priceFormatted, item[ name, priceFormatted ] ]
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                 // Workaround against RP2-API-Bug #5401975
137                 // $row['product']['name'] is empty:
138                 // $return['name'] = $row['product']['name'];
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      * Returns the ordered AddOns
178      * (Doesn't takes care of validity period)
179      *
180      * @param string $ordNr
181      * @return array [ $pronr[ title, name, amount, desc, priceFormatted ] ]
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                 // Workaround against RP2-API-Bug #5402189:
198                 // unit_net is is calculated wrong: round($rp2UserInputPrice*1.19, 2)/1.19
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                 // We need the desc as key for correct sorting AND
204                 // need the disposition-id to prohibit overwritten positions
205                 // by multiple added positions.
206                 $return['item'][$row['product']['pronr'].$row['odid']] = $item;
207             }
208         }
209         asort($return['item']);
210         return (array) $return;
211     }
212 
213     /**
214      * Returns the ordered certificates
215      * (Doesn't takes care of validity period)
216      *
217      * @param string $ordNr
218      * @return array [ $type[ $domain[ title, amount, desc, priceFormatted, item[ name, priceFormatted ] ] ] ]
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             // Workaround against RP2-API-BUG #5402091:
232             // There is no [product][norm] for ssl-certificates
233             // U need to rename all ssl-certificates to SSL_foobar to get grabbed
234             // here correctly
235             // => readDispositions()
236             if ($row['product']['norm'] == 'ext' && strpos($row['product']['pronr'], 'SSL_') === 0)
237             {
238                 // Workaround against RP2-API-Bug #5402235:
239                 // There is no link between a ssl-certificate and the
240                 // Domain it is registered for
241                 // The only known way is to parse the domain out of the auto-generated desc
242                 $regEx = "/(\\S*\\.\\S*\\.\\S*)/"; // quick and dirty, i Know
243                 preg_match($regEx, $row['descr'], $domain);
244                 $domain = $domain[1];
245 
246                 $return[$row['product']['pronr']]['item'][$domain]['name'] = $domain;
247 
248                 // Workaround against RP2-API-Bug #5402189:
249                 // unit_net is is calculated wrong: round($rp2UserInputPrice*1.19, 2)/1.19
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      * Returns the ordered exchange-accounts
272      * (Doesn't takes care of evaluation/validity period)
273      *
274      * @param string $ordNr
275      * @return array [ type[ name, amount, desc, priceFormatted, item[ name, priceFormatted ] ] ]
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             // Workaround against RP2-API-BUG #5402091:
289             // There is no [product][norm] for exchange-accounts
290             // U need to rename all exchange-accounts to EXCHANGE_foobar to get grabbed
291             // here correctly
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                 // Workaround against RP2-API-Bug #5402189:
299                 // unit_net is is calculated wrong: round($rp2UserInputPrice*1.19, 2)/1.19
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      * Formats float into 12.345,67 � and integer into 12.345,- �
320      * Returns $zeroString if price is NULL
321      *
322      * @param float|int $price
323      * @param string $zeroString = Inklusive
324      * @return string (12.345,67 �|12.345,- �|Inklusive)
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, ',', '.')).' &euro;' : $zeroString;
330     }
331 
332     /**
333      * Formats $price and $priceDefault as invoice-string
334      *
335      * @param float $price
336      * @param float $priceDefault
337      * @param string $patternZero
338      * @param string $patternDiscount
339      * @param bool $activeAccounting
340      * @return string (12.345,67 �|12.345,- �|12.345,67 � // Abzgl. 1.345,- � Rabatt)
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                 //$discount = self::getEuroFormatted($priceDefault-$price);
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 }
API documentation generated by ApiGen