/** * @see HTMLTemplate::getContent() */ public function getContent() { $final_pdf = ''; require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpSupplyOrderCustomer.php'; require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpSupplier.php'; require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpSupplyOrder.php'; // Retrieval of the link between supplier order AND customer order if exists $erp_supply_order_customer = ErpSupplyOrderCustomer::getSupplyOrdersCustomer((int) $this->supply_order->id); $supply_order_details = $this->supply_order->getEntriesCollection((int) $this->supply_order->id_lang); $this->roundSupplyOrderDetails($supply_order_details); $supply_order_receipt_history = array(); foreach ($supply_order_details as $supply_order_detail) { $supply_order_receipt_history[$supply_order_detail->id] = $this->getSupplyOrderReceiptHistoryCollection($supply_order_detail->id); } $this->roundSupplyOrder($this->supply_order); $tax_order_summary = $this->getTaxOrderSummary(); $currency = new Currency((int) $this->supply_order->id_currency); //-ERP information // get additional supplier information $erp_supplier = null; $erp_supplier_fax = ''; if (isset($this->supply_order->id_supplier) && (int) $this->supply_order->id_supplier > 0) { $id_erpip_supplier = ErpSupplier::getErpSupplierIdBySupplierId((int) $this->supply_order->id_supplier); if ((int) $id_erpip_supplier > 0) { $erp_supplier = new ErpSupplier((int) $id_erpip_supplier); } } if ($erp_supplier != null) { $erp_supplier_fax = $erp_supplier->fax; } //-ERP information // get additional supply order information $erp_supply_order = null; if (isset($this->supply_order->id) && (int) $this->supply_order->id > 0) { $id_erpip_supply_order = ErpSupplyOrder::getErpSupplierOrderIdBySupplierOrderId((int) $this->supply_order->id); if ((int) $id_erpip_supply_order > 0) { $erp_supply_order = new ErpSupplyOrder((int) $id_erpip_supply_order); } } // get shipping address $adresse_livraison = self::getStoreByName('Adresse livraison'); $this->smarty->assign(array('warehouse' => $this->warehouse, 'address_warehouse' => $this->address_warehouse, 'address_supplier' => $this->address_supplier, 'supply_order' => $this->supply_order, 'erp_supply_order' => $erp_supply_order, 'supply_order_details' => $supply_order_details, 'supply_order_receipt_history' => $supply_order_receipt_history, 'tax_order_summary' => $tax_order_summary, 'currency' => $currency, 'fax' => $erp_supplier_fax, 'action' => Tools::getValue('submitAction'), 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'shop_addr' => Configuration::get('PS_SHOP_ADDR1'), 'shop_addr2' => Configuration::get('PS_SHOP_ADDR2'), 'shop_code' => Configuration::get('PS_SHOP_CODE'), 'shop_city' => Configuration::get('PS_SHOP_CITY'), 'shop_country' => Configuration::get('PS_SHOP_COUNTRY'), 'adresse_livraison' => $adresse_livraison)); // if there is an supply order generated : display a PDF page by customer if (!empty($erp_supply_order_customer)) { // distribution by customer : one page per customer $final_item = array(); foreach ($erp_supply_order_customer as $item) { $final_item[$item['id_customer']][] = $item; } $pdf_customer = ''; // Create page per customer foreach ($final_item as $id_customer => $datas) { $customer = new Customer((int) $id_customer); $order_detail = array(); foreach ($datas as $data) { $order_detail_line = new OrderDetailCore((int) $data['id_order_detail']); $order_detail_line->tax_rate = Tax::getProductTaxRate($order_detail_line->product_id); $order_detail[] = $order_detail_line; } $this->smarty->assign(array('is_customer_page' => 'true')); $this->smarty->assign(array('supply_order_details' => $order_detail)); $this->smarty->assign(array('customer_name' => $customer->lastname . ' ' . $customer->firstname)); $pdf_customer .= '<div style="page-break-before:always"><div>'; $pdf_customer .= $this->smarty->fetch(_PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/pdf/erp-supply-order-customer.tpl'); } $this->smarty->assign(array('is_customer_page' => 'false')); $this->smarty->assign(array('supply_order_details' => $supply_order_details)); $final_pdf = $this->smarty->fetch(_PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/pdf/erp-supply-order.tpl') . $pdf_customer; } else { $final_pdf = $this->smarty->fetch(_PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/pdf/erp-supply-order.tpl'); } return $final_pdf; }
$erp_supplier = new ErpSupplier((int) $id_erpip_supplier); } if (!is_null($erp_supplier)) { echo Tools::jsonEncode($erp_supplier); } } else { echo Tools::jsonEncode(array('error' => $erpip->l('Error : no supplier found !'))); } break; case 'getSupplyOrderDescription': if (Tools::isSubmit('id_supplier_order')) { require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpSupplyOrder.php'; $id_supplier_order = (int) Tools::getValue('id_supplier_order'); if ($id_supplier_order > 0) { /*-ERP get association */ $id_erpip_supply_order = ErpSupplyOrder::getErpSupplierOrderIdBySupplierOrderId($id_supplier_order); if ((int) $id_erpip_supply_order > 0) { $erp_supply_order = new ErpSupplyOrder((int) $id_erpip_supply_order); if ($erp_supply_order) { echo $erp_supply_order->description; } } } } break; /* Dash product*/ /* Dash product*/ case 'getProduct': $id_product = Tools::getValue('id_product'); $id_supplier = Tools::getValue('id_supplier'); $id_currency = Tools::isSubmit('id_currency') ? Tools::getValue('id_currency') : Context::getContext()->id_currency;
/** * @see AdminController::renderView() */ public function renderView() { require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpSupplyOrderCustomer.php'; $this->show_toolbar = true; $this->toolbar_scroll = false; $this->table = 'supply_order_detail'; $this->identifier = 'id_supply_order_detail'; $this->className = 'SupplyOrderDetail'; $this->colorOnBackground = false; $this->lang = false; $this->list_simple_header = true; $this->list_no_link = true; // gets the id supplier to view $id_supply_order = (int) Tools::getValue('id_supply_order'); // gets global order information $supply_order = new SupplyOrder((int) $id_supply_order); if (Validate::isLoadedObject($supply_order)) { if (!$supply_order->is_template) { $this->displayInformation($this->l('This interface allows you to display detailed information about your order.') . '<br />'); } else { $this->displayInformation($this->l('This interface allows you to display detailed information about your order template.') . '<br />'); } $lang_id = (int) $supply_order->id_lang; // just in case.. unset($this->_select, $this->_join, $this->_where, $this->_orderBy, $this->_orderWay, $this->_group, $this->_filterHaving, $this->_filter); $this->_select = 'CONCAT("' . $this->l('Ref') . ' : ", reference, " ", "' . $this->l('Supplier') . ' : ", supplier_reference) as refs'; $this->_select .= ',CONCAT("EAN13 :", ean13," UPC : ",upc) as bare_codes '; // gets all information on the products ordered $this->_where = 'AND a.`id_supply_order` = ' . (int) $id_supply_order; // gets the list ordered by price desc, without limit $this->getList($lang_id, 'price_te', 'DESC', 0, false, false); // gets the currency used in this order $currency = new Currency($supply_order->id_currency); // gets the warehouse where products will be received $warehouse = new Warehouse($supply_order->id_warehouse); // sets toolbar title with order reference if (!$supply_order->is_template) { $this->toolbar_title = sprintf($this->l('Details on supply order #%s'), $supply_order->reference); } else { $this->toolbar_title = sprintf($this->l('Details on supply order template #%s'), $supply_order->reference); } // re-defines fields_list $this->fields_list = array('refs' => array('title' => $this->l('Refs.'), 'align' => 'center', 'width' => 120, 'orderby' => false, 'filter' => false, 'search' => false), 'bare_codes' => array('title' => $this->l('Bare codes'), 'align' => 'center', 'width' => 100, 'orderby' => false, 'filter' => false, 'search' => false), 'name' => array('title' => $this->l('Name'), 'orderby' => false, 'filter' => false, 'search' => false), 'unit_price_te' => array('title' => $this->l('Unit price (tax excl.)'), 'align' => 'right', 'width' => 80, 'orderby' => false, 'filter' => false, 'search' => false, 'type' => 'price', 'currency' => true), 'quantity_expected' => array('title' => $this->l('Quantity'), 'align' => 'right', 'width' => 80, 'orderby' => false, 'filter' => false, 'search' => false), 'price_te' => array('title' => $this->l('Price (tax excl.)'), 'align' => 'right', 'width' => 80, 'orderby' => false, 'filter' => false, 'search' => false, 'type' => 'price', 'currency' => true), 'discount_rate' => array('title' => $this->l('Discount rate'), 'align' => 'right', 'width' => 80, 'orderby' => false, 'filter' => false, 'search' => false, 'suffix' => '%'), 'discount_value_te' => array('title' => $this->l('Discount value (tax excl.)'), 'align' => 'right', 'width' => 80, 'orderby' => false, 'filter' => false, 'search' => false, 'type' => 'price', 'currency' => true), 'price_with_discount_te' => array('title' => $this->l('Price with product discount (tax excl.)'), 'align' => 'right', 'width' => 80, 'orderby' => false, 'filter' => false, 'search' => false, 'type' => 'price', 'currency' => true), 'tax_rate' => array('title' => $this->l('Tax rate'), 'align' => 'right', 'width' => 80, 'orderby' => false, 'filter' => false, 'search' => false, 'suffix' => '%'), 'tax_value' => array('title' => $this->l('Tax value'), 'align' => 'right', 'width' => 80, 'orderby' => false, 'filter' => false, 'search' => false, 'type' => 'price', 'currency' => true), 'price_ti' => array('title' => $this->l('Price (tax incl.)'), 'align' => 'right', 'width' => 80, 'orderby' => false, 'filter' => false, 'search' => false, 'type' => 'price', 'currency' => true)); //some staff before render list foreach ($this->_list as &$item) { $item['discount_rate'] = Tools::ps_round($item['discount_rate'], 4); $item['tax_rate'] = Tools::ps_round($item['tax_rate'], 4); $item['id_currency'] = $currency->id; } // unsets some buttons unset($this->toolbar_btn['export-csv-orders']); unset($this->toolbar_btn['export-csv-details']); unset($this->toolbar_btn['new']); // renders list $helper = new HelperList(); $this->setHelperDisplay($helper); $helper->actions = array(); $helper->show_toolbar = false; $helper->toolbar_btn = $this->toolbar_btn; $content = $helper->generateList($this->_list, $this->fields_list); //-ERP information //get information in erp_supply_order $erp_shipping_amount = 0; $erp_escompte = 0; $erp_date_to_invoice = null; $erp_global_discount_amount = 0; $erp_invoice_number = 0; $erp_supply_order_description = ''; $d_erp_supply_order = ErpSupplyOrder::getErpSupplierOrderIdBySupplierOrderId((int) $id_supply_order); if ((int) $d_erp_supply_order > 0) { $erp_supply_order = new ErpSupplyOrder((int) $d_erp_supply_order); $erp_shipping_amount = $erp_supply_order->shipping_amount; $erp_escompte = $erp_supply_order->escompte; $erp_date_to_invoice = $erp_supply_order->date_to_invoice; $erp_global_discount_amount = $erp_supply_order->global_discount_amount; $erp_invoice_number = $erp_supply_order->invoice_number; $erp_supply_order_description = $erp_supply_order->description; } // calculated values $total_shipping = $supply_order->total_with_discount_te + $erp_shipping_amount; $escompte_amount = $total_shipping * $erp_escompte / 100; $total_escompte = $total_shipping - $escompte_amount; $total_to_pay = $total_escompte + $supply_order->total_tax; // remove id_lang attribute for version >= 1.5.5 // id_lang parameter in displayDate() is deprecated if (version_compare(_PS_VERSION_, '1.5.5', '>=')) { $supply_order_creation_date = Tools::displayDate($supply_order->date_add, null, false); $supply_order_last_update = Tools::displayDate($supply_order->date_upd, null, false); $supply_order_expected = Tools::displayDate($supply_order->date_delivery_expected, null, false); //$supply_order_date_to_invoice = Tools::displayDate($erp_date_to_invoice, null , false); } else { $supply_order_creation_date = Tools::displayDate($supply_order->date_add, $lang_id, false); $supply_order_last_update = Tools::displayDate($supply_order->date_upd, $lang_id, false); $supply_order_expected = Tools::displayDate($supply_order->date_delivery_expected, $lang_id, false); //$supply_order_date_to_invoice = Tools::displayDate($erp_date_to_invoice, $lang_id , false); } // display these global order informations $this->tpl_view_vars = array('supply_order_detail_content' => $content, 'supply_order_warehouse' => Validate::isLoadedObject($warehouse) ? $warehouse->name : '', 'supply_order_reference' => $supply_order->reference, 'supply_order_supplier_name' => $supply_order->supplier_name, 'supply_order_creation_date' => $supply_order_creation_date, 'supply_order_last_update' => $supply_order_last_update, 'supply_order_expected' => $supply_order_expected, 'supply_order_discount_rate' => Tools::ps_round($supply_order->discount_rate, 2), 'supply_order_total_te' => Tools::displayPrice($supply_order->total_te, $currency), 'supply_order_discount_value_te' => Tools::displayPrice($supply_order->discount_value_te, $currency), 'supply_order_total_with_discount_te' => Tools::displayPrice($supply_order->total_with_discount_te, $currency), 'supply_order_total_tax' => Tools::displayPrice($supply_order->total_tax, $currency), 'supply_order_total_ti' => Tools::displayPrice($supply_order->total_ti, $currency), 'supply_order_currency' => $currency, 'is_template' => $supply_order->is_template, 'supply_order_discount_amount' => Tools::ps_round($erp_global_discount_amount, 2), 'supply_order_escompte' => Tools::ps_round($erp_escompte, 2), 'supply_order_shipping_amount' => Tools::ps_round($erp_shipping_amount, 2), 'supply_order_invoice_number' => $erp_invoice_number, 'supply_order_date_to_invoice' => $erp_date_to_invoice, 'total_shipping' => Tools::displayPrice($total_shipping, $currency), 'escompte_amount' => Tools::displayPrice($escompte_amount, $currency), 'total_escompte' => Tools::displayPrice($total_escompte, $currency), 'total_to_pay' => Tools::displayPrice($total_to_pay, $currency), 'supply_order_description' => $erp_supply_order_description, 'concerned_customer' => ErpSupplyOrderCustomer::getSupplyOrdersConcernedCustomer((int) $id_supply_order)); } return parent::renderView(); }