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