ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules 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  {
27  parent::__construct();
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  if(!count($bookings = ilPaymentBookings::getBookingsOfCustomer($this->user_obj->getId())))
72  {
73  ilUtil::sendInfo($this->lng->txt('pay_not_buyed_any_object'));
74  return true;
75  }
76 
77  $counter = 0;
78 
79  foreach($bookings as $booking)
80  {
81 
82  $f_result[$counter]['transaction'] = "<a href=\"".$this->ctrl->getLinkTarget($this, "createBill")."&transaction=".$booking['transaction']."\">".$booking['transaction'].".pdf</a>";
83 
84  $f_result[$counter]['order_date'] = ilDatePresentation::formatDate(new ilDateTime($booking['order_date'], IL_CAL_UNIX));
85 
86  ++$counter;
87  }
88  return $this->showBillHistoryTable($f_result);
89  }
90 
91  private function showBillHistoryTable($a_result_set)
92  {
93  $this->ctrl->setParameter($this,'cmd','showBillHistory');
94  $tbl = new ilShopTableGUI($this);
95  $tbl->setId('tbl_bill_history');
96  $tbl->setTitle($this->lng->txt("paya_bill_history"));
97  $tbl->setRowTemplate("tpl.shop_statistics_row.html", "Services/Payment");
98 
99  $tbl->addColumn($this->lng->txt('paya_transaction'), 'transaction', '10%');
100  $tbl->addColumn($this->lng->txt('paya_order_date'), 'order_date', '10%');
101 
102  $tbl->setData($a_result_set);
103 
104  $this->tpl->setVariable('TABLE', $tbl->getHTML());
105  return true;
106  }
107 
108  function createBill()
109  {
110  global $tpl,$ilObjDataCache;
111 
112  $customer=$this->user_obj;
113  $transaction = $_GET['transaction'];
114 
115 // $total_price = 0;
116 // $total_vat = 0;
117  $i = 0;
118 
119  include_once './Services/UICore/classes/class.ilTemplate.php';
120  include_once './Services/Utilities/classes/class.ilUtil.php';
121  include_once './Services/Payment/classes/class.ilPaymentSettings.php';
122 
124  $currency = $genSet->get('currency_unit');
125 
126  $user_id = $this->user_obj->getId();
127 
128  $bookings = ilPaymentBookings::__readBillByTransaction($user_id,$transaction);
129  if($bookings[$i]['street'] == NULL) $bookings[$i]['street'] = nl2br(utf8_decode($customer->getStreet()));
130  if($bookings[$i]['zipcode'] == NULL) $bookings[$i]['zipcode'] = nl2br(utf8_decode($customer->getZipcode()));
131  if($bookings[$i]['city'] == NULL) $bookings[$i]['city'] = nl2br(utf8_decode($customer->getCity()));
132  if($bookings[$i]['country'] == NULL)
133  {
134  $bookings[$i]['country'] = nl2br(utf8_decode($customer->getCountry()));
135  }
136 
137  if(2 == strlen($bookings[$i]['country']))
138  {
139  $this->lng->loadLanguageModule('meta');
140  $bookings[$i]['country'] = utf8_decode($this->lng->txt('meta_c_'.strtoupper($bookings[$i]['country'])));
141  }
142 
143  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.pay_bill.html','Services/Payment');
144  $tpl = new ilTemplate('tpl.pay_bill.html', true, true, 'Services/Payment');
145 
146  if($tpl->placeholderExists('HTTP_PATH'))
147  {
148  $http_path = ilUtil::_getHttpPath();
149  $tpl->setVariable('HTTP_PATH', $http_path);
150  }
152  $tpl->setVariable('DATE', utf8_decode(ilDatePresentation::formatDate(new ilDate($bookings[$i]['order_date'], IL_CAL_UNIX))));
153  $tpl->setVariable('TXT_CREDIT', utf8_decode($this->lng->txt('credit')));
154  $tpl->setVariable('TXT_DAY_OF_SERVICE_PROVISION',$this->lng->txt('day_of_service_provision'));
155  include_once './Services/Payment/classes/class.ilPayMethods.php';
156  $str_paymethod = ilPayMethods::getStringByPaymethod($bookings[$i]['b_pay_method']);
157  if(strlen(trim($bookings[$i]['transaction_extern'])))
158  {
159  $tpl->setVariable('TXT_EXTERNAL_BILL_NO', str_replace('%s',$str_paymethod,utf8_decode($this->lng->txt('external_bill_no'))));
160  $tpl->setVariable('EXTERNAL_BILL_NO', $bookings[$i]['transaction_extern']);
161  }
162  $tpl->setVariable('TXT_POSITION',$this->lng->txt('position'));
163  $tpl->setVariable('TXT_AMOUNT',$this->lng->txt('amount'));
164  $tpl->setVariable('TXT_UNIT_PRICE', utf8_decode($this->lng->txt('unit_price')));
165 
166  $tpl->setVariable('VENDOR_ADDRESS', nl2br(utf8_decode($genSet->get('address'))));
167  $tpl->setVariable('VENDOR_ADD_INFO', nl2br(utf8_decode($genSet->get('add_info'))));
168  $tpl->setVariable('VENDOR_BANK_DATA', nl2br(utf8_decode($genSet->get('bank_data'))));
169  $tpl->setVariable('TXT_BANK_DATA', utf8_decode($this->lng->txt('pay_bank_data')));
170 
171 
172  $tpl->setVariable('CUSTOMER_FIRSTNAME',utf8_decode($customer->getFirstName()));// $customer['vorname']);
173  $tpl->setVariable('CUSTOMER_LASTNAME', utf8_decode($customer->getLastName())); //$customer['nachname']);
174  if($bookings['po_box']== '')
175  {
176  $tpl->setVariable('CUSTOMER_STREET',utf8_decode( $bookings[$i]['street']));
177  }
178  else
179  {
180  $tpl->setVariable('CUSTOMER_STREET', utf8_decode($bookings[$i]['po_box']));
181  }
182  $tpl->setVariable('CUSTOMER_ZIPCODE', utf8_decode($bookings[$i]['zipcode']));
183  $tpl->setVariable('CUSTOMER_CITY', utf8_decode($bookings[$i]['city']));
184  $tpl->setVariable('CUSTOMER_COUNTRY', utf8_decode($bookings[$i]['country']));
185 
186  $tpl->setVariable('BILL_NO', $transaction);
187 
188  $tpl->setVariable('TXT_BILL', utf8_decode($this->lng->txt('pays_bill')));
189  $tpl->setVariable('TXT_BILL_NO', utf8_decode($this->lng->txt('pay_bill_no')));
190  $tpl->setVariable('TXT_DATE', utf8_decode($this->lng->txt('date')));
191 
192  $tpl->setVariable('TXT_ARTICLE', utf8_decode($this->lng->txt('pay_article')));
193  $tpl->setVariable('TXT_VAT_RATE', utf8_decode($this->lng->txt('vat_rate')));
194  $tpl->setVariable('TXT_VAT_UNIT', utf8_decode($this->lng->txt('vat_unit')));
195  $tpl->setVariable('TXT_PRICE', utf8_decode($this->lng->txt('price_a')));
196 
197  for ($i = 0; $i < count($bookings[$i]); $i++)
198  {
199  $tmp_pobject = new ilPaymentObject($this->user_obj, $bookings[$i]['pobject_id']);
200 
201  $obj_id = $ilObjDataCache->lookupObjId($bookings[$i]['ref_id']);
202  $obj_type = $ilObjDataCache->lookupType($obj_id);
203 
204  $tpl->setCurrentBlock('loop');
205  $tpl->setVariable('LOOP_POSITION', $i+1);
206  $tpl->setVariable('LOOP_AMOUNT', '1');
207  $tpl->setVariable('LOOP_TXT_PERIOD_OF_SERVICE_PROVISION', utf8_decode($this->lng->txt('period_of_service_provision')));
208 
209  $tpl->setVariable('LOOP_OBJ_TYPE', utf8_decode($this->lng->txt($obj_type)));
210  $tpl->setVariable('LOOP_TITLE', utf8_decode($bookings[$i]['object_title']) . $assigned_coupons);
211  $tpl->setVariable('LOOP_TXT_ENTITLED_RETRIEVE', utf8_decode($this->lng->txt('pay_entitled_retrieve')));
212 
213  if( $bookings[$i]['duration'] == 0 && $bookings[$i]['access_enddate'] == NULL)
214  {
215  $tpl->setVariable('LOOP_DURATION', utf8_decode($this->lng->txt('unlimited_duration')));
216  }
217  else
218  {
219  $access_startdate = utf8_decode(ilDatePresentation::formatDate(new ilDate($bookings[$i]['access_startdate'], IL_CAL_DATETIME)));
220  $access_enddate = utf8_decode(ilDatePresentation::formatDate(new ilDate($bookings[$i]['access_enddate'], IL_CAL_DATETIME)));
221 
222  $tpl->setVariable('LOOP_DURATION',
223  $access_startdate.' - '.$access_enddate.' / '.
224  $bookings[$i]['duration'] . ' ' . utf8_decode($this->lng->txt('paya_months')));
225  }
226  // old one
227  $tpl->setVariable('LOOP_VAT_RATE',number_format($bookings[$i]['vat_rate'], 2, ',', '.').' %');
228  $tpl->setVariable('LOOP_VAT_UNIT', number_format($bookings[$i]['vat_unit'], 2, ',', '.').' '.$currency);
229  $tpl->setVariable('LOOP_UNIT_PRICE',number_format($bookings[$i]['price'], 2, ',', '.').' '.$currency);
230  $tpl->setVariable('LOOP_PRICE',number_format($bookings[$i]['price'], 2, ',', '.').' '.$currency);
231  $tpl->parseCurrentBlock('loop');
232 
233  $bookings['total'] += (float)$bookings[$i]['price'];
234  $bookings['total_vat']+= (float)$bookings[$i]['vat_unit'];
235  $bookings['total_discount'] +=(float) $bookings[$i]['discount'];
236  unset($tmp_pobject);
237 
238  $sub_total_amount = $bookings['total'];
239  }
240 
241  $bookings['total'] += $bookings['total_discount'];
242  if($bookings['total_discount'] < 0)
243  {
244  $tpl->setCurrentBlock('cloop');
245 
246  $tpl->setVariable('TXT_SUBTOTAL_AMOUNT', utf8_decode($this->lng->txt('pay_bmf_subtotal_amount')));
247  $tpl->setVariable('SUBTOTAL_AMOUNT', number_format($sub_total_amount, 2, ',', '.') . ' ' . $currency);
248 
249  $tpl->setVariable('TXT_COUPON', utf8_decode($this->lng->txt('paya_coupons_coupon') . ' ' . $coupon['pcc_code']));
250  $tpl->setVariable('BONUS', number_format($bookings['total_discount'], 2, ',', '.') . ' ' . $currency);
251  $tpl->parseCurrentBlock();
252  }
253 
254  if ($bookings['total'] < 0)
255  {
256  $bookings['total'] = 0.00;
257  // $bookings['total_vat'] = 0.0;
258  }
259  $total_net_price = $sub_total_amount-$bookings['total_vat'];
260 
261  $tpl->setVariable('TXT_TOTAL_NETPRICE', utf8_decode($this->lng->txt('total_netprice')));
262  $tpl->setVariable('TOTAL_NETPRICE', number_format($total_net_price, 2, ',', '.') . ' ' . $currency);
263 
264  $tpl->setVariable('TXT_TOTAL_AMOUNT', utf8_decode($this->lng->txt('pay_bmf_total_amount')));
265  $tpl->setVariable('TOTAL_AMOUNT', number_format($bookings['total'], 2, ',', '.') . ' ' . $currency);
266  if ($bookings['total_vat'] > 0)
267  {
268  $tpl->setVariable('TOTAL_VAT',number_format( $bookings['total_vat'], 2, ',', '.') . ' ' .$currency);
269  $tpl->setVariable('TXT_TOTAL_VAT', utf8_decode($this->lng->txt('plus_vat')));
270  }
271  if(1 == $bookings[0]['b_pay_method'])
272  {
273  $tpl->setVariable('TXT_PAYMENT_TYPE', utf8_decode($this->lng->txt('pay_unpayed_bill')));
274  }
275  else
276  {
277  $tpl->setVariable('TXT_PAYMENT_TYPE', utf8_decode($this->lng->txt('pay_payed_bill')));
278  }
279 
280  if (!@file_exists($genSet->get('pdf_path')))
281  {
282  ilUtil::makeDir($genSet->get('pdf_path'));
283  }
284 
285  $file_name = time();
286  if (@file_exists($genSet->get('pdf_path')))
287  {
288  ilUtil::html2pdf($tpl->get(), $genSet->get('pdf_path') . '/' . $file_name . '.pdf');
289  }
290 
291  if (@file_exists($genSet->get('pdf_path') . '/' . $file_name . '.pdf'))
292  {
294  $genSet->get('pdf_path') . '/' . $file_name . '.pdf',
295  $transaction . '.pdf',
296  $a_mime = 'application/pdf'
297  );
298  }
299 
300  @unlink($genSet->get('pdf_path') . '/' . $file_name . '.html');
301  @unlink($genSet->get('pdf_path') . '/' . $file_name . '.pdf');
302  }
303 
304  protected function prepareOutput()
305  {
306  global $ilTabs;
307 
308  parent::prepareOutput();
309 
310  $ilTabs->setTabActive('paya_buyed_objects');
311  $ilTabs->setSubTabActive('paya_buyed_objects');
312  }
313  public function showItems()
314  {
315  include_once "./Services/Repository/classes/class.ilRepositoryExplorer.php";
316 
317  $this->initBookingsObject();
318 
319  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
320 
321  if(!count($bookings = ilPaymentBookings::getBookingsOfCustomer($this->user_obj->getId())))
322  {
323  ilUtil::sendInfo($this->lng->txt('pay_not_buyed_any_object'));
324 
325  return true;
326  }
327 
328  $counter = 0;
329 
330  foreach($bookings as $booking)
331  {
332  $tmp_obj = ilObjectFactory::getInstanceByRefId($booking['ref_id'], false);
333  $tmp_vendor = ilObjectFactory::getInstanceByObjId($booking['b_vendor_id'], false);
334  $tmp_purchaser = ilObjectFactory::getInstanceByObjId($booking['customer_id'], false);
335 
336  $transaction = $booking['transaction'];
337 
338  include_once './Services/Payment/classes/class.ilPayMethods.php';
339  $str_paymethod = ilPayMethods::getStringByPaymethod($booking['b_pay_method']);
340  $transaction .= " (" . $str_paymethod . ")";
341  $f_result[$counter]['transaction'] = $transaction;
342 
343  if($tmp_obj)
344  {
345  $obj_link = ilRepositoryExplorer::buildLinkTarget($booking['ref_id'],$tmp_obj->getType());
346  $obj_target = ilRepositoryExplorer::buildFrameTarget($tmp_obj->getType(),$booking['ref_id'],$tmp_obj->getId());
347  $f_result[$counter]['object_title'] = "<a href=\"".$obj_link."\" target=\"".$obj_target."\">".$tmp_obj->getTitle()."</a>";
348  }
349  else
350  {
351  $obj_link = '';
352  $obj_target = '';
353  $f_result[$counter]['object_title'] = $booking['object_title'].'<br> ('.$this->lng->txt('object_deleted').')';
354  }
355  $f_result[$counter]['vendor'] = '['.$tmp_vendor->getLogin().']';
356  $f_result[$counter]['customer'] = '['.$tmp_purchaser->getLogin().']';
357  $f_result[$counter]['order_date'] = ilDatePresentation::formatDate(new ilDateTime($booking['order_date'], IL_CAL_UNIX));
358 //todo check for accessduration!!
359  if($booking['duration'] == 0 && $booking['access_enddate'] == NULL)
360  {
361  $f_result[$counter]['duration'] = $this->lng->txt("unlimited_duration");
362  }
363  else
364  {
365  if($booking['duration'] > 0)
366  {
367  $f_result[$counter]['duration'] = $booking['duration'].' '.$this->lng->txt('paya_months');
368  }
369  $f_result[$counter]['duration'] .= ilDatePresentation::formatDate(new ilDateTime($booking['access_startdate'], IL_CAL_DATETIME))
370  .' - '.ilDatePresentation::formatDate(new ilDateTime($booking['access_enddate'], IL_CAL_DATETIME));
371  }
372  $f_result[$counter]['price'] = $booking['price'].' '.$booking['currency_unit'];
373  $f_result[$counter]['discount'] = ($booking['discount'] != '' ? (round($booking['discount'], 2).' '.$booking['currency_unit']) : '&nbsp;');
374 
375  $payed_access = $booking['payed'] ?
376  $this->lng->txt('yes') :
377  $this->lng->txt('no');
378 
379  $payed_access .= '/';
380  $payed_access .= $booking['access_granted'] ?
381  $this->lng->txt('yes') :
382  $this->lng->txt('no');
383 
384  $f_result[$counter]['payed_access'] = $payed_access;
385 
386  unset($tmp_obj);
387  unset($tmp_vendor);
388  unset($tmp_purchaser);
389 
390  ++$counter;
391  }
392  return $this->showStatisticTable($f_result);
393  }
394 
395  private function showStatisticTable($a_result_set)
396  {
397  $tbl = new ilShopTableGUI($this);
398  $tbl->setTitle($this->lng->txt("paya_buyed_objects"));
399  $tbl->setId('tbl_bought_objects');
400  $tbl->setRowTemplate("tpl.shop_statistics_row.html", "Services/Payment");
401 
402  $tbl->addColumn($this->lng->txt('paya_transaction'), 'transaction', '10%');
403  $tbl->addColumn($this->lng->txt('title'), 'object_title', '10%');
404  $tbl->addColumn($this->lng->txt('paya_vendor'), 'vendor', '10%');
405  $tbl->addColumn($this->lng->txt('paya_customer'), 'customer', '10%');
406  $tbl->addColumn($this->lng->txt('paya_order_date'), 'order_date', '10%');
407  $tbl->addColumn($this->lng->txt('duration'), 'duration', '10%');
408  $tbl->addColumn($this->lng->txt('price_a'), 'price', '5%');
409  $tbl->addColumn($this->lng->txt('paya_coupons_coupon'), 'discount', '5%');
410  $tbl->addColumn($this->lng->txt('paya_payed_access'), 'payed_access', '5%');
411 
412  $tbl->setData($a_result_set);
413 
414  $this->tpl->setVariable('TABLE', $tbl->getHTML());
415 
416  return true;
417  }
418 
419  private function initBookingsObject()
420  {
421  include_once './Services/Payment/classes/class.ilPaymentBookings.php';
422 
423  $this->bookings_obj = new ilPaymentBookings();
424 
425  return true;
426  }
427 }
428 ?>
static getBookingsOfCustomer($a_usr_id)
const IL_CAL_DATETIME
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
buildLinkTarget($a_node_id, $a_type)
note: most of this stuff is used by ilCourseContentInterface too
Class ilShopBaseGUI.
$_GET["client_id"]
Class ilShopBoughtObjectsGUI.
$cmd
Definition: sahs_server.php:35
static getStringByPaymethod($a_type)
static setUseRelativeDates($a_status)
set use relative dates
const IL_CAL_UNIX
Class ilShopTableGUI.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static html2pdf($html, $pdf_file)
produce pdf out of html with htmldoc
Class for single dates.
special template class to simplify handling of ITX/PEAR
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
buildFrameTarget($a_type, $a_child=0, $a_obj_id=0)
STATIC, do not use $this inside!
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static _getHttpPath()
static __readBillByTransaction($a_user_id, $a_transaction_nr)