ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPurchaseBillGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
32 include_once './payment/classes/class.ilPaymentShoppingCart.php';
33 include_once './payment/classes/class.ilPaymentShoppingCartGUI.php';
34 include_once './payment/classes/class.ilPaymentCoupons.php';
35 
37 {
38  var $ctrl;
39  var $tpl;
40 
41  var $psc_obj = null;
42  var $user_obj = null;
43 
44  var $coupon_obj = null;
45  var $error;
46 
47  private $totalVat = 0;
48 
50  {
51  global $ilias, $ilDB, $lng, $tpl, $rbacsystem, $ilCtrl, $ilTabs;
52 
53  $this->ilias = $ilias;
54  $this->db = $ilDB;
55  $this->lng = $lng;
56  $this->ctrl = $ilCtrl;
57  $this->tpl = $tpl;
58 
59  // $this->psc_obj =& new ilPaymentShoppingCart($this->user_obj);
60  // Get user object
61  $this->user_obj = $user_obj;
62 
63 
64  $this->coupon_obj = new ilPaymentCoupons($this->user_obj);
65 
66  if (!is_array($_SESSION['bill']['personal_data']))
67  {
68  $_SESSION['bill']['personal_data']['firstname'] = $this->user_obj->getFirstname();
69  $_SESSION['bill']['personal_data']['lastname'] = $this->user_obj->getLastname();
70  if (strpos('_' . $this->user_obj->getStreet(), ' ') > 0)
71  {
72  $houseNo = substr($this->user_obj->getStreet(), strrpos($this->user_obj->getStreet(), ' ')+1);
73  $street = substr($this->user_obj->getStreet(), 0, strlen($this->user_obj->getStreet())-(strlen($houseNo)+1));
74  $_SESSION['bill']['personal_data']['street'] = $street;
75  $_SESSION['bill']['personal_data']['house_number'] = $houseNo;
76  }
77  else
78  {
79  $_SESSION['bill']['personal_data']['street'] = $this->user_obj->getStreet();
80  $_SESSION['bill']['personal_data']['house_number'] = '';
81  }
82  $_SESSION['bill']['personal_data']['po_box'] = '';
83  $_SESSION['bill']['personal_data']['zipcode'] = $this->user_obj->getZipcode();
84  $_SESSION['bill']['personal_data']['city'] = $this->user_obj->getCity();
85  $_SESSION['bill']['personal_data']['country'] = $this->__getCountryCode($this->user_obj->getCountry());
86  $_SESSION['bill']['personal_data']['email'] = $this->user_obj->getEmail();
87  $_SESSION['bill']['personal_data']['language'] = $this->user_obj->getLanguage();
88  }
89 
90  if (!is_array($_SESSION['coupons']['bill']))
91  {
92  $_SESSION['coupons']['bill'] = array();
93  }
94 
95  $this->__loadTemplate();
96  $this->error = '';
97  $this->lng->loadLanguageModule('payment');
98 
99  $ilTabs->clearTargets();
100  $ilTabs->clearSubTabs();
101  }
102 
103  function cancel()
104  {
105  ilUtil::redirect('./payment.php');
106  }
107 
108  function showPersonalData()
109  {
110  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
111 
112  if(!count($items = $this->psc_obj->getEntries(PAY_METHOD_BILL)))
113  {
114  $this->tpl->setVariable('HEADER',$this->lng->txt('pay_bmf_your_order'));
115  $this->tpl->touchBlock('stop_floating');
116  ilUtil::sendInfo($this->lng->txt('pay_shopping_cart_empty'));
117  }
118  else
119  {
120  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.pay_bmf_personal_data.html','payment');
121 
122  $this->tpl->setVariable('PERSONAL_DATA_FORMACTION',$this->ctrl->getFormAction($this));
123 
124  // set table header
125  $this->tpl->setVariable('TYPE_IMG',ilUtil::getImagePath('icon_pays_b.gif'));
126  $this->tpl->setVariable('ALT_IMG',$this->lng->txt('obj_usr'));
127  //$this->tpl->setVariable('HEADER',$this->lng->txt('pay_step1'));
128  $this->tpl->setVariable('HEADER',$this->lng->txt('pay_bmf_your_order'));
129  $this->tpl->setVariable('TITLE',$this->lng->txt('pay_bmf_personal_data'));
130  $this->tpl->setVariable('DESCRIPTION',$this->lng->txt('pay_bmf_description_personal_data'));
131  $this->tpl->touchBlock('stop_floating');
132  $this->tpl->setVariable('TXT_CLOSE_WINDOW',$this->lng->txt('close_window'));
133 
134  // set plain text variables
135  $this->tpl->setVariable('TXT_FIRSTNAME',$this->lng->txt('firstname'));
136  $this->tpl->setVariable('TXT_LASTNAME',$this->lng->txt('lastname'));
137  $this->tpl->setVariable('TXT_STREET',$this->lng->txt('street'));
138  $this->tpl->setVariable('TXT_HOUSE_NUMBER',$this->lng->txt('pay_bmf_house_number'));
139  $this->tpl->setVariable('TXT_OR',$this->lng->txt('pay_bmf_or'));
140  $this->tpl->setVariable('TXT_PO_BOX',$this->lng->txt('pay_bmf_po_box'));
141  $this->tpl->setVariable('TXT_ZIPCODE',$this->lng->txt('zipcode'));
142  $this->tpl->setVariable('TXT_CITY',$this->lng->txt('city'));
143  $this->tpl->setVariable('TXT_COUNTRY',$this->lng->txt('country'));
144  $this->tpl->setVariable('TXT_EMAIL',$this->lng->txt('email'));
145 
146  $this->tpl->setVariable('INPUT_VALUE',ucfirst($this->lng->txt('next')));
147  $this->tpl->setVariable('CANCEL',$this->lng->txt('cancel'));
148 
149  // fill defaults
150 
151  $this->error != '' && isset($_POST['country']) ? $this->__showCountries($this->tpl, $_POST['country'])
152  : $this->__showCountries($this->tpl, $_SESSION['bill']['personal_data']['country']);
153  $this->tpl->setVariable('FIRSTNAME', $this->user_obj->getFirstname());
154  $this->tpl->setVariable('LASTNAME', $this->user_obj->getLastname());
155  $this->tpl->setVariable('STREET',
156  $this->error != '' && isset($_POST['street'])
157  ? ilUtil::prepareFormOutput($_POST['street'],true)
158  : ilUtil::prepareFormOutput($_SESSION['bill']['personal_data']['street'],true));
159  $this->tpl->setVariable('HOUSE_NUMBER',
160  $this->error != '' && isset($_POST['house_number'])
161  ? ilUtil::prepareFormOutput($_POST['house_number'],true)
162  : ilUtil::prepareFormOutput($_SESSION['bill']['personal_data']['house_number'],true));
163  $this->tpl->setVariable('PO_BOX',
164  $this->error != '' && isset($_POST['po_box'])
165  ? ilUtil::prepareFormOutput($_POST['po_box'],true)
166  : ilUtil::prepareFormOutput($_SESSION['bill']['personal_data']['po_box'],true));
167  $this->tpl->setVariable('ZIPCODE',
168  $this->error != '' && isset($_POST['zipcode'])
169  ? ilUtil::prepareFormOutput($_POST['zipcode'],true)
170  : ilUtil::prepareFormOutput($_SESSION['bill']['personal_data']['zipcode'],true));
171  $this->tpl->setVariable('CITY',
172  $this->error != '' && isset($_POST['city'])
173  ? ilUtil::prepareFormOutput($_POST['city'],true)
174  : ilUtil::prepareFormOutput($_SESSION['bill']['personal_data']['city'],true));
175  $this->tpl->setVariable('EMAIL', $this->user_obj->getEmail());
176 
177  }
178  }
179 
180  function getPersonalData()
181  {
182 
183  if ($_SESSION['bill']['personal_data']['firstname'] == '' ||
184  $_SESSION['bill']['personal_data']['lastname'] == '' ||
185  $_POST['zipcode'] == '' ||
186  $_POST['city'] == '' ||
187  $_POST['country'] == '' ||
188  $_SESSION['bill']['personal_data']['email'] == '')
189  {
190 
191  $this->error = $this->lng->txt('pay_bmf_personal_data_not_valid');
192  ilUtil::sendInfo($this->error);
193  $this->showPersonalData();
194  return;
195  }
196 
197  if (($_POST['street'] == '' && $_POST['house_number'] == '' && $_POST['po_box'] == '') ||
198  (($_POST['street'] != '' || $_POST['house_number'] != '') && $_POST['po_box'] != '') ||
199  ($_POST['street'] != '' && $_POST['house_number'] == '') ||
200  ($_POST['street'] == '' && $_POST['house_number'] != ''))
201  {
202  $this->error = $this->lng->txt('pay_bmf_street_or_pobox');
203  ilUtil::sendInfo($this->error);
204  $this->showPersonalData();
205  return;
206  }
207 
208  $_SESSION['bill']['personal_data']['firstname'] = $this->user_obj->getFirstname();
209  $_SESSION['bill']['personal_data']['lastname'] = $this->user_obj->getLastname();
210  $_SESSION['bill']['personal_data']['street'] = $_POST['street'];
211  $_SESSION['bill']['personal_data']['house_number'] = $_POST['house_number'];
212  $_SESSION['bill']['personal_data']['po_box'] = $_POST['po_box'];
213  $_SESSION['bill']['personal_data']['zipcode'] = $_POST['zipcode'];
214  $_SESSION['bill']['personal_data']['city'] = $_POST['city'];
215  $_SESSION['bill']['personal_data']['country'] = $_POST['country'];
216 
217  $_SESSION['bill']['personal_data']['email'] = $this->user_obj->getEmail();
218  $_SESSION['bill']['personal_data']['language'] = $this->user_obj->getLanguage();
219 
220  $this->error = '';
221  $this->showBillConfirm();
222 
223  }
224 
225  function showBillConfirm()
226  {
227  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
228 
229  if(!count($items = $this->psc_obj->getEntries(PAY_METHOD_BILL)))
230  {
231  $this->tpl->setVariable('HEADER',$this->lng->txt('pay_bmf_your_order'));
232  $this->tpl->touchBlock('stop_floating');
233  ilUtil::sendInfo($this->lng->txt('pay_shopping_cart_empty'));
234  }
235  else
236  {
237 
238  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.pay_bill_confirm.html','payment');
239 
240  $this->__showShoppingCart();
241 
242  $this->tpl->setVariable('BILL_CONFIRM_FORMACTION',$this->ctrl->getFormAction($this));
243 
244  // set table header
245  $this->tpl->setVariable('TYPE_IMG',ilUtil::getImagePath('icon_pays_b.gif'));
246  $this->tpl->setVariable('ALT_IMG',$this->lng->txt('obj_usr'));
247  $this->tpl->touchBlock('stop_floating');
248  $this->tpl->setVariable('TXT_CLOSE_WINDOW',$this->lng->txt('close_window'));
249 
250  // set plain text variables
251  $this->tpl->setVariable('TXT_TERMS_CONDITIONS',$this->lng->txt('pay_bmf_terms_conditions'));
252  $this->tpl->setVariable('TXT_TERMS_CONDITIONS_READ',$this->lng->txt('pay_bmf_terms_conditions_read'));
253  $this->tpl->setVariable('TXT_TERMS_CONDITIONS_SHOW',$this->lng->txt('pay_bmf_terms_conditions_show'));
254  $this->tpl->setVariable('LINK_TERMS_CONDITIONS','./payment.php?view=conditions');
255  $this->tpl->setVariable('TXT_PASSWORD',$this->lng->txt('password'));
256  $this->tpl->setVariable('TXT_CONFIRM_ORDER',$this->lng->txt('pay_confirm_order'));
257 
258  $this->tpl->setVariable('INPUT_VALUE',$this->lng->txt('pay_send_order'));
259  $this->tpl->setVariable('CANCEL',$this->lng->txt('cancel'));
260  if ($this->error != '' &&
261  isset($_POST['terms_conditions']))
262  {
263  $this->tpl->setVariable('TERMS_CONDITIONS_' . strtoupper($_POST['terms_conditions']), ' checked') ;
264  }
265  if ($this->error != '' &&
266  isset($_POST['password']))
267  {
268  $this->tpl->setVariable('PASSWORD', ilUtil::prepareFormOutput($_POST['password'],true));
269  }
270 
271  // Button
272  $this->tpl->addBlockfile('BUTTONS', 'buttons', 'tpl.buttons.html');
273  $this->tpl->setCurrentBlock('btn_cell');
274  $this->tpl->setVariable('BTN_LINK', $this->ctrl->getLinkTarget($this, 'showPersonalData'));
275  $this->tpl->setVariable('BTN_TXT', $this->lng->txt('pay_bmf_back'));
276  $this->tpl->parseCurrentBlock('btn_cell');
277 
278  }
279  }
280 
284  function &executeCommand()
285  {
286  global $tree;
287 
288  $cmd = $this->ctrl->getCmd();
289 
290  switch ($this->ctrl->getNextClass($this))
291  {
292  default:
293  if(!$cmd = $this->ctrl->getCmd())
294  {
295  $cmd = 'showPersonalData';
296  }
297  $this->$cmd();
298  break;
299  }
300  }
301 
302  function __saveTransaction()
303  {
304  global $ilias, $ilUser, $ilObjDataCache;
305 
306  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
307 
308  $sc = $this->psc_obj->getShoppingCart(PAY_METHOD_BILL);
309 
310  $this->psc_obj->clearCouponItemsSession();
311 
312  if (is_array($sc) && count($sc) > 0)
313  {
314  include_once './payment/classes/class.ilPaymentBookings.php';
315  $book_obj =& new ilPaymentBookings($this->usr_obj);
316 
317  for ($i = 0; $i < count($sc); $i++)
318  {
319  if (!empty($_SESSION['coupons']['bill']))
320  {
321  $sc[$i]['math_price'] = (float) $sc[$i]['betrag'];
322 
323  $tmp_pobject =& new ilPaymentObject($this->user_obj, $sc[$i]['pobject_id']);
324 
325  foreach ($_SESSION['coupons']['bill'] as $key => $coupon)
326  {
327  $this->coupon_obj->setId($coupon['pc_pk']);
328  $this->coupon_obj->setCurrentCoupon($coupon);
329 
330  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
331  {
332  $_SESSION['coupons']['bill'][$key]['total_objects_coupon_price'] += (float) $sc[$i]['betrag'];
333  $_SESSION['coupons']['bill'][$key]['items'][] = $sc[$i];
334  }
335  }
336 
337  unset($tmp_pobject);
338  }
339  }
340 
341  $coupon_discount_items = $this->psc_obj->calcDiscountPrices($_SESSION['coupons']['bill']);
342 
343  for ($i = 0; $i < count($sc); $i++)
344  {
345  $pobjectData = ilPaymentObject::_getObjectData($sc[$i]['pobject_id']);
346  $pobject =& new ilPaymentObject($this->user_obj,$sc[$i]['pobject_id']);
347 
348  $inst_id_time = $ilias->getSetting('inst_id').'_'.$ilUser->getId().'_'.substr((string) time(),-3);
349  $transaction = $inst_id_time.substr(md5(uniqid(rand(), true)), 0, 4);
350  $price = $sc[$i]['betrag'];
351  $bonus = 0.0;
352 
353  if (array_key_exists($sc[$i]['pobject_id'], $coupon_discount_items))
354  {
355  $bonus = $coupon_discount_items[$sc[$i]['pobject_id']]['math_price'] - $coupon_discount_items[$sc[$i]['pobject_id']]['discount_price'];
356  }
357 
358  $book_obj->setTransaction($inst_id_time.substr(md5(uniqid(rand(), true)), 0, 4));
359  $book_obj->setPobjectId($sc[$i]['pobject_id']);
360  $book_obj->setCustomerId($ilUser->getId());
361  $book_obj->setVendorId($pobjectData['vendor_id']);
362  $book_obj->setPayMethod($pobjectData['pay_method']);
363  $book_obj->setOrderDate(time());
364  $book_obj->setDuration($sc[$i]['dauer']);
365  $book_obj->setUnlimitedDuration($sc[i]['unlimited_duration']);
366  $book_obj->setPrice($sc[$i]['betrag_string']);
367  $book_obj->setDiscount($bonus > 0 ? ilPaymentPrices::_getPriceStringFromAmount($bonus * (-1)) : '');
368  $book_obj->setPayed(1);
369  $book_obj->setAccess(1);
370  $book_obj->setVoucher('');
371  $book_obj->setTransactionExtern('');
372 
373  $book_obj->setVatRate($sc[$i]['vat_rate']);
374  $book_obj->setVatUnit($sc[$i]['vat_unit']);
375  $book_obj->setObjectTitle($sc[$i]['buchungstext']);
376 
377  include_once './payment/classes/class.ilPayMethods.php';
378 
379  $save_user_adr_bill = (int) ilPayMethods::_enabled('save_user_adr_bill') ? 1 : 0;
380 
381  if($save_user_adr_bill == 1)
382  {
383  $book_obj->setStreet($_SESSION['bill']['personal_data']['street'], $_SESSION['bill']['personal_data']['house_number']);
384  $book_obj->setPoBox($_SESSION['bill']['personal_data']['po_box']);
385  $book_obj->setZipcode($_SESSION['bill']['personal_data']['zipcode']);
386  $book_obj->setCity($_SESSION['bill']['personal_data']['city']);
387  $book_obj->setCountry($_SESSION['bill']['personal_data']['country']);
388  }
389 
390  $booking_id = $book_obj->add();
391 
392  if (!empty($_SESSION['coupons']['bill']) && $booking_id)
393  {
394  foreach ($_SESSION['coupons']['bill'] as $coupon)
395  {
396  $this->coupon_obj->setId($coupon['pc_pk']);
397  $this->coupon_obj->setCurrentCoupon($coupon);
398 
399  if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
400  {
401  $this->coupon_obj->addCouponForBookingId($booking_id);
402  }
403  }
404  }
405 
406  unset($booking_id);
407  unset($pobject);
408 
409  $obj_id = $ilObjDataCache->lookupObjId($pobjectData['ref_id']);
410  $obj_type = $ilObjDataCache->lookupType($obj_id);
411  $obj_title = $ilObjDataCache->lookupTitle($obj_id);
412 
413  $bookings['list'][] = array(
414  'type' => $obj_type,
415  'title' => '['.$obj_id.']: ' . $obj_title,
416  'duration' => $sc[$i]['dauer'],
417  'vat_rate' => $sc[$i]['vat_rate'],
418  'vat_unit' => $sc[$i]['vat_unit'],
419  'price' => $sc[$i]['betrag_string'],
420  'betrag' => $sc[$i]['betrag']
421  );
422 
423  $total += $sc[$i]['betrag'];
424  $total_vat += $sc[$i]['vat_unit'];
425 
426 
427  if ($sc[$i]['psc_id']) $this->psc_obj->delete($sc[$i]['psc_id']);
428  }
429 
430  if (!empty($_SESSION['coupons']['bill']))
431  {
432  foreach ($_SESSION['coupons']['bill'] as $coupon)
433  {
434  $this->coupon_obj->setId($coupon['pc_pk']);
435  $this->coupon_obj->setCurrentCoupon($coupon);
436  $this->coupon_obj->addTracking();
437  }
438  }
439  }
440 
441  $bookings['total'] = $total;
442 
443  $bookings['total_vat'] = $total_vat;
444 
445  $bookings['transaction'] = $transaction;
446 
447  return $bookings;
448  }
449 
450  function __sendBill($customer, $bookings)
451  {
452 
453  global $ilUser, $ilias, $tpl;
454 
455  $transaction = $bookings['transaction'];
456 
457  include_once './classes/class.ilTemplate.php';
458  include_once './Services/Utilities/classes/class.ilUtil.php';
459  include_once './payment/classes/class.ilGeneralSettings.php';
460  include_once './payment/classes/class.ilPaymentShoppingCart.php';
461  include_once 'Services/Mail/classes/class.ilMimeMail.php';
462 
463  $psc_obj = new ilPaymentShoppingCart($this->user_obj);
464  $genSet = new ilGeneralSettings();
465  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.pay_bill.html','payment');
466  $tpl = new ilTemplate('./payment/templates/default/tpl.pay_bill.html', true, true, true);
467 
468  $tpl->setVariable('VENDOR_ADDRESS', nl2br(utf8_decode($genSet->get('address'))));
469  $tpl->setVariable('VENDOR_ADD_INFO', nl2br(utf8_decode($genSet->get('add_info'))));
470  $tpl->setVariable('VENDOR_BANK_DATA', nl2br(utf8_decode($genSet->get('bank_data'))));
471  $tpl->setVariable('TXT_BANK_DATA', utf8_decode($this->lng->txt('pay_bank_data')));
472 
473 
474  $tpl->setVariable('CUSTOMER_FIRSTNAME', $customer['firstname']);
475  $tpl->setVariable('CUSTOMER_LASTNAME', $customer['lastname']);
476  if($customer['po_box']== '')
477  {
478  $tpl->setVariable('CUSTOMER_STREET', $customer['street']. ' ' . $customer['house_number']);
479  }
480  else
481  {
482  $tpl->setVariable('CUSTOMER_STREET', $customer['po_box']);
483  }
484  $tpl->setVariable('CUSTOMER_ZIPCODE', $customer['zipcode']);
485  $tpl->setVariable('CUSTOMER_CITY', $customer['city']);
486  $tpl->setVariable('CUSTOMER_COUNTRY', $customer['country']);
487 
488  $tpl->setVariable('BILL_NO', $transaction);
489  $tpl->setVariable('DATE', date('d.m.Y'));
490 
491  $tpl->setVariable('TXT_BILL', utf8_decode($this->lng->txt('pays_bill')));
492  $tpl->setVariable('TXT_BILL_NO', utf8_decode($this->lng->txt('pay_bill_no')));
493  $tpl->setVariable('TXT_DATE', utf8_decode($this->lng->txt('date')));
494 
495  $tpl->setVariable('TXT_ARTICLE', utf8_decode($this->lng->txt('pay_article')));
496  $tpl->setVariable('TXT_VAT_RATE', utf8_decode($this->lng->txt('vat_rate')));
497  $tpl->setVariable('TXT_VAT_UNIT', utf8_decode($this->lng->txt('vat_unit')));
498  $tpl->setVariable('TXT_PRICE', utf8_decode($this->lng->txt('price_a')));
499 
500  for ($i = 0; $i < count($bookings['list']); $i++)
501  {
502  $tmp_pobject =& new ilPaymentObject($this->user_obj, $bookings['list'][$i]['pobject_id']);
503 
504  $assigned_coupons = '';
505  if (!empty($_SESSION['coupons']['bill']))
506  {
507  foreach ($_SESSION['coupons']['bill'] as $key => $coupon)
508  {
509  $this->coupon_obj->setId($coupon['pc_pk']);
510  $this->coupon_obj->setCurrentCoupon($coupon);
511 
512  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
513  {
514  $assigned_coupons .= '<br />' . $this->lng->txt('paya_coupons_coupon') . ': ' . $coupon['pcc_code'];
515  }
516  }
517  }
518 
519  $tpl->setCurrentBlock('loop');
520  $tpl->setVariable('LOOP_OBJ_TYPE', utf8_decode($this->lng->txt($bookings['list'][$i]['type'])));
521  $tpl->setVariable('LOOP_TITLE', utf8_decode($bookings['list'][$i]['title']) . $assigned_coupons);
522  $tpl->setVariable('LOOP_TXT_ENTITLED_RETRIEVE', utf8_decode($this->lng->txt('pay_entitled_retrieve')));
523 
524  if( $bookings['list'][$i]['duration'] == 0)
525  {
526  $tpl->setVariable('LOOP_DURATION', utf8_decode($this->lng->txt('unlimited_duration')));
527  } else
528  $tpl->setVariable('LOOP_DURATION', $bookings['list'][$i]['duration'] . ' ' . utf8_decode($this->lng->txt('paya_months')));
529  $tpl->setVariable('LOOP_VAT_RATE', $bookings['list'][$i]['vat_rate']);
530  $tpl->setVariable('LOOP_VAT_UNIT', $bookings['list'][$i]['vat_unit'].' '.$genSet->get('currency_unit'));
531  $tpl->setVariable('LOOP_PRICE', $bookings['list'][$i]['price']);
532  $tpl->parseCurrentBlock('loop');
533 
534  unset($tmp_pobject);
535  }
536 
537  if (!empty($_SESSION['coupons']['bill']))
538  {
539  if (count($items = $bookings['list']))
540  {
541  $sub_total_amount = $bookings['total'];
542 
543  foreach ($_SESSION['coupons']['bill'] as $coupon)
544  {
545  $this->coupon_obj->setId($coupon['pc_pk']);
546  $this->coupon_obj->setCurrentCoupon($coupon);
547 
548  $total_object_price = 0.0;
549  $current_coupon_bonus = 0.0;
550 
551  foreach ($bookings['list'] as $item)
552  {
553  $tmp_pobject =& new ilPaymentObject($this->user_obj, $item['pobject_id']);
554 
555  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
556  {
557  $total_object_price += $item['betrag'];
558  }
559 
560  unset($tmp_pobject);
561  }
562 
563  $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
564 
565  $bookings['total'] += $current_coupon_bonus * (-1);
566 
567  $tpl->setCurrentBlock('cloop');
568  $tpl->setVariable('TXT_COUPON', utf8_decode($this->lng->txt('paya_coupons_coupon') . ' ' . $coupon['pcc_code']));
569  $tpl->setVariable('BONUS', number_format($current_coupon_bonus * (-1), 2, ',', '.') . ' ' . $genSet->get('currency_unit'));
570  $tpl->parseCurrentBlock();
571  }
572 
573  $tpl->setVariable('TXT_SUBTOTAL_AMOUNT', utf8_decode($this->lng->txt('pay_bmf_subtotal_amount')));
574  $tpl->setVariable('SUBTOTAL_AMOUNT', number_format($sub_total_amount, 2, ',', '.') . ' ' . $genSet->get('currency_unit'));
575  }
576  }
577 
578  if ($bookings['total'] < 0)
579  {
580  $bookings['total'] = 0.0;
581  $bookings['total_vat'] = 0.0;
582  }
583 
584 
585  $tpl->setVariable('TXT_TOTAL_AMOUNT', utf8_decode($this->lng->txt('pay_bmf_total_amount')));
586  $tpl->setVariable('TOTAL_AMOUNT', number_format($bookings['total'], 2, ',', '.') . ' ' . $genSet->get('currency_unit'));
587  if ($bookings['total_vat'] > 0)
588  {
589  $tpl->setVariable('TOTAL_VAT', $bookings['total_vat']. ' ' . $genSet->get('currency_unit'));
590  $tpl->setVariable('TXT_TOTAL_VAT', utf8_decode($this->lng->txt('pay_bmf_vat_included')));
591  }
592 
593  $tpl->setVariable('TXT_PAYMENT_TYPE', utf8_decode($this->lng->txt('pay_payed_bill')));
594 
595  if (!@file_exists($genSet->get('pdf_path')))
596  {
597 
598  ilUtil::makeDir($genSet->get('pdf_path'));
599  }
600 
601  if (@file_exists($genSet->get('pdf_path')))
602  {
603  ilUtil::html2pdf($tpl->get(), $genSet->get('pdf_path') . '/' . $transaction . '.pdf');
604  }
605 
606  if (@file_exists($genSet->get('pdf_path') . '/' . $transaction . '.pdf') &&
607  $ilUser->getEmail() != '' &&
608  $ilias->getSetting('admin_email') != '')
609  {
610  $m= new ilMimeMail; // create the mail
611  $m->From( $ilias->getSetting('admin_email') );
612  $m->To( $ilUser->getEmail() );
613  $m->Subject( $this->lng->txt('pay_message_subject') );
614  $message = $this->lng->txt('pay_message_hello') . ' ' . $ilUser->getFirstname() . ' ' . $ilUser->getLastname() . ",\n\n";
615  $message .= $this->lng->txt('pay_message_thanks') . "\n\n";
616  $message .= $this->lng->txt('pay_message_attachment') . "\n\n";
617  $message .= $this->lng->txt('pay_message_regards') . "\n\n";
618  $message .= strip_tags($genSet->get('address'));
619  $m->Body( $message ); // set the body
620  $m->Attach( $genSet->get('pdf_path') . '/' . $transaction . '.pdf', 'application/pdf' ) ; // attach a file of type image/gif
621  $m->Send(); // send the mail
622  }
623 
624  @unlink($genSet->get('pdf_path') . '/' . $transaction . '.html');
625  @unlink($genSet->get('pdf_path') . '/' . $transaction . '.pdf');
626  }
627 
628  function __addBookings($a_result,$a_transaction)
629  {
630  include_once './payment/classes/class.ilPaymentBookings.php';
631  include_once './payment/classes/class.ilPaymentShoppingCart.php';
632  include_once './payment/classes/class.ilPaymentObject.php';
633  include_once './payment/classes/class.ilPaymentPrices.php';
634  include_once './payment/classes/class.ilGeneralSettings.php';
635  include_once './payment/classes/class.ilPayMethods.php';
636 
637  $save_user_adr_bill = (int) ilPayMethods::_enabled('save_user_adr_bill') ? 1 : 0;
638 
639  $booking_obj =& new ilPaymentBookings();
640 
641  $sc_obj =& new ilPaymentShoppingCart($this->user_obj);
642 
643  $items = $sc_obj->getEntries(PAY_METHOD_BILL);
644 
645  $sc_obj->clearCouponItemsSession();
646 
647  foreach($items as $entry)
648  {
649  $pobject =& new ilPaymentObject($this->user_obj,$entry['pobject_id']);
650 
651  $price = ilPaymentPrices::_getPrice($entry['price_id']);
652 
653  if (!empty($_SESSION['coupons']['bill']))
654  {
655  //$entry['math_price'] = (float) ilPaymentPrices::_getPriceFromArray($price);
656  $entry['math_price'] = $entry['price'];
657  foreach ($_SESSION['coupons']['bill'] as $key => $coupon)
658  {
659  $this->coupon_obj->setId($coupon['pc_pk']);
660  $this->coupon_obj->setCurrentCoupon($coupon);
661 
662  if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
663  {
664  //$_SESSION['coupons']['bill'][$key]['total_objects_coupon_price'] += (float) ilPaymentPrices::_getPriceFromArray($price);
665  $_SESSION['coupons']['bill'][$key]['total_objects_coupon_price'] += $entry['price'];
666  $_SESSION['coupons']['bill'][$key]['items'][] = $entry;
667  }
668  }
669  }
670 
671  unset($pobject);
672  }
673 
674  $coupon_discount_items = $sc_obj->calcDiscountPrices($_SESSION['coupons']['bill']);
675 
676  $i = 0;
677  foreach($items as $entry)
678  {
679  $pobject =& new ilPaymentObject($this->user_obj,$entry['pobject_id']);
680 
681  $price = ilPaymentPrices::_getPrice($entry['price_id']);
682 
683 
684  if (array_key_exists($entry['pobject_id'], $coupon_discount_items))
685  {
686  $bonus = $coupon_discount_items[$entry['pobject_id']]['math_price'] - $coupon_discount_items[$entry['pobject_id']]['discount_price'];
687  }
688 
689  $booking_obj->setTransaction($a_transaction);
690  $booking_obj->setPobjectId($entry['pobject_id']);
691  $booking_obj->setCustomerId($this->user_obj->getId());
692  $booking_obj->setVendorId($pobject->getVendorId());
693  $booking_obj->setPayMethod($pobject->getPayMethod());
694  $booking_obj->setOrderDate(time());
695  $booking_obj->setDuration($price['duration']);
696  $booking_obj->setPrice(ilPaymentPrices::_getPriceString($entry['price_id']));
697  $booking_obj->setDiscount($bonus > 0 ? ilPaymentPrices::_getPriceStringFromAmount((-1) * $bonus) : '');
698  $booking_obj->setPayed(1);
699  $booking_obj->setAccess(1);
700  $booking_obj->setVoucher($a_result->buchungsListe->buchungen[$i++]->belegNr);
701  $booking_obj->setTransactionExtern($a_result->buchungsListe->kassenzeichen);
702 
703  $booking_obj->setVatUnit($entry['vat_unit']);
704  $obj_id = $ilObjDataCache->lookupObjId($pobject->getRefId());
705  $obj_type = $ilObjDataCache->lookupType($obj_id);
706  $obj_title = $ilObjDataCache->lookupTitle($obj_id);
707 
708  $oVAT = new ilShopVats((int)$pobject->getVatId());
709  $obj_vat_rate = $oVAT->getRate();
710 
711 
712  $book_obj->setObjectTitle($obj_title);
713  $book_obj->setVatRate($obj_vat_rate);
714 
715  //sets the customers address for the bill if enabled in administration
716  if($save_user_adr_bill == 1)
717  {
718  $booking_obj->setStreet($_SESSION['bill']['personal_data']['street'], $_SESSION['bill']['personal_data']['house_number']);
719  $booking_obj->setPoBox($_SESSION['bill']['personal_data']['po_box']);
720  $booking_obj->setZipcode($_SESSION['bill']['personal_data']['zipcode']);
721  $booking_obj->setCity($_SESSION['bill']['personal_data']['city']);
722  $booking_obj->setCountry($_SESSION['bill']['personal_data']['country']);
723  }
724 
725  $current_booking_id = $booking_obj->add();
726 
727  if (!empty($_SESSION['coupons']['bill']) && $current_booking_id)
728  {
729  foreach ($_SESSION['coupons']['bill'] as $coupon)
730  {
731  $this->coupon_obj->setId($coupon['pc_pk']);
732  $this->coupon_obj->setCurrentCoupon($coupon);
733 
734  if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
735  {
736  $this->coupon_obj->addCouponForBookingId($current_booking_id);
737  }
738  }
739  }
740 
741  unset($current_booking_id);
742  unset($pobject);
743  }
744 
745  if (!empty($_SESSION['coupons']['bill']))
746  {
747  foreach ($_SESSION['coupons']['bill'] as $coupon)
748  {
749  $this->coupon_obj->setId($coupon['pc_pk']);
750  $this->coupon_obj->setCurrentCoupon($coupon);
751  $this->coupon_obj->addTracking();
752  }
753  }
754  }
755 
757  {
758  include_once './payment/classes/class.ilPaymentShoppingCart.php';
759 
760  $sc_obj =& new ilPaymentShoppingCart($this->user_obj);
761 
762  return $sc_obj->emptyShoppingCart();
763  }
764 
765  function __clearSession()
766  {
767  $_SESSION['coupons']['bill'] = '';
768  }
769 
770  function __loadTemplate()
771  {
772  $this->tpl->addBlockFile('CONTENT', 'content', 'tpl.payb_content.html');
773 
774  $this->__buildStylesheet();
775  $this->__buildStatusline();
776  }
777 
778  function __buildStatusline()
779  {
780  $this->tpl->addBlockFile('STATUSLINE', 'statusline', 'tpl.statusline.html');
781 # $this->__buildLocator();
782  }
783 
784  function __buildLocator()
785  {
786  $this->tpl->addBlockFile('LOCATOR', 'locator', 'tpl.locator.html');
787  $this->tpl->setVariable('TXT_LOCATOR',$this->lng->txt('locator'));
788 
789  $this->tpl->setCurrentBlock('locator_item');
790  $this->tpl->setVariable('ITEM', $this->lng->txt('personal_desktop'));
791  $this->tpl->setVariable('LINK_ITEM','../ilias.php?baseClass=ilPersonalDesktopGUI');
792  #$this->tpl->setVariable('LINK_ITEM', '../usr_personaldesktop.php');
793  $this->tpl->parseCurrentBlock();
794 
795  $this->tpl->setCurrentBlock('locator_item');
796  $this->tpl->setVariable('PREFIX','>&nbsp;');
797 # $this->tpl->setVariable('ITEM', $this->lng->txt('pay_locator'));
798  $this->tpl->setVariable('ITEM', 'Payment');
799  $this->tpl->setVariable('LINK_ITEM', './payment.php');
800  $this->tpl->parseCurrentBlock();
801 
802  // CHECK for new mail and info
804 
805  return true;
806  }
807 
808  function __buildStylesheet()
809  {
810  $this->tpl->setVariable('LOCATION_STYLESHEET',ilUtil::getStyleSheetLocation());
811  }
812 
816  function __showCountries(&$tpl, $value = '')
817  {
818  $countries = $this->__getCountries();
819  foreach($countries as $code => $text)
820  {
821  $tpl->setCurrentBlock('loop_countries');
822  $tpl->setVariable('LOOP_COUNTRIES', $code);
823  $tpl->setVariable('LOOP_COUNTRIES_TXT', $text);
824  if ($value != '' &&
825  $value == $code)
826  {
827  $tpl->setVariable('LOOP_COUNTRIES_SELECTED', ' selected');
828  }
829  $tpl->parseCurrentBlock('loop_countries');
830  }
831  $tpl->setVariable('TXT_PLEASE_SELECT', $this->lng->txt('pay_bmf_please_select'));
832  return;
833  }
834 
835  function __getCountries()
836  {
837  global $lng;
838 
839  $lng->loadLanguageModule('meta');
840 
841  $cntcodes = array ('DE','ES','FR','GB','AT','CH','AF','AL','DZ','AS','AD','AO',
842  'AI','AQ','AG','AR','AM','AW','AU','AT','AZ','BS','BH','BD','BB','BY',
843  'BE','BZ','BJ','BM','BT','BO','BA','BW','BV','BR','IO','BN','BG','BF',
844  'BI','KH','CM','CA','CV','KY','CF','TD','CL','CN','CX','CC','CO','KM',
845  'CG','CK','CR','CI','HR','CU','CY','CZ','DK','DJ','DM','DO','TP','EC',
846  'EG','SV','GQ','ER','EE','ET','FK','FO','FJ','FI','FR','FX','GF','PF',
847  'TF','GA','GM','GE','DE','GH','GI','GR','GL','GD','GP','GU','GT','GN',
848  'GW','GY','HT','HM','HN','HU','IS','IN','ID','IR','IQ','IE','IL','IT',
849  'JM','JP','JO','KZ','KE','KI','KP','KR','KW','KG','LA','LV','LB','LS',
850  'LR','LY','LI','LT','LU','MO','MK','MG','MW','MY','MV','ML','MT','MH',
851  'MQ','MR','MU','YT','MX','FM','MD','MC','MN','MS','MA','MZ','MM','NA',
852  'NR','NP','NL','AN','NC','NZ','NI','NE','NG','NU','NF','MP','NO','OM',
853  'PK','PW','PA','PG','PY','PE','PH','PN','PL','PT','PR','QA','RE','RO',
854  'RU','RW','KN','LC','VC','WS','SM','ST','SA','CH','SN','SC','SL','SG',
855  'SK','SI','SB','SO','ZA','GS','ES','LK','SH','PM','SD','SR','SJ','SZ',
856  'SE','SY','TW','TJ','TZ','TH','TG','TK','TO','TT','TN','TR','TM','TC',
857  'TV','UG','UA','AE','GB','UY','US','UM','UZ','VU','VA','VE','VN','VG',
858  'VI','WF','EH','YE','ZR','ZM','ZW');
859  $cntrs = array();
860  foreach($cntcodes as $cntcode)
861  {
862  $cntrs[$cntcode] = $lng->txt('meta_c_'.$cntcode);
863  }
864  asort($cntrs);
865  return $cntrs;
866  }
867 
868  function __getCountryCode($value = '')
869  {
870  $countries = $this->__getCountries();
871  foreach($countries as $code => $text)
872  {
873  if ($text == $value)
874  {
875  return $code;
876  }
877  }
878  return;
879  }
880 
881  function __getCountryName($value = '')
882  {
883  $countries = $this->__getCountries();
884  return $countries[$value];
885  }
886 
887  function __getShoppingCart()
888  {
889  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
890 
891  if(!count($items = $this->psc_obj->getEntries(PAY_METHOD_BILL)))
892  {
893  return 0;
894  }
895 
896  $counter = 0;
897  foreach($items as $item)
898  {
899  $tmp_pobject =& new ilPaymentObject($this->user_obj,$item['pobject_id']);
900 
901  $tmp_obj =& ilObjectFactory::getInstanceByRefId($tmp_pobject->getRefId(), false);
902  if($tmp_obj)
903  {
904  $f_result[$counter]['buchungstext'] = $tmp_obj->getTitle();
905  }
906  else
907  {
908  $f_result[$counter]['buchungstext'] = $this->lng->txt('object_not_found');
909  }
910  $price_arr = ilPaymentPrices::_getPrice($item['price_id']);
911 
912  //$price = (int) $price_arr['unit_value'];
913  $price = (float) $price_arr['price'];
914 
915 
916  /* if ($price_arr['sub_unit_value'] != '' &&
917  $price_arr['sub_unit_value'] > 0)
918  {
919  $price .= '.'.( (int) $price_arr['sub_unit_value']);
920  }
921 */
922  $f_result[$counter]['betrag'] = $price * 1.0;
923 
924  unset($tmp_obj);
925  unset($tmp_pobject);
926 
927  ++$counter;
928  }
929 
930  return $f_result;
931  }
932 
933  function __getTotalAmount()
934  {
935  $amount = 0;
936 
937  if (is_array($result = $this->__getShoppingCart()))
938  {
939  for ($i = 0; $i < count($result); $i++)
940  {
941  $amount += $result[$i]['betrag'];
942  }
943  }
944 
945  return $amount;
946  }
947 
948  // if ok, a transaction-id will be generated and the customer gets a bill
949  function getBill()
950  {
951  if ($_POST['terms_conditions'] != 1)
952  {
953  $this->error = $this->lng->txt('pay_bmf_check_terms_conditions');
954  ilUtil::sendInfo($this->error);
955  $this->getPersonalData();
956  return;
957  }
958  if ($_POST['password'] == '' ||
959  md5($_POST['password']) != $this->user_obj->getPasswd())
960  {
961  $this->error = $this->lng->txt('pay_bmf_password_not_valid');
962  ilUtil::sendInfo($this->error);
963  $this->getPersonalData();
964  return;
965  }
966  $this->error = '';
967  ilUtil::sendInfo($this->lng->txt('pay_message_thanks'));
968 
969  $bookingList = $this->__saveTransaction();
970  $customer = $_SESSION['bill']['personal_data'];
971  $this->__sendBill($customer, $bookingList);
972 
973  }
974 
975 
977  {
978  include_once './payment/classes/class.ilGeneralSettings.php';
979 
980  $genSet = new ilGeneralSettings();
981 
982  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
983 
984  if(!count($items = $this->psc_obj->getEntries(PAY_METHOD_BILL)))
985  {
986  ilUtil::sendInfo($this->lng->txt('pay_shopping_cart_empty'));
987  }
988 
989  $counter = 0;
990  foreach($items as $item)
991  {
992  $tmp_pobject =& new ilPaymentObject($this->user_obj,$item['pobject_id']);
993 
994  $tmp_obj =& ilObjectFactory::getInstanceByRefId($tmp_pobject->getRefId(), false);
995 
996  $price_arr = ilPaymentPrices::_getPrice($item['price_id']);
997 
998  $assigned_coupons = '';
999  if (!empty($_SESSION['coupons']['bill']))
1000  {
1001  foreach ($_SESSION['coupons']['bill'] as $key => $coupon)
1002  {
1003  $this->coupon_obj->setId($coupon['pc_pk']);
1004  $this->coupon_obj->setCurrentCoupon($coupon);
1005 
1006  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
1007  {
1008  $assigned_coupons .= '<br />' . $this->lng->txt('paya_coupons_coupon') . ': ' . $coupon['pcc_code'];
1009  }
1010  }
1011  }
1012  if($tmp_obj)
1013  {
1014  $f_result[$counter][] = $tmp_obj->getTitle();
1015  }
1016  else
1017  {
1018  $f_result[$counter][] = $this->lng->txt('object_not_found');
1019  }
1020 
1021  if ($assigned_coupons != '') $f_result[$counter][count($f_result[$counter]) - 1] .= $assigned_coupons;
1022 
1023  if($price_arr['duration'] == 0)
1024  {
1025  $f_result[$counter][] = $this->lng->txt('unlimited_duration');
1026  }
1027  else
1028  {
1029  $f_result[$counter][] = $price_arr['duration'] . ' ' . $this->lng->txt('paya_months');
1030  }
1031 
1032 
1033  $oVAT = new ilShopVats((int)$tmp_pobject->getVatId());
1034  $f_result[$counter][] = ilShopUtils::_formatVAT($oVAT->getRate());
1035 
1036  $float_price = $price_arr['price'];
1037 
1038  $f_result[$counter][] = $tmp_pobject->getVat($float_price, 'GUI').' '.$genSet->get('currency_unit');
1039  $this->totalVat = $this->totalVat + $tmp_pobject->getVat($float_price);
1040 
1041  $f_result[$counter][] = ilPaymentPrices::_getPriceString($item['price_id']);
1042 
1043  unset($tmp_obj);
1044  unset($tmp_pobject);
1045 
1046  ++$counter;
1047  }
1048 
1049  return $this->__showItemsTable($f_result);
1050  }
1051 
1052  function &__initTableGUI()
1053  {
1054  include_once './Services/Table/classes/class.ilTableGUI.php';
1055 
1056  return new ilTableGUI(0,false);
1057  }
1058 
1059  function __showItemsTable($a_result_set)
1060  {
1061  include_once './payment/classes/class.ilGeneralSettings.php';
1062 
1063  $genSet = new ilGeneralSettings();
1064 
1065  $tbl =& $this->__initTableGUI();
1066  $tpl =& $tbl->getTemplateObject();
1067 
1068  // SET FORMACTION
1069  $tpl->setCurrentBlock('tbl_form_header');
1070 
1071  $tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
1072  $tpl->parseCurrentBlock();
1073 
1074  $tbl->setTitle($this->lng->txt('paya_shopping_cart'),'icon_pays_b.gif',$this->lng->txt('paya_shopping_cart'));
1075  $tbl->setHeaderNames(array($this->lng->txt('title'),
1076  $this->lng->txt('duration'),
1077  $this->lng->txt('vat_rate'),
1078  $this->lng->txt('vat_unit'),
1079  $this->lng->txt('price_a')));
1080 
1081  $tbl->setHeaderVars(array('title',
1082  'duration',
1083  'vat_rate',
1084  'vat_unit',
1085  'price'),
1086  array('cmd' => '',
1087  'cmdClass' => 'ilpurchasebillgui',
1088  'cmdNode' => $_GET['cmdNode']));
1089 
1090  $tbl->disable('footer');
1091  $tbl->disable('sort');
1092  $tbl->disable('linkbar');
1093 
1094  $offset = $_GET['offset'];
1095  $order = $_GET['sort_by'];
1096  $direction = $_GET['sort_order'] ? $_GET['sort_order'] : 'desc';
1097 
1098  $tbl->setOrderColumn($order,'title');
1099  $tbl->setOrderDirection($direction);
1100  $tbl->setOffset($offset);
1101  $tbl->setLimit($_GET['limit']);
1102  $tbl->setMaxCount(count($a_result_set));
1103 # $tbl->setFooter('tblfooter',$this->lng->txt('previous'),$this->lng->txt('next'));
1104  $tbl->setData($a_result_set);
1105 
1106  $sc_obj =& new ilPaymentShoppingCart($this->user_obj);
1107 
1108  $totalAmount = $sc_obj->getTotalAmount();
1109 
1110  $tpl->setCurrentBlock('tbl_footer_linkbar');
1111  $amount .= "<table class=\"\" style=\"float: right;\">\n";
1112  if (!empty($_SESSION['coupons']['bill']))
1113  {
1114  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
1115 
1116  if (count($items = $this->psc_obj->getEntries(PAY_METHOD_BILL)))
1117  {
1118  $amount .= "<tr>\n";
1119  $amount .= "<td>\n";
1120  $amount .= "<b>" . $this->lng->txt("pay_bmf_subtotal_amount") . ":";
1121  $amount .= "</td>\n";
1122  $amount .= "<td>\n";
1123  $amount .= number_format($totalAmount[PAY_METHOD_BILL], 2, ",", ".") . " " . $genSet->get("currency_unit") . "</b>";
1124  $amount .= "</td>\n";
1125  $amount .= "</tr>\n";
1126 
1127  foreach ($_SESSION['coupons']['bill'] as $coupon)
1128  {
1129  $this->coupon_obj->setCurrentCoupon($coupon);
1130  $this->coupon_obj->setId($coupon['pc_pk']);
1131 
1132  $total_object_price = 0.0;
1133  $current_coupon_bonus = 0.0;
1134 
1135  foreach ($items as $item)
1136  {
1137  $tmp_pobject =& new ilPaymentObject($this->user_obj, $item['pobject_id']);
1138 
1139  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
1140  {
1141  $price_data = ilPaymentPrices::_getPrice($item['price_id']);
1142  $price = (float) $price_data['price'];
1143 
1144  $total_object_price += $price;
1145  }
1146 
1147  unset($tmp_pobject);
1148  }
1149 
1150  $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
1151  $totalAmount[PAY_METHOD_BILL] += $current_coupon_bonus * (-1);
1152 
1153  $amount .= "<tr>\n";
1154  $amount .= "<td>\n";
1155  $amount .= $this->lng->txt('paya_coupons_coupon') . ' ' . $coupon['pcc_code'] . ':';
1156  $amount .= "</td>\n";
1157  $amount .= "<td>\n";
1158  $amount .= number_format($current_coupon_bonus * (-1), 2, ",", ".") . " " . $genSet->get("currency_unit");
1159  $amount .= "</td>\n";
1160  $amount .= "</tr>\n";
1161  }
1162 
1163  if ($totalAmount[PAY_METHOD_BILL] < 0)
1164  {
1165  $totalAmount[PAY_METHOD_BILL] = 0;
1166  $this->totalVat = 0;
1167  }
1168  }
1169  }
1170 
1171  $amount .= "<tr>\n";
1172  $amount .= "<td>\n";
1173  $amount .= "<b>" . $this->lng->txt("pay_bmf_total_amount") . ":";
1174  $amount .= "</td>\n";
1175  $amount .= "<td>\n";
1176  $amount .= number_format($totalAmount[PAY_METHOD_BILL], 2, ",", ".") . " " . $genSet->get("currency_unit");
1177  $amount .= "</td>\n";
1178  $amount .= "</tr>\n";
1179 
1180  if ($this->totalVat > 0)
1181  {
1182  $amount .= "<tr>\n";
1183  $amount .= "<td>\n";
1184  $amount .= $this->lng->txt("pay_bmf_vat_included") . ":";
1185  $amount .= "</td>\n";
1186  $amount .= "<td>\n";
1187  $amount .= ilShopUtils::_formatFloat($this->totalVat) . " " . $genSet->get('currency_unit');
1188  $amount .= "</td>\n";
1189  $amount .= "</tr>\n";
1190  }
1191 
1192  $amount .= "</table>\n";
1193 
1194  $tpl->setVariable('LINKBAR', $amount);
1195  $tpl->parseCurrentBlock('tbl_footer_linkbar');
1196  $tpl->setCurrentBlock('tbl_footer');
1197  $tpl->setVariable('COLUMN_COUNT',5);
1198  $tpl->parseCurrentBlock();
1199  $tbl->render();
1200 
1201  $this->tpl->setVariable('ITEMS_TABLE',$tbl->tpl->get());
1202 
1203  return true;
1204  }
1205 }
1206 ?>