public function __construct($user_obj)
 {
     $this->user_obj = $user_obj;
     $this->pay_method = ilPayMethods::_getIdByTitle('paypal');
     $ppSet = ilPaypalSettings::getInstance();
     $this->paypalConfig = $ppSet->getAll();
     parent::__construct($this->user_obj, $this->pay_method);
 }
 function ilPurchaseBMFGUI($user_obj)
 {
     $this->pm_id = ilPayMethods::_getIdByTitle('bmf');
     $this->pay_method = ilPayMethods::_getIdByTitle('bmf');
     // Get user object
     $this->user_obj = $user_obj;
     parent::__construct($this->user_obj, $this->pay_method);
 }
 public function __construct($user_obj)
 {
     $this->user_obj = $user_obj;
     $this->pay_method = ilPayMethods::_getIdByTitle('bill');
     parent::__construct($user_obj, $this->pay_method);
     $this->setAccess(0);
     $this->setPayed(0);
 }
 public function __construct($user_obj, $a_pobject_id = null)
 {
     global $ilDB;
     $this->db = $ilDB;
     $this->user_obj = $user_obj;
     $this->STATUS_NOT_BUYABLE = 0;
     $this->STATUS_BUYABLE = 1;
     $this->STATUS_EXPIRES = 2;
     $this->PAY_METHOD_NOT_SPECIFIED = 0;
     $this->pobject_id = $a_pobject_id;
     include_once './Services/Payment/classes/class.ilPayMethods.php';
     $pmObj = new ilPayMethods();
     $tmp = $pmObj->readAll();
     foreach ($tmp as $pm) {
         $tmp = strtoupper($pm['pm_title']);
         $this->PAY_METHOD_ . ($tmp = $pm['pm_id']);
     }
     $this->__read();
 }
 public function deleteAddressesForPaymethodsObject()
 {
     // delete addresses here
     include_once './Services/Payment/classes/class.ilPayMethods.php';
     $this->__initBookingObject();
     foreach ($_POST['paymethod'] as $pay_method) {
         ilPayMethods::_disableSaveUserAddress($pay_method);
         $del_bookings = $this->booking_obj->deleteAddressesByPaymethod((int) $pay_method);
     }
     ilUtil::sendSuccess($this->lng->txt('pays_updated_pay_method'));
     return $this->payMethodsObject();
 }
 private function showItemsTable(&$a_tpl, $a_result_set, $a_pay_method = 0)
 {
     include_once './Services/Payment/classes/class.ilPaymentSettings.php';
     $genSet = ilPaymentSettings::_getInstance();
     include_once './Services/Payment/classes/class.ilShoppingCartTableGUI.php';
     $tbl = new ilShoppingCartTableGUI($this);
     $tbl->setId('tbl_id_' . $a_pay_method);
     $tbl->setTitle($this->lng->txt('paya_shopping_cart') . " (" . $this->lng->txt('payment_system') . ": " . ilPayMethods::getStringByPaymethod($a_pay_method['pm_title']) . ")");
     $coupon_session = $a_pay_method['pm_title'];
     $tbl->setRowTemplate("tpl.shop_shoppingcart_row.html", "Services/Payment");
     $tbl->addColumn('', 'item', '1%', true);
     $tbl->addColumn($this->lng->txt('title'), "table" . $a_pay_method['pm_title'] . "_title", '30%');
     $tbl->addColumn($this->lng->txt('duration'), "table" . $a_pay_method['pm_title'] . "_duration", '30%');
     $tbl->addColumn($this->lng->txt('vat_rate'), "table" . $a_pay_method['pm_title'] . "_vat_rate", '15%');
     $tbl->addColumn($this->lng->txt('vat_unit'), "table" . $a_pay_method['pm_title'] . "_vat_unit", '15%');
     $tbl->addColumn($this->lng->txt('price_a'), "table" . $a_pay_method['pm_title'] . "_price", '10%');
     $tbl->setPrefix("table" . $a_pay_method['pm_title'] . "_");
     $tbl->addMultiCommand('deleteItem', $this->lng->txt('delete'));
     // show total amount of costs
     $sc_obj = new ilPaymentShoppingCart($this->user_obj);
     $totalAmount = $sc_obj->getTotalAmount();
     if (!empty($_SESSION['coupons'][$coupon_session])) {
         if (count($items = $sc_obj->getEntries($a_pay_method['pm_id']))) {
             $tbl->setTotalData('TXT_SUB_TOTAL', $this->lng->txt('pay_bmf_subtotal_amount') . ": ");
             $tbl->setTotalData('VAL_SUB_TOTAL', number_format($totalAmount[$a_pay_method['pm_id']], 2, ',', '.') . " " . $genSet->get('currency_unit'));
             foreach ($_SESSION['coupons'][$coupon_session] as $coupon) {
                 $this->coupon_obj->setId($coupon['pc_pk']);
                 $this->coupon_obj->setCurrentCoupon($coupon);
                 $total_object_price = 0.0;
                 $current_coupon_bonus = 0.0;
                 foreach ($items as $item) {
                     $tmp_pobject = new ilPaymentObject($this->user_obj, $item['pobject_id']);
                     if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId())) {
                         $price_data = ilPaymentPrices::_getPrice($item['price_id']);
                         $price = (double) $price_data['price'];
                         $total_object_price += $price;
                     }
                     unset($tmp_pobject);
                 }
                 $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
                 $totalAmount[$current_coupon_bonus] += $current_coupon_bonus * -1;
             }
             $tbl->setTotalData('TXT_COUPON_BONUS', $this->lng->txt('paya_coupons_coupon') . ": ");
             # . $coupon['pcc_code'] . ": ");
             #$tbl->setTotalData('VAL_COUPON_BONUS', number_format($current_coupon_bonus * (-1), 2, ',', '.') . " " . $genSet->get('currency_unit'));
             $tbl->setTotalData('VAL_COUPON_BONUS', number_format($totalAmount[$current_coupon_bonus], 2, ',', '.') . " " . $genSet->get('currency_unit'));
             if ($totalAmount[$a_pay_method['pm_id']] < 0) {
                 $totalAmount[$a_pay_method['pm_id']] = 0;
                 $this->totalVat = 0;
             }
         }
     }
     $this->totalAmount[$a_pay_method['pm_id']] = $totalAmount[$a_pay_method['pm_id']] - $totalAmount[$current_coupon_bonus] * -1;
     $tbl->setTotalData('TXT_TOTAL_AMOUNT', $this->lng->txt('pay_bmf_total_amount') . ": ");
     $tbl->setTotalData('VAL_TOTAL_AMOUNT', number_format($this->totalAmount[$a_pay_method['pm_id']], 2, ',', '.') . " " . $genSet->get('currency_unit'));
     #.$item['currency']);
     if ($this->totalVat > 0) {
         $tbl->setTotalData('TXT_TOTAL_VAT', $this->lng->txt('pay_bmf_vat_included') . ": ");
         $tbl->setTotalData('VAL_TOTAL_VAT', number_format($this->totalVat, 2, ',', '.') . " " . $genSet->get('currency_unit'));
     }
     $tbl->setData($a_result_set);
     $a_tpl->setVariable('ITEMS_TABLE', $tbl->getCartHTML());
     return true;
 }
 public function add()
 {
     include_once './Services/Payment/classes/class.ilPaymentPrices.php';
     switch ($this->getPriceType()) {
         case ilPaymentPrices::TYPE_DURATION_DATE:
             // do nothing. access_startdate, access_enddate is already set
             break;
         case ilPaymentPrices::TYPE_DURATION_MONTH:
         case ilPaymentPrices::TYPE_UNLIMITED_DURATION:
             if ($this->getAccessExtension() == 1) {
                 $this->__checkExtensionDependencies();
             } else {
                 $this->setAccessStartdate(date('Y-m-d H:i:s', $this->getOrderDate()));
                 if ($this->getDuration() > 0) {
                     $this->__calculateAccessEnddate();
                 }
             }
             break;
         default:
             return false;
             // price_type_not_set!!!
             break;
     }
     $next_id = $this->db->nextId('payment_statistic');
     if (ilPayMethods::_EnabledSaveUserAddress((int) $this->getPayMethod()) == 1) {
         $statement = $this->db->insert('payment_statistic', array('booking_id' => array('integer', $next_id), 'transaction' => array('text', $this->getTransaction()), 'pobject_id' => array('integer', $this->getPobjectId()), 'customer_id' => array('integer', $this->getCustomerId()), 'b_vendor_id' => array('integer', $this->getVendorId()), 'b_pay_method' => array('integer', $this->getPayMethod()), 'order_date' => array('integer', $this->getOrderDate()), 'duration' => array('text', $this->getDuration()), 'price' => array('float', $this->getPrice()), 'discount' => array('float', $this->getDiscount()), 'payed' => array('integer', $this->getPayedStatus()), 'access_granted' => array('integer', $this->getAccessStatus()), 'voucher' => array('text', $this->getVoucher()), 'transaction_extern' => array('text', $this->getTransactionExtern()), 'street' => array('text', $this->getStreet()), 'po_box' => array('text', $this->getPoBox()), 'zipcode' => array('text', $this->getZipcode()), 'city' => array('text', $this->getCity()), 'country' => array('text', $this->getCountry()), 'vat_rate' => array('float', $this->getVatRate()), 'vat_unit' => array('float', $this->getVatUnit()), 'object_title' => array('text', $this->getObjectTitle()), 'email_extern' => array('text', $this->getEmailExtern()), 'name_extern' => array('text', $this->getNameExtern()), 'currency_unit' => array('text', $this->getCurrencyUnit()), 'access_startdate' => array('timestamp', $this->getAccessStartdate()), 'access_enddate' => array('timestamp', $this->getAccessEnddate())));
     } else {
         $statement = $this->db->insert('payment_statistic', array('booking_id' => array('integer', $next_id), 'transaction' => array('text', $this->getTransaction()), 'pobject_id' => array('integer', $this->getPobjectId()), 'customer_id' => array('integer', $this->getCustomerId()), 'b_vendor_id' => array('integer', $this->getVendorId()), 'b_pay_method' => array('integer', $this->getPayMethod()), 'order_date' => array('integer', $this->getOrderDate()), 'duration' => array('text', $this->getDuration()), 'price' => array('float', $this->getPrice()), 'discount' => array('float', $this->getDiscount()), 'payed' => array('integer', $this->getPayedStatus()), 'access_granted' => array('integer', $this->getAccessStatus()), 'voucher' => array('text', $this->getVoucher()), 'transaction_extern' => array('text', $this->getTransactionExtern()), 'vat_rate' => array('float', $this->getVatRate()), 'vat_unit' => array('float', $this->getVatUnit()), 'object_title' => array('text', $this->getObjectTitle()), 'email_extern' => array('text', $this->getEmailExtern()), 'name_extern' => array('text', $this->getNameExtern()), 'currency_unit' => array('text', $this->getCurrencyUnit()), 'access_startdate' => array('timestamp', $this->getAccessStartdate()), 'access_enddate' => array('timestamp', $this->getAccessEnddate())));
     }
     return $next_id;
 }
 public static function getPayMethodsOptions($type = 0)
 {
     global $ilDB, $lng;
     $res = $ilDB->query('SELECT * FROM payment_paymethods WHERE pm_enabled = 1');
     $options = array();
     //this is only for additional entries in SelectInputGUIs
     switch ($type) {
         case 'all':
             $options['all'] = $lng->txt('pay_all');
             break;
         case 'not_specified':
             $options[0] = $lng->txt('paya_pay_method_not_specified');
             break;
             //default: break;
     }
     while ($row = $ilDB->fetchAssoc($res)) {
         $options[$row['pm_id']] = ilPayMethods::getStringByPaymethod($row['pm_title']);
     }
     return $options;
 }
 public function saveCustomer()
 {
     global $ilObjDataCache;
     if (!isset($_GET['sell_id'])) {
         ilUtil::sendInfo($this->lng->txt('paya_error_no_object_id_given'));
         $this->showObjectSelector();
         return true;
     }
     if (!isset($_GET['user_id'])) {
         ilUtil::sendInfo($this->lng->txt('paya_error_no_user_id_given'));
         $this->searchUser();
         return true;
     }
     if ($_POST["pay_method"] == "" || $_POST["duration"] == "") {
         ilUtil::sendInfo($this->lng->txt('paya_error_mandatory_fields'));
         $this->addCustomer();
         return true;
     }
     $pObjectId = ilPaymentObject::_lookupPobjectId($_GET["sell_id"]);
     $obj = new ilPaymentObject($this->user_obj, $pObjectId);
     $this->__initBookingObject();
     $transaction = ilInvoiceNumberPlaceholdersPropertyGUI::_generateInvoiceNumber($_GET["user_id"]);
     $this->booking_obj->setTransaction($transaction);
     $this->booking_obj->setTransactionExtern($_POST["transaction"]);
     $this->booking_obj->setPobjectId($pObjectId);
     $this->booking_obj->setCustomerId($_GET["user_id"]);
     $this->booking_obj->setVendorId($obj->getVendorId());
     $this->booking_obj->setPayMethod((int) $_POST["pay_method"]);
     $this->booking_obj->setOrderDate(time());
     $price = ilPaymentPrices::_getPrice($_POST["duration"]);
     $this->booking_obj->setDuration($price["duration"]);
     $this->booking_obj->setAccessExtension($price['extension']);
     switch ((int) $price['price_type']) {
         case ilPaymentPrices::TYPE_UNLIMITED_DURATION:
             $this->booking_obj->setDuration(0);
             break;
         case ilPaymentPrices::TYPE_DURATION_DATE:
             $this->booking_obj->setAccessStartdate($price['duration_from']);
             $this->booking_obj->setAccessEnddate($price['duration_until']);
             $this->booking_obj->setDuration(0);
             break;
         default:
         case ilPaymentPrices::TYPE_DURATION_MONTH:
             $this->booking_obj->setDuration($price["duration"]);
             break;
     }
     $this->booking_obj->setPriceType($price['price_type']);
     $this->booking_obj->setPrice(ilPaymentPrices::_getPriceString($_POST["duration"]));
     $this->booking_obj->setAccess((int) $_POST['access']);
     $this->booking_obj->setPayed((int) $_POST['payed']);
     $this->booking_obj->setVoucher('');
     $obj_id = $ilObjDataCache->lookupObjId($obj->getRefId());
     $obj_type = $ilObjDataCache->lookupType($obj_id);
     $obj_title = $ilObjDataCache->lookupTitle($obj_id);
     include_once 'Services/Payment/classes/class.ilShopVatsList.php';
     $oVAT = new ilShopVats((int) $obj->getVatId());
     $obj_vat_rate = $oVAT->getRate();
     $obj_vat_unit = $obj->getVat($this->booking_obj->getPrice());
     $this->booking_obj->setObjectTitle($obj_title);
     $this->booking_obj->setVatRate($obj_vat_rate);
     $this->booking_obj->setVatUnit($obj_vat_unit);
     include_once './Services/Payment/classes/class.ilPaymentSettings.php';
     $genSet = ilPaymentSettings::_getInstance();
     $this->booking_obj->setCurrencyUnit($genSet->get('currency_unit'));
     include_once './Services/Payment/classes/class.ilPayMethods.php';
     if (ilPayMethods::_EnabledSaveUserAddress((int) $_POST["pay_method"]) == 1) {
         /**
          * @class $ilObjUser ilObjUser
          */
         global $ilObjUser;
         $user_id[] = $_GET["user_id"];
         $cust_obj = ilObjUser::_readUsersProfileData($user_id);
         $this->booking_obj->setStreet($cust_obj[$_GET["user_id"]]['street'], '');
         $this->booking_obj->setZipcode($cust_obj[$_GET["user_id"]]['zipcode']);
         $this->booking_obj->setCity($cust_obj[$_GET["user_id"]]['city']);
         $this->booking_obj->setCountry($cust_obj[$_GET["user_id"]]['country']);
     }
     if ($this->booking_obj->add()) {
         // add purchased item to desktop
         ilShopUtils::_addPurchasedObjToDesktop($obj, $this->booking_obj->getCustomerId());
         // autosubscribe user if purchased object is a course
         if ($obj_type == 'crs') {
             ilShopUtils::_assignPurchasedCourseMemberRole($obj, $this->booking_obj->getCustomerId());
         }
         ilUtil::sendInfo($this->lng->txt('paya_customer_added_successfully'));
         $this->showStatistics();
     } else {
         ilUtil::sendInfo($this->lng->txt('paya_error_adding_customer'));
         $this->addCustomer();
     }
     return true;
 }
 public function showItems()
 {
     include_once "./Services/Repository/classes/class.ilRepositoryExplorer.php";
     $this->initBookingsObject();
     $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html', 'Services/Payment');
     if (!count($bookings = ilPaymentBookings::getBookingsOfCustomer($this->user_obj->getId()))) {
         ilUtil::sendInfo($this->lng->txt('pay_not_buyed_any_object'));
         return true;
     }
     $counter = 0;
     foreach ($bookings as $booking) {
         $tmp_obj = ilObjectFactory::getInstanceByRefId($booking['ref_id'], false);
         $tmp_vendor = ilObjectFactory::getInstanceByObjId($booking['b_vendor_id'], false);
         $tmp_purchaser = ilObjectFactory::getInstanceByObjId($booking['customer_id'], false);
         $transaction = $booking['transaction'];
         include_once './Services/Payment/classes/class.ilPayMethods.php';
         $str_paymethod = ilPayMethods::getStringByPaymethod($booking['b_pay_method']);
         $transaction .= " (" . $str_paymethod . ")";
         $f_result[$counter]['transaction'] = $transaction;
         if ($tmp_obj) {
             $obj_link = ilRepositoryExplorer::buildLinkTarget($booking['ref_id'], $tmp_obj->getType());
             $obj_target = ilRepositoryExplorer::buildFrameTarget($tmp_obj->getType(), $booking['ref_id'], $tmp_obj->getId());
             $f_result[$counter]['object_title'] = "<a href=\"" . $obj_link . "\" target=\"" . $obj_target . "\">" . $tmp_obj->getTitle() . "</a>";
         } else {
             $obj_link = '';
             $obj_target = '';
             $f_result[$counter]['object_title'] = $booking['object_title'] . '<br> (' . $this->lng->txt('object_deleted') . ')';
         }
         $f_result[$counter]['vendor'] = '[' . $tmp_vendor->getLogin() . ']';
         $f_result[$counter]['customer'] = '[' . $tmp_purchaser->getLogin() . ']';
         $f_result[$counter]['order_date'] = ilDatePresentation::formatDate(new ilDateTime($booking['order_date'], IL_CAL_UNIX));
         //todo check for accessduration!!
         if ($booking['duration'] == 0 && $booking['access_enddate'] == NULL) {
             $f_result[$counter]['duration'] = $this->lng->txt("unlimited_duration");
         } else {
             if ($booking['duration'] > 0) {
                 $f_result[$counter]['duration'] = $booking['duration'] . ' ' . $this->lng->txt('paya_months');
             }
             $f_result[$counter]['duration'] .= ilDatePresentation::formatDate(new ilDateTime($booking['access_startdate'], IL_CAL_DATETIME)) . ' - ' . ilDatePresentation::formatDate(new ilDateTime($booking['access_enddate'], IL_CAL_DATETIME));
         }
         $f_result[$counter]['price'] = $booking['price'] . ' ' . $booking['currency_unit'];
         $f_result[$counter]['discount'] = $booking['discount'] != '' ? round($booking['discount'], 2) . ' ' . $booking['currency_unit'] : '&nbsp;';
         $payed_access = $booking['payed'] ? $this->lng->txt('yes') : $this->lng->txt('no');
         $payed_access .= '/';
         $payed_access .= $booking['access_granted'] ? $this->lng->txt('yes') : $this->lng->txt('no');
         $f_result[$counter]['payed_access'] = $payed_access;
         unset($tmp_obj);
         unset($tmp_vendor);
         unset($tmp_purchaser);
         ++$counter;
     }
     return $this->showStatisticTable($f_result);
 }
 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', '');
 }
 public function showObjects()
 {
     /** 
      * @var $ilToolbar ilToolbarGUI */
     global $ilToolbar;
     include_once './Services/Payment/classes/class.ilPayMethods.php';
     $ilToolbar->addButton($this->lng->txt('paya_sell_object'), $this->ctrl->getLinkTarget($this, 'showObjectSelector'));
     if (!$_POST['show_filter'] && $_POST['updateView'] == '1') {
         $this->resetObjectFilter();
     } else {
         if ($_POST['updateView'] == 1) {
             $_SESSION['pay_objects']['updateView'] = $_POST['updateView'];
             $_SESSION['pay_objects']['show_filter'] = $_POST['show_filter'];
             $_SESSION['pay_objects']['title_type'] = $_POST['title_type'];
             $_SESSION['pay_objects']['title_value'] = $_POST['title_value'];
             $_SESSION['pay_objects']['pay_method'] = $_POST['pay_method'];
             $_SESSION['pay_objects']['vendor'] = $_POST['vendor'];
         }
     }
     $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html', 'Services/Payment');
     $this->__initPaymentObject();
     $this->lng->loadLanguageModule('search');
     $filter_form = new ilPropertyFormGUI();
     $filter_form->setFormAction($this->ctrl->getFormAction($this));
     $filter_form->setTitle($this->lng->txt('pay_filter'));
     $filter_form->setId('filter_form');
     $filter_form->setTableWidth('100 %');
     //hide_filter
     $o_hide_check = new ilCheckBoxInputGUI($this->lng->txt('show_filter'), 'show_filter');
     $o_hide_check->setValue(1);
     $o_hide_check->setChecked($_SESSION['pay_objects']['show_filter'] ? 1 : 0);
     $o_hidden = new ilHiddenInputGUI('updateView');
     $o_hidden->setValue(1);
     $o_hidden->setPostVar('updateView');
     $o_hide_check->addSubItem($o_hidden);
     //title
     $radio_group = new ilRadioGroupInputGUI($this->lng->txt('search_in_title'), 'title_type');
     $radio_option = new ilRadioOption($this->lng->txt('search_any_word'), 'or');
     $radio_group->addOption($radio_option);
     $radio_option = new ilRadioOption($this->lng->txt('search_all_words'), 'and');
     $radio_group->addOption($radio_option);
     $radio_group->setRequired(false);
     $radio_group->setValue('or');
     $radio_group->setPostVar('title_type');
     $o_title = new ilTextInputGUI();
     $o_title->setValue($_SESSION['pay_objects']['title_value']);
     $o_title->setPostVar('title_value');
     $o_title->setTitle($this->lng->txt('title'));
     $o_hide_check->addSubItem($radio_group);
     $o_hide_check->addSubItem($o_title);
     //vendor
     $o_vendor = new ilTextInputGUI();
     $o_vendor->setTitle($this->lng->txt('paya_vendor'));
     $o_vendor->setValue($_SESSION['pay_objects']['vendor']);
     $o_vendor->setPostVar('vendor');
     $o_hide_check->addSubItem($o_vendor);
     // paymethod
     $o_paymethod = new ilSelectInputGUI();
     $o_paymethod->setTitle($this->lng->txt('payment_system'));
     $o_paymethod->setOptions(ilPaymethods::getPayMethodsOptions('all'));
     $o_paymethod->setValue($_SESSION['pay_objects']['pay_method']);
     $o_paymethod->setPostVar('pay_method');
     $o_hide_check->addSubItem($o_paymethod);
     $filter_form->addCommandButton('showObjects', $this->lng->txt('pay_update_view'));
     $filter_form->addCommandButton('resetObjectFilter', $this->lng->txt('pay_reset_filter'));
     $filter_form->addItem($o_hide_check);
     if (!count($objects = ilPaymentObject::_getObjectsData($this->user_obj->getId()))) {
         ilUtil::sendInfo($this->lng->txt('paya_no_objects_assigned'));
         return true;
     }
     $this->tpl->setVariable('FORM', $filter_form->getHTML());
     $counter = 0;
     foreach ($objects as $data) {
         /** @var $tmp_obj ilObject */
         $tmp_obj = ilObjectFactory::getInstanceByRefId($data['ref_id'], false);
         if ($tmp_obj) {
             $f_result[$counter]['title'] = $tmp_obj->getTitle();
         } else {
             $f_result[$counter]['title'] = $this->lng->txt('object_not_found');
         }
         switch ($data['status']) {
             case $this->pobject->STATUS_BUYABLE:
                 $f_result[$counter]['status'] = $this->lng->txt('paya_buyable');
                 break;
             case $this->pobject->STATUS_NOT_BUYABLE:
                 $f_result[$counter]['status'] = $this->lng->txt('paya_not_buyable');
                 break;
             case $this->pobject->STATUS_EXPIRES:
                 $f_result[$counter]['status'] = $this->lng->txt('paya_expires');
                 break;
         }
         $str_paymethod = ilPayMethods::getStringByPaymethod($data['pay_method']);
         $f_result[$counter]['pay_method'] = $str_paymethod;
         if ($data['vat_id'] <= 0) {
             $vat_rate = $this->lng->txt('payment_vat_has_to_be_defined_by_administration_short');
         } else {
             try {
                 $oVAT = new ilShopVats((int) $data['vat_id']);
                 $vat_rate = ilShopUtils::_formatVAT((double) $oVAT->getRate());
             } catch (ilShopException $e) {
                 $vat_rate = $this->lng->txt('payment_vat_has_to_be_defined_by_administration_short');
             }
         }
         $f_result[$counter]['vat_rate'] = $vat_rate;
         /** @var $tmp_user ilObjUser */
         $tmp_user = ilObjectFactory::getInstanceByObjId($data['vendor_id']);
         $f_result[$counter]['vendor'] = $tmp_user->getFullname() . ' [' . $tmp_user->getLogin() . ']';
         // Get number of purchasers
         $f_result[$counter]['purchasers'] = ilPaymentBookings::_getCountBookingsByObject($data['pobject_id']);
         // edit link
         $this->ctrl->setParameter($this, 'pobject_id', $data['pobject_id']);
         $link_change = "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"" . $this->ctrl->getLinkTarget($this, "editDetails") . "\">" . $this->lng->txt("edit") . "</a></div>";
         $f_result[$counter]['options'] = $link_change;
         unset($tmp_user);
         unset($tmp_obj);
         ++$counter;
     }
     return $this->__showObjectsTable($f_result);
 }