ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilShopBoughtObjectsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Payment/classes/class.ilShopBaseGUI.php';
5 include_once './Services/Payment/classes/class.ilPaymentCurrency.php';
6 include_once './Services/Payment/classes/class.ilShopTableGUI.php';
7 
19 {
20  private $user_obj;
21 
22  private $psc_obj = null;
23 
24  public function __construct($user_obj)
25  {
27 
28  $this->user_obj = $user_obj;
29  }
30 
31  public function executeCommand()
32  {
33  global $ilUser;
34 
35  if(ANONYMOUS_USER_ID == $ilUser->getId() && !isset($_SESSION['download_links']));
36  {
37  // $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
38  }
39 
40  $cmd = $this->ctrl->getCmd();
41  switch ($this->ctrl->getNextClass($this))
42  {
43  case 'showBillHistory':
44  $this->$cmd();
45  break;
46 
47  default:
48  $this->prepareOutput();
49  if(!$cmd = $this->ctrl->getCmd())
50  {
51  $cmd = 'showItems';
52  }
53  $this->$cmd();
54  break;
55  }
56  }
57 
58 
59  protected function buildSubTabs()
60  {
61  global $ilTabs, $ilUser, $rbacreview;
62 
63  $ilTabs->addSubTabTarget('paya_buyed_objects', $this->ctrl->getLinkTarget($this, 'showItems'), '', '', '','showItems');
64  $ilTabs->addSubTabTarget('paya_bill_history', $this->ctrl->getLinkTarget($this, 'showBillHistory'), '', '', '','showBillHistory');
65  }
66 
67  public function showBillHistory()
68  {
69  global $ilTabs;
70 
71  include_once "./Services/Repository/classes/class.ilRepositoryExplorer.php";
72 
73  $ilTabs->setSubTabActive('paya_bill_history');
74 
75  $this->initBookingsObject();
76  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
77 
78  $bookings = $this->bookings_obj->getDistinctTransactions($this->user_obj->getId());
79 
80  if(!count($bookings))
81  {
82  ilUtil::sendInfo($this->lng->txt('pay_not_buyed_any_object'));
83  return true;
84  }
85 
86  $counter = 0;
87 
88  foreach($bookings as $booking)
89  {
90 
91  $f_result[$counter]['transaction'] = "<a href=\"".$this->ctrl->getLinkTarget($this, "createBill")."&transaction=".$booking['transaction']."\">".$booking['transaction'].".pdf</a>";
92 
93  $f_result[$counter]['order_date'] = ilDatePresentation::formatDate(new ilDateTime($booking['order_date'], IL_CAL_UNIX));
94 
95  ++$counter;
96  }
97  return $this->showBillHistoryTable($f_result);
98  }
99 
100  private function showBillHistoryTable($a_result_set)
101  {
102  $this->ctrl->setParameter($this,'cmd','showBillHistory');
103  $tbl = new ilShopTableGUI($this);
104  $tbl->setId('tbl_bill_history');
105  $tbl->setTitle($this->lng->txt("paya_bill_history"));
106  $tbl->setRowTemplate("tpl.shop_statistics_row.html", "Services/Payment");
107 
108  $tbl->addColumn($this->lng->txt('paya_transaction'), 'transaction', '10%');
109  $tbl->addColumn($this->lng->txt('paya_order_date'), 'order_date', '10%');
110 
111  $tbl->setData($a_result_set);
112 
113  $this->tpl->setVariable('TABLE', $tbl->getHTML());
114  return true;
115  }
116 
117  function createBill()
118  {
119  global $ilUser, $ilias, $tpl,$ilObjDataCache;
120 
121  $customer=$this->user_obj;
122  $transaction = $_GET['transaction'];
123 
124  $total_price = 0;
125  $total_vat = 0;
126  $i = 0;
127 
128  include_once './classes/class.ilTemplate.php';
129  include_once './Services/Utilities/classes/class.ilUtil.php';
130  include_once './Services/Payment/classes/class.ilGeneralSettings.php';
131 
132  $genSet = new ilGeneralSettings();
133  $currency = $genSet->get('currency_unit');
134 
135  $user_id = $this->user_obj->getId();
136 
137  $bookings = ilPaymentBookings::__readBillByTransaction($user_id,$transaction);
138  if($bookings[$i]['street'] == NULL) $bookings[$i]['street'] = nl2br(utf8_decode($customer->getStreet()));
139  if($bookings[$i]['zipcode'] == NULL) $bookings[$i]['zipcode'] = nl2br(utf8_decode($customer->getZipcode()));
140  if($bookings[$i]['city'] == NULL) $bookings[$i]['city'] = nl2br(utf8_decode($customer->getCity()));
141  if($bookings[$i]['country'] == NULL) $bookings[$i]['country'] = nl2br(utf8_decode($customer->getCountry()));
142 
143  $i = 0;
144  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.pay_bill.html','Services/Payment');
145  $tpl = new ilTemplate('./Services/Payment/templates/default/tpl.pay_bill.html', true, true, true);
146 
147  $tpl->setVariable('VENDOR_ADDRESS', nl2br(utf8_decode($genSet->get('address'))));
148  $tpl->setVariable('VENDOR_ADD_INFO', nl2br(utf8_decode($genSet->get('add_info'))));
149  $tpl->setVariable('VENDOR_BANK_DATA', nl2br(utf8_decode($genSet->get('bank_data'))));
150  $tpl->setVariable('TXT_BANK_DATA', utf8_decode($this->lng->txt('pay_bank_data')));
151 
152 
153  $tpl->setVariable('CUSTOMER_FIRSTNAME',$customer->getFirstName());// $customer['vorname']);
154  $tpl->setVariable('CUSTOMER_LASTNAME', $customer->getLastName()); //$customer['nachname']);
155  if($bookings['po_box']== '')
156  {
157  $tpl->setVariable('CUSTOMER_STREET',utf8_decode( $bookings[$i]['street']));
158  }
159  else
160  {
161  $tpl->setVariable('CUSTOMER_STREET', $bookings[$i]['po_box']);
162  }
163  $tpl->setVariable('CUSTOMER_ZIPCODE', $bookings[$i]['zipcode']);
164  $tpl->setVariable('CUSTOMER_CITY', $bookings[$i]['city']);
165  $tpl->setVariable('CUSTOMER_COUNTRY', $bookings[$i]['country']);
166 
167  $tpl->setVariable('BILL_NO', $transaction);
168  $tpl->setVariable('DATE', ilDatePresentation::formatDate(new ilDateTime($bookings[$i]['order_date'], IL_CAL_UNIX)));
169 
170  $tpl->setVariable('TXT_BILL', utf8_decode($this->lng->txt('pays_bill')));
171  $tpl->setVariable('TXT_BILL_NO', utf8_decode($this->lng->txt('pay_bill_no')));
172  $tpl->setVariable('TXT_DATE', utf8_decode($this->lng->txt('date')));
173 
174  $tpl->setVariable('TXT_ARTICLE', utf8_decode($this->lng->txt('pay_article')));
175  $tpl->setVariable('TXT_VAT_RATE', utf8_decode($this->lng->txt('vat_rate')));
176  $tpl->setVariable('TXT_VAT_UNIT', utf8_decode($this->lng->txt('vat_unit')));
177  $tpl->setVariable('TXT_PRICE', utf8_decode($this->lng->txt('price_a')));
178 
179  for ($i = 0; $i < count($bookings[$i]); $i++)
180  {
181  $tmp_pobject = new ilPaymentObject($this->user_obj, $booking[$i]['pobject_id']);
182 
183  $obj_id = $ilObjDataCache->lookupObjId($bookings[$i]['ref_id']);
184  $obj_type = $ilObjDataCache->lookupType($obj_id);
185 
186  $tpl->setCurrentBlock('loop');
187  $tpl->setVariable('LOOP_OBJ_TYPE', utf8_decode($this->lng->txt($obj_type)));
188  $tpl->setVariable('LOOP_TITLE', utf8_decode($bookings[$i]['object_title']) . $assigned_coupons);
189  $tpl->setVariable('LOOP_TXT_ENTITLED_RETRIEVE', utf8_decode($this->lng->txt('pay_entitled_retrieve')));
190 
191  if( $bookings[$i]['duration'] == 0)
192  {
193  $tpl->setVariable('LOOP_DURATION', utf8_decode($this->lng->txt('unlimited_duration')));
194  }
195  else
196  {
197  $tpl->setVariable('LOOP_DURATION', $bookings[$i]['duration'] . ' ' . utf8_decode($this->lng->txt('paya_months')));
198  }
199 
200  // old one
201  $tpl->setVariable('LOOP_VAT_RATE',number_format($bookings[$i]['vat_rate'], 2, ',', '.').' %');
202  $tpl->setVariable('LOOP_VAT_UNIT', number_format($bookings[$i]['vat_unit'], 2, ',', '.').' '.$currency);
203  $tpl->setVariable('LOOP_PRICE',number_format($bookings[$i]['price'], 2, ',', '.').' '.$currency);
204  $tpl->parseCurrentBlock('loop');
205 
206  // TODO: CURRENCY not finished yet
207  /*****
208  $currency_symbol = $bookings[$i]['currency_unit'];
209 
210  $tpl->setVariable('LOOP_VAT_RATE', $bookings[$i]['vat_rate'].' %');
211  # $tpl->setVariable('LOOP_VAT_UNIT', number_format( $bookings[$i]['vat_unit'], 2, ',', '.').' '.$currency);
212  # $tpl->setVariable('LOOP_PRICE',number_format( $bookings[$i]['price'], 2, ',', '.').' '.$currency);
213 
214  $tpl->setVariable('LOOP_VAT_UNIT',utf8_decode( ilPaymentCurrency::_formatPriceToString($bookings[$i]['vat_unit'], $currency_symbol)));
215  $tpl->setVariable('LOOP_PRICE', utf8_decode(ilPaymentCurrency::_formatPriceToString($bookings[$i]['price'], $currency_symbol)));
216  $tpl->parseCurrentBlock('loop');
217 
218  /***** */
219 
220  $bookings['total'] += (float)$bookings[$i]['price'];
221  $bookings['total_vat']+= (float)$bookings[$i]['vat_unit'];
222  $bookings['total_discount'] +=(float) $bookings[$i]['discount'];
223  unset($tmp_pobject);
224 
225  $sub_total_amount = $bookings['total'];
226  }
227 
228  if($bookings['total_discount'] < 0)
229  {
230  $tpl->setCurrentBlock('cloop');
231  $tpl->setVariable('TXT_COUPON', utf8_decode($this->lng->txt('paya_coupons_coupon') . ' ' . $coupon['pcc_code']));
232  $tpl->setVariable('BONUS', number_format($bookings['total_discount'], 2, ',', '.') . ' ' . $currency);
233  // TODO: CURRENCY $tpl->setVariable('BONUS', ilPaymentCurrency::_formatPriceToString($current_coupon_bonus * (-1),$currency_symbol));
234  $tpl->parseCurrentBlock();
235  }
236 
237  $bookings['total'] += $bookings['total_discount'];
238  $tpl->setVariable('TXT_SUBTOTAL_AMOUNT', utf8_decode($this->lng->txt('pay_bmf_subtotal_amount')));
239  $tpl->setVariable('SUBTOTAL_AMOUNT', number_format($sub_total_amount, 2, ',', '.') . ' ' . $currency);
240  // TODO: CURRENCY $tpl->setVariable('SUBTOTAL_AMOUNT', ilPaymentCurrency::_formatPriceToString($sub_total_amount, $currency_symbol));
241 
242  if ($bookings['total'] < 0)
243  {
244  $bookings['total'] = 0.00;
245  // $bookings['total_vat'] = 0.0;
246  }
247 
248  $tpl->setVariable('TXT_TOTAL_AMOUNT', utf8_decode($this->lng->txt('pay_bmf_total_amount')));
249  $tpl->setVariable('TOTAL_AMOUNT', number_format($bookings['total'], 2, ',', '.') . ' ' . $currency);
250  // TODO: CURRENCY $tpl->setVariable('TOTAL_AMOUNT',utf8_decode(ilPaymentCurrency::_formatPriceToString($bookings['total'], $currency_symbol) ));
251  if ($bookings['total_vat'] > 0)
252  {
253  $tpl->setVariable('TOTAL_VAT',number_format( $bookings['total_vat'], 2, ',', '.') . ' ' .$currency);
254  // TODO: CURRENCY $tpl->setVariable('TOTAL_VAT',ilPaymentCurrency::_formatPriceToString($bookings['total_vat'],$currency_symbol));
255  $tpl->setVariable('TXT_TOTAL_VAT', utf8_decode($this->lng->txt('pay_bmf_vat_included')));
256  }
257 
258  $tpl->setVariable('TXT_PAYMENT_TYPE', utf8_decode($this->lng->txt('pay_payed_bill')));
259 
260  if (!@file_exists($genSet->get('pdf_path')))
261  {
262 
263  ilUtil::makeDir($genSet->get('pdf_path'));
264  }
265 
266  if (@file_exists($genSet->get('pdf_path')))
267  {
268  ilUtil::html2pdf($tpl->get(), $genSet->get('pdf_path') . '/' . $transaction . '.pdf');
269  }
270 
271  if (@file_exists($genSet->get('pdf_path') . '/' . $transaction . '.pdf'))
272  {
274  $genSet->get('pdf_path') . '/' . $transaction . '.pdf',
275  $transaction . '.pdf',
276  $a_mime = 'application/pdf'
277  );
278  }
279 
280  @unlink($genSet->get('pdf_path') . '/' . $transaction . '.html');
281  @unlink($genSet->get('pdf_path') . '/' . $transaction . '.pdf');
282  }
283 
284 
285  protected function prepareOutput()
286  {
287  global $ilTabs;
288 
290 
291  $ilTabs->setTabActive('paya_buyed_objects');
292  $ilTabs->setSubTabActive('paya_buyed_objects');
293  }
294  public function showItems()
295  {
296  include_once "./Services/Repository/classes/class.ilRepositoryExplorer.php";
297 
298  $this->initBookingsObject();
299 
300  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
301 
302  if(!count($bookings = $this->bookings_obj->getBookingsOfCustomer($this->user_obj->getId())))
303  {
304  ilUtil::sendInfo($this->lng->txt('pay_not_buyed_any_object'));
305 
306  return true;
307  }
308 
309  $counter = 0;
310 
311  foreach($bookings as $booking)
312  {
313  $tmp_obj = ilObjectFactory::getInstanceByRefId($booking['ref_id'], false);
314 
315  $tmp_vendor = ilObjectFactory::getInstanceByObjId($booking['b_vendor_id']);
316  $tmp_purchaser = ilObjectFactory::getInstanceByObjId($booking['customer_id']);
317 
318  $transaction = $booking['transaction'];
319 
320  include_once './Services/Payment/classes/class.ilPayMethods.php';
321  $str_paymethod = ilPayMethods::getStringByPaymethod($booking['b_pay_method']);
322  $transaction .= " (" . $str_paymethod . ")";
323  $f_result[$counter]['transaction'] = $transaction;
324 
325  if($tmp_obj)
326  {
327  $obj_link = ilRepositoryExplorer::buildLinkTarget($booking['ref_id'],$tmp_obj->getType());
328  $obj_target = ilRepositoryExplorer::buildFrameTarget($tmp_obj->getType(),$booking['ref_id'],$tmp_obj->getId());
329  $f_result[$counter]['object_title'] = "<a href=\"".$obj_link."\" target=\"".$obj_target."\">".$tmp_obj->getTitle()."</a>";
330  }
331  else
332  {
333  $obj_link = '';
334  $obj_target = '';
335  $f_result[$counter]['object_title'] = $booking['object_title'].'<br> ('.$this->lng->txt('object_deleted').')';
336  }
337  /*
338  if ($tmp_obj->getType() == "crs")
339  {
340  $f_result[$counter][] = "<a href=\"" . ILIAS_HTTP_PATH . "/repository.php?ref_id=" .
341  $booking["ref_id"] . "\">" . $tmp_obj->getTitle() . "</a>";
342  }
343  else if ($tmp_obj->getType() == "lm")
344  {
345  $f_result[$counter][] = "<a href=\"" . ILIAS_HTTP_PATH . "/content/lm_presentation.php?ref_id=" .
346  $booking["ref_id"] . "\" target=\"_blank\">" . $tmp_obj->getTitle() . "</a>";
347  }
348  else
349  {
350  $f_result[$counter][] = $tmp_obj->getTitle();
351  }
352  */
353  $f_result[$counter]['vendor'] = '['.$tmp_vendor->getLogin().']';
354  $f_result[$counter]['customer'] = '['.$tmp_purchaser->getLogin().']';
355  $f_result[$counter]['order_date'] = ilDatePresentation::formatDate(new ilDateTime($booking['order_date'], IL_CAL_UNIX));
356 
357  if($booking['duration'] != 0)
358  {
359  $f_result[$counter]['duration'] = $booking['duration'].' '.$this->lng->txt('paya_months');
360  }
361  else
362  {
363  $f_result[$counter]['duration'] = $this->lng->txt("unlimited_duration");
364  }
365  $f_result[$counter]['price'] = $booking['price'].' '.$booking['currency_unit'];
366  $f_result[$counter]['discount'] = ($booking['discount'] != '' ? ($booking['discount'].' '.$booking['currency_unit']) : '&nbsp;');
367 // TODO CURRENCY
368 /*
369  $f_result[$counter][] = ilPaymentCurrency::_formatPriceToString($booking['price'], $booking['currency_unit']);
370  $f_result[$counter][] = ($booking['discount'] != '' ? ilPaymentCurrency::_formatPriceToString($booking['discount']) : '&nbsp;');
371 
372  */
373  $payed_access = $booking['payed'] ?
374  $this->lng->txt('yes') :
375  $this->lng->txt('no');
376 
377  $payed_access .= '/';
378  $payed_access .= $booking['access_granted'] ?
379  $this->lng->txt('yes') :
380  $this->lng->txt('no');
381 
382  $f_result[$counter]['payed_access'] = $payed_access;
383 
384  unset($tmp_obj);
385  unset($tmp_vendor);
386  unset($tmp_purchaser);
387 
388  ++$counter;
389  }
390  return $this->showStatisticTable($f_result);
391  }
392 
393  private function showStatisticTable($a_result_set)
394  {
395  $tbl = new ilShopTableGUI($this);
396  $tbl->setTitle($this->lng->txt("paya_buyed_objects"));
397  $tbl->setId('tbl_bought_objects');
398  $tbl->setRowTemplate("tpl.shop_statistics_row.html", "Services/Payment");
399 
400  $tbl->addColumn($this->lng->txt('paya_transaction'), 'transaction', '10%');
401  $tbl->addColumn($this->lng->txt('title'), 'object_title', '10%');
402  $tbl->addColumn($this->lng->txt('paya_vendor'), 'vendor', '10%');
403  $tbl->addColumn($this->lng->txt('paya_customer'), 'customer', '10%');
404  $tbl->addColumn($this->lng->txt('paya_order_date'), 'order_date', '10%');
405  $tbl->addColumn($this->lng->txt('duration'), 'duration', '10%');
406  $tbl->addColumn($this->lng->txt('price_a'), 'price', '5%');
407  $tbl->addColumn($this->lng->txt('paya_coupons_coupon'), 'discount', '5%');
408  $tbl->addColumn($this->lng->txt('paya_payed_access'), 'payed_access', '5%');
409 
410  $tbl->setData($a_result_set);
411 
412  $this->tpl->setVariable('TABLE', $tbl->getHTML());
413 
414  return true;
415  }
416 
417  private function initBookingsObject()
418  {
419  include_once './Services/Payment/classes/class.ilPaymentBookings.php';
420 
421  $this->bookings_obj = new ilPaymentBookings();
422 
423  return true;
424  }
425 }
426 ?>