function createBill() { global $tpl, $ilObjDataCache; $customer = $this->user_obj; $transaction = $_GET['transaction']; // $total_price = 0; // $total_vat = 0; $i = 0; include_once './Services/UICore/classes/class.ilTemplate.php'; include_once './Services/Utilities/classes/class.ilUtil.php'; include_once './Services/Payment/classes/class.ilPaymentSettings.php'; $genSet = ilPaymentSettings::_getInstance(); $currency = $genSet->get('currency_unit'); $user_id = $this->user_obj->getId(); $bookings = ilPaymentBookings::__readBillByTransaction($user_id, $transaction); if ($bookings[$i]['street'] == NULL) { $bookings[$i]['street'] = nl2br(utf8_decode($customer->getStreet())); } if ($bookings[$i]['zipcode'] == NULL) { $bookings[$i]['zipcode'] = nl2br(utf8_decode($customer->getZipcode())); } if ($bookings[$i]['city'] == NULL) { $bookings[$i]['city'] = nl2br(utf8_decode($customer->getCity())); } if ($bookings[$i]['country'] == NULL) { $bookings[$i]['country'] = nl2br(utf8_decode($customer->getCountry())); } if (2 == strlen($bookings[$i]['country'])) { $this->lng->loadLanguageModule('meta'); $bookings[$i]['country'] = utf8_decode($this->lng->txt('meta_c_' . strtoupper($bookings[$i]['country']))); } $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.pay_bill.html', 'Services/Payment'); $tpl = new ilTemplate('tpl.pay_bill.html', true, true, 'Services/Payment'); if ($tpl->placeholderExists('HTTP_PATH')) { $http_path = ilUtil::_getHttpPath(); $tpl->setVariable('HTTP_PATH', $http_path); } ilDatePresentation::setUseRelativeDates(false); $tpl->setVariable('DATE', utf8_decode(ilDatePresentation::formatDate(new ilDate($bookings[$i]['order_date'], IL_CAL_UNIX)))); $tpl->setVariable('TXT_CREDIT', utf8_decode($this->lng->txt('credit'))); $tpl->setVariable('TXT_DAY_OF_SERVICE_PROVISION', $this->lng->txt('day_of_service_provision')); include_once './Services/Payment/classes/class.ilPayMethods.php'; $str_paymethod = ilPayMethods::getStringByPaymethod($bookings[$i]['b_pay_method']); if (strlen(trim($bookings[$i]['transaction_extern']))) { $tpl->setVariable('TXT_EXTERNAL_BILL_NO', str_replace('%s', $str_paymethod, utf8_decode($this->lng->txt('external_bill_no')))); $tpl->setVariable('EXTERNAL_BILL_NO', $bookings[$i]['transaction_extern']); } $tpl->setVariable('TXT_POSITION', $this->lng->txt('position')); $tpl->setVariable('TXT_AMOUNT', $this->lng->txt('amount')); $tpl->setVariable('TXT_UNIT_PRICE', utf8_decode($this->lng->txt('unit_price'))); $tpl->setVariable('VENDOR_ADDRESS', nl2br(utf8_decode($genSet->get('address')))); $tpl->setVariable('VENDOR_ADD_INFO', nl2br(utf8_decode($genSet->get('add_info')))); $tpl->setVariable('VENDOR_BANK_DATA', nl2br(utf8_decode($genSet->get('bank_data')))); $tpl->setVariable('TXT_BANK_DATA', utf8_decode($this->lng->txt('pay_bank_data'))); $tpl->setVariable('CUSTOMER_FIRSTNAME', utf8_decode($customer->getFirstName())); // $customer['vorname']); $tpl->setVariable('CUSTOMER_LASTNAME', utf8_decode($customer->getLastName())); //$customer['nachname']); if ($bookings['po_box'] == '') { $tpl->setVariable('CUSTOMER_STREET', utf8_decode($bookings[$i]['street'])); } else { $tpl->setVariable('CUSTOMER_STREET', utf8_decode($bookings[$i]['po_box'])); } $tpl->setVariable('CUSTOMER_ZIPCODE', utf8_decode($bookings[$i]['zipcode'])); $tpl->setVariable('CUSTOMER_CITY', utf8_decode($bookings[$i]['city'])); $tpl->setVariable('CUSTOMER_COUNTRY', utf8_decode($bookings[$i]['country'])); $tpl->setVariable('BILL_NO', $transaction); $tpl->setVariable('TXT_BILL', utf8_decode($this->lng->txt('pays_bill'))); $tpl->setVariable('TXT_BILL_NO', utf8_decode($this->lng->txt('pay_bill_no'))); $tpl->setVariable('TXT_DATE', utf8_decode($this->lng->txt('date'))); $tpl->setVariable('TXT_ARTICLE', utf8_decode($this->lng->txt('pay_article'))); $tpl->setVariable('TXT_VAT_RATE', utf8_decode($this->lng->txt('vat_rate'))); $tpl->setVariable('TXT_VAT_UNIT', utf8_decode($this->lng->txt('vat_unit'))); $tpl->setVariable('TXT_PRICE', utf8_decode($this->lng->txt('price_a'))); for ($i = 0; $i < count($bookings[$i]); $i++) { $tmp_pobject = new ilPaymentObject($this->user_obj, $bookings[$i]['pobject_id']); $obj_id = $ilObjDataCache->lookupObjId($bookings[$i]['ref_id']); $obj_type = $ilObjDataCache->lookupType($obj_id); $tpl->setCurrentBlock('loop'); $tpl->setVariable('LOOP_POSITION', $i + 1); $tpl->setVariable('LOOP_AMOUNT', '1'); $tpl->setVariable('LOOP_TXT_PERIOD_OF_SERVICE_PROVISION', utf8_decode($this->lng->txt('period_of_service_provision'))); $tpl->setVariable('LOOP_OBJ_TYPE', utf8_decode($this->lng->txt($obj_type))); $tpl->setVariable('LOOP_TITLE', utf8_decode($bookings[$i]['object_title']) . $assigned_coupons); $tpl->setVariable('LOOP_TXT_ENTITLED_RETRIEVE', utf8_decode($this->lng->txt('pay_entitled_retrieve'))); if ($bookings[$i]['duration'] == 0 && $bookings[$i]['access_enddate'] == NULL) { $tpl->setVariable('LOOP_DURATION', utf8_decode($this->lng->txt('unlimited_duration'))); } else { $access_startdate = utf8_decode(ilDatePresentation::formatDate(new ilDate($bookings[$i]['access_startdate'], IL_CAL_DATETIME))); $access_enddate = utf8_decode(ilDatePresentation::formatDate(new ilDate($bookings[$i]['access_enddate'], IL_CAL_DATETIME))); $tpl->setVariable('LOOP_DURATION', $access_startdate . ' - ' . $access_enddate . ' / ' . $bookings[$i]['duration'] . ' ' . utf8_decode($this->lng->txt('paya_months'))); } // old one $tpl->setVariable('LOOP_VAT_RATE', number_format($bookings[$i]['vat_rate'], 2, ',', '.') . ' %'); $tpl->setVariable('LOOP_VAT_UNIT', number_format($bookings[$i]['vat_unit'], 2, ',', '.') . ' ' . $currency); $tpl->setVariable('LOOP_UNIT_PRICE', number_format($bookings[$i]['price'], 2, ',', '.') . ' ' . $currency); $tpl->setVariable('LOOP_PRICE', number_format($bookings[$i]['price'], 2, ',', '.') . ' ' . $currency); $tpl->parseCurrentBlock('loop'); $bookings['total'] += (double) $bookings[$i]['price']; $bookings['total_vat'] += (double) $bookings[$i]['vat_unit']; $bookings['total_discount'] += (double) $bookings[$i]['discount']; unset($tmp_pobject); $sub_total_amount = $bookings['total']; } $bookings['total'] += $bookings['total_discount']; if ($bookings['total_discount'] < 0) { $tpl->setCurrentBlock('cloop'); $tpl->setVariable('TXT_SUBTOTAL_AMOUNT', utf8_decode($this->lng->txt('pay_bmf_subtotal_amount'))); $tpl->setVariable('SUBTOTAL_AMOUNT', number_format($sub_total_amount, 2, ',', '.') . ' ' . $currency); $tpl->setVariable('TXT_COUPON', utf8_decode($this->lng->txt('paya_coupons_coupon') . ' ' . $coupon['pcc_code'])); $tpl->setVariable('BONUS', number_format($bookings['total_discount'], 2, ',', '.') . ' ' . $currency); $tpl->parseCurrentBlock(); } if ($bookings['total'] < 0) { $bookings['total'] = 0.0; // $bookings['total_vat'] = 0.0; } $total_net_price = $sub_total_amount - $bookings['total_vat']; $tpl->setVariable('TXT_TOTAL_NETPRICE', utf8_decode($this->lng->txt('total_netprice'))); $tpl->setVariable('TOTAL_NETPRICE', number_format($total_net_price, 2, ',', '.') . ' ' . $currency); $tpl->setVariable('TXT_TOTAL_AMOUNT', utf8_decode($this->lng->txt('pay_bmf_total_amount'))); $tpl->setVariable('TOTAL_AMOUNT', number_format($bookings['total'], 2, ',', '.') . ' ' . $currency); if ($bookings['total_vat'] > 0) { $tpl->setVariable('TOTAL_VAT', number_format($bookings['total_vat'], 2, ',', '.') . ' ' . $currency); $tpl->setVariable('TXT_TOTAL_VAT', utf8_decode($this->lng->txt('plus_vat'))); } if (1 == $bookings[0]['b_pay_method']) { $tpl->setVariable('TXT_PAYMENT_TYPE', utf8_decode($this->lng->txt('pay_unpayed_bill'))); } else { $tpl->setVariable('TXT_PAYMENT_TYPE', utf8_decode($this->lng->txt('pay_payed_bill'))); } if (!@file_exists($genSet->get('pdf_path'))) { ilUtil::makeDir($genSet->get('pdf_path')); } $file_name = time(); if (@file_exists($genSet->get('pdf_path'))) { ilUtil::html2pdf($tpl->get(), $genSet->get('pdf_path') . '/' . $file_name . '.pdf'); } if (@file_exists($genSet->get('pdf_path') . '/' . $file_name . '.pdf')) { ilUtil::deliverFile($genSet->get('pdf_path') . '/' . $file_name . '.pdf', $transaction . '.pdf', $a_mime = 'application/pdf'); } @unlink($genSet->get('pdf_path') . '/' . $file_name . '.html'); @unlink($genSet->get('pdf_path') . '/' . $file_name . '.pdf'); }
public function __sendBill($bookings) { global $tpl, $ilSetting; $i = 0; include_once './Services/UICore/classes/class.ilTemplate.php'; include_once './Services/Utilities/classes/class.ilUtil.php'; include_once './Services/Payment/classes/class.ilPaymentSettings.php'; include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php'; include_once 'Services/Mail/classes/class.ilMimeMail.php'; // $psc_obj = new ilPaymentShoppingCart($this->user_obj); $genSet = ilPaymentSettings::_getInstance(); $currency = $genSet->get('currency_unit'); // $tpl = new ilTemplate('./Services/Payment/templates/default/tpl.pay_bill.html', true, true, true); $tpl = new ilTemplate('tpl.pay_bill.html', true, true, 'Services/Payment'); if ($tpl->placeholderExists('HTTP_PATH')) { $http_path = ilUtil::_getHttpPath(); $tpl->setVariable('HTTP_PATH', $http_path); } ilDatePresentation::setUseRelativeDates(false); $tpl->setVariable('DATE', utf8_decode(ilDatePresentation::formatDate(new ilDate($bookings['list'][$i]['order_date'], IL_CAL_UNIX)))); $tpl->setVariable('TXT_CREDIT', utf8_decode($this->lng->txt('credit'))); $tpl->setVariable('TXT_DAY_OF_SERVICE_PROVISION', $this->lng->txt('day_of_service_provision')); include_once './Services/Payment/classes/class.ilPayMethods.php'; $str_paymethod = ilPayMethods::getStringByPaymethod($bookings['list'][$i]['b_pay_method']); if (strlen(trim($bookings['transaction_extern']))) { $tpl->setVariable('TXT_EXTERNAL_BILL_NO', str_replace('%s', $str_paymethod, utf8_decode($this->lng->txt('external_bill_no')))); $tpl->setVariable('EXTERNAL_BILL_NO', $bookings['transaction_extern']); } $tpl->setVariable('TXT_POSITION', $this->lng->txt('position')); $tpl->setVariable('TXT_AMOUNT', $this->lng->txt('amount')); $tpl->setVariable('TXT_UNIT_PRICE', utf8_decode($this->lng->txt('unit_price'))); $tpl->setVariable('VENDOR_ADDRESS', nl2br(utf8_decode($genSet->get('address')))); $tpl->setVariable('VENDOR_ADD_INFO', nl2br(utf8_decode($genSet->get('add_info')))); $tpl->setVariable('VENDOR_BANK_DATA', nl2br(utf8_decode($genSet->get('bank_data')))); $tpl->setVariable('TXT_BANK_DATA', utf8_decode($this->lng->txt('pay_bank_data'))); $tpl->setVariable('CUSTOMER_FIRSTNAME', utf8_decode($this->user_obj->getFirstname())); $tpl->setVariable('CUSTOMER_LASTNAME', utf8_decode($this->user_obj->getLastname())); if ($bookings['po_box'] == '') { $tpl->setVariable('CUSTOMER_STREET', utf8_decode($bookings['street'])); // contains also housenumber } else { $tpl->setVariable('CUSTOMER_STREET', utf8_decode($bookings['po_box'])); } $tpl->setVariable('CUSTOMER_ZIPCODE', utf8_decode($bookings['zipcode'])); $tpl->setVariable('CUSTOMER_CITY', utf8_decode($bookings['city'])); $tpl->setVariable('CUSTOMER_COUNTRY', utf8_decode($bookings['country'])); $tpl->setVariable('BILL_NO', $bookings['transaction']); $tpl->setVariable('DATE', date('d.m.Y')); $tpl->setVariable('TXT_BILL', utf8_decode($this->lng->txt('pays_bill'))); $tpl->setVariable('TXT_BILL_NO', utf8_decode($this->lng->txt('pay_bill_no'))); $tpl->setVariable('TXT_DATE', utf8_decode($this->lng->txt('date'))); $tpl->setVariable('TXT_ARTICLE', utf8_decode($this->lng->txt('pay_article'))); $tpl->setVariable('TXT_VAT_RATE', utf8_decode($this->lng->txt('vat_rate'))); $tpl->setVariable('TXT_VAT_UNIT', utf8_decode($this->lng->txt('vat_unit'))); $tpl->setVariable('TXT_PRICE', utf8_decode($this->lng->txt('price_a'))); for ($i = 0; $i < count($bookings['list']); $i++) { $tmp_pobject = new ilPaymentObject($this->user_obj, $bookings['list'][$i]['pobject_id']); $assigned_coupons = ''; if (!empty($_SESSION['coupons'][$this->session_var])) { foreach ($_SESSION['coupons'][$this->session_var] as $coupon) { $this->coupon_obj->setId($coupon['pc_pk']); $this->coupon_obj->setCurrentCoupon($coupon); if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId())) { $assigned_coupons .= '<br />' . $this->lng->txt('paya_coupons_coupon') . ': ' . $coupon['pcc_code']; } } } $tpl->setCurrentBlock('loop'); $tpl->setVariable('LOOP_POSITION', $i + 1); $tpl->setVariable('LOOP_AMOUNT', '1'); $tpl->setVariable('LOOP_TXT_PERIOD_OF_SERVICE_PROVISION', utf8_decode($this->lng->txt('period_of_service_provision'))); $tpl->setVariable('LOOP_OBJ_TYPE', utf8_decode($this->lng->txt($bookings['list'][$i]['type']))); $tpl->setVariable('LOOP_TITLE', $tmp = utf8_decode($bookings['list'][$i]['title'])); $tpl->setVariable('LOOP_COUPON', utf8_decode($assigned_coupons)); $tpl->setVariable('LOOP_TXT_ENTITLED_RETRIEVE', utf8_decode($this->lng->txt('pay_entitled_retrieve'))); if ($bookings['list'][$i]['duration'] == 0 && $bookings['list'][$i]['access_enddate'] == NULL) { $tpl->setVariable('LOOP_DURATION', utf8_decode($this->lng->txt('unlimited_duration'))); } else { $access_startdate = utf8_decode(ilDatePresentation::formatDate(new ilDate($bookings['list'][$i]['access_startdate'], IL_CAL_DATE))); $access_enddate = utf8_decode(ilDatePresentation::formatDate(new ilDate($bookings['list'][$i]['access_enddate'], IL_CAL_DATE))); $tmp_duration = $access_startdate . ' - ' . $access_enddate; if ($bookings['list'][$i]['duration'] > 0) { $tmp_duration .= ' / ' . $bookings['list'][$i]['duration'] . ' ' . utf8_decode($this->lng->txt('paya_months')); } $tpl->setVariable('LOOP_DURATION', $tmp_duration); } #$currency = $bookings['list'][$i]['currency_unit']; $tpl->setVariable('LOOP_VAT_RATE', number_format($bookings['list'][$i]['vat_rate'], 2, ',', '.') . ' %'); $tpl->setVariable('LOOP_VAT_UNIT', number_format($bookings['list'][$i]['vat_unit'], 2, ',', '.') . ' ' . $currency); $tpl->setVariable('LOOP_PRICE', number_format($bookings['list'][$i]['price'], 2, ',', '.') . ' ' . $currency); $tpl->setVariable('LOOP_UNIT_PRICE', number_format($bookings['list'][$i]['price'], 2, ',', '.') . ' ' . $currency); $tpl->parseCurrentBlock('loop'); $bookings['total'] += (double) $bookings[$i]['price']; $bookings['total_vat'] += (double) $bookings[$i]['vat_unit']; #$bookings['total_discount'] +=(float) $bookings[$i]['discount']; unset($tmp_pobject); $sub_total_amount = $bookings['total']; } $bookings['total'] += $bookings['total_discount']; if ($bookings['total_discount'] < 0) { $tpl->setCurrentBlock('cloop'); $tpl->setVariable('TXT_SUBTOTAL_AMOUNT', utf8_decode($this->lng->txt('pay_bmf_subtotal_amount'))); $tpl->setVariable('SUBTOTAL_AMOUNT', number_format($sub_total_amount, 2, ',', '.') . ' ' . $currency); $tpl->setVariable('TXT_COUPON', utf8_decode($this->lng->txt('paya_coupons_coupon'))); $tpl->setVariable('BONUS', number_format($bookings['total_discount'], 2, ',', '.') . ' ' . $currency); $tpl->parseCurrentBlock(); } if ($bookings['total'] < 0) { $bookings['total'] = 0.0; // $bookings['total_vat'] = 0.0; } $total_net_price = $sub_total_amount - $bookings['total_vat']; $tpl->setVariable('TXT_TOTAL_NETPRICE', utf8_decode($this->lng->txt('total_netprice'))); $tpl->setVariable('TOTAL_NETPRICE', number_format($total_net_price, 2, ',', '.') . ' ' . $currency); $tpl->setVariable('TXT_TOTAL_AMOUNT', utf8_decode($this->lng->txt('pay_bmf_total_amount'))); $tpl->setVariable('TOTAL_AMOUNT', number_format($bookings['total'], 2, ',', '.') . ' ' . $currency); if ($bookings['total_vat'] > 0) { $tpl->setVariable('TOTAL_VAT', number_format($bookings['total_vat'], 2, ',', '.') . ' ' . $currency); $tpl->setVariable('TXT_TOTAL_VAT', utf8_decode($this->lng->txt('plus_vat'))); } if (1 == $bookings['list'][0]['b_pay_method']) { $tpl->setVariable('TXT_PAYMENT_TYPE', utf8_decode($this->lng->txt('pay_unpayed_bill'))); } else { $tpl->setVariable('TXT_PAYMENT_TYPE', utf8_decode($this->lng->txt('pay_payed_bill'))); } if (!@file_exists($genSet->get('pdf_path'))) { ilUtil::makeDir($genSet->get('pdf_path')); } $file_name = time(); if (@file_exists($genSet->get('pdf_path'))) { ilUtil::html2pdf($tpl->get(), $genSet->get('pdf_path') . '/' . $file_name . '.pdf'); } if (@file_exists($genSet->get('pdf_path') . '/' . $file_name . '.pdf') && $this->user_obj->getEmail() != '' && $ilSetting->get('admin_email') != '') { $m = new ilMimeMail(); // create the mail $m->From($ilSetting->get('admin_email')); $m->To($this->user_obj->getEmail()); $m->Subject($this->lng->txt('pay_message_subject')); // if there is no mailbillingtext use this as standard $message = $this->lng->txt('pay_message_hello') . ' ' . $this->user_obj->getFirstname() . ' ' . $this->user_obj->getLastname() . ",\n\n"; $message .= $this->lng->txt('pay_message_thanks') . "\n\n"; $message .= $this->lng->txt('pay_message_attachment') . "\n\n"; $message .= $this->lng->txt('pay_message_regards') . "\n\n"; $message .= strip_tags($genSet->get('address')); //replacePlaceholders... $billing_text = $genSet->getMailBillingText(); if (!$billing_text) { $message = ''; } if ($genSet->getMailUsePlaceholders() == 1) { include_once './Services/Payment/classes/class.ilBillingMailPlaceholdersPropertyGUI.php'; $message = ilBillingMailPlaceholdersPropertyGUI::replaceBillingMailPlaceholders($billing_text, $this->user_obj->getId()); } $m->Body($message); // set the body $m->Attach($genSet->get('pdf_path') . '/' . $file_name . '.pdf', 'application/pdf'); // attach a file of type image/gif if ($genSet->get('attach_sr_invoice') == 1) { require_once 'Services/RTE/classes/class.ilRTE.php'; $regulations = ilRTE::_replaceMediaObjectImageSrc($genSet->get('statutory_regulations'), 1); $reg_file_name = 'statutory_regulations'; if (@file_exists($genSet->get('pdf_path'))) { ilUtil::html2pdf($regulations, $genSet->get('pdf_path') . '/' . $reg_file_name . '.pdf'); } $m->Attach($genSet->get('pdf_path') . '/' . $reg_file_name . '.pdf', 'application/pdf'); // attach a file of type image/gif } $m->Send(); // send the mail } @unlink($genSet->get('pdf_path') . '/' . $file_name . '.html'); @unlink($genSet->get('pdf_path') . '/' . $file_name . '.pdf'); unset($current_booking_id); unset($pobject); unset($_SESSION['coupons'][$this->session_var]); $this->ctrl->redirectByClass('ilShopBoughtObjectsGUI', ''); }