public function renderView() { $supplier = new SupplierCore((int) Tools::getValue('id_supplier')); $products = $supplier->getProductsLite($this->context->language->id); $total_product = count($products); $comb_array = array(); for ($i = 0; $i < $total_product; $i++) { $products[$i] = new Product($products[$i]['id_product'], false, $this->context->language->id); $products[$i]->loadStockData(); // Build attributes combinations $combinations = $products[$i]->getAttributeCombinations($this->context->language->id); foreach ($combinations as $combination) { $comb_infos = Supplier::getProductInformationsBySupplier($this->object->id, $products[$i]->id, $combination['id_product_attribute']); $comb_array[$combination['id_product_attribute']]['product_supplier_reference'] = $comb_infos['product_supplier_reference']; $comb_array[$combination['id_product_attribute']]['product_supplier_price_te'] = Tools::displayPrice($comb_infos['product_supplier_price_te'], new Currency($comb_infos['id_currency'])); $comb_array[$combination['id_product_attribute']]['reference'] = $combination['reference']; $comb_array[$combination['id_product_attribute']]['ean13'] = $combination['ean13']; $comb_array[$combination['id_product_attribute']]['upc'] = $combination['upc']; $comb_array[$combination['id_product_attribute']]['quantity'] = $combination['quantity']; $comb_array[$combination['id_product_attribute']]['attributes'][] = array($combination['group_name'], $combination['attribute_name'], $combination['id_attribute']); } if (isset($comb_array)) { foreach ($comb_array as $key => $product_attribute) { $list = ''; foreach ($product_attribute['attributes'] as $attribute) { $list .= $attribute[0] . ' - ' . $attribute[1] . ', '; } $comb_array[$key]['attributes'] = rtrim($list, ', '); } isset($comb_array) ? $products[$i]->combination = $comb_array : ''; unset($comb_array); } else { $product_infos = Supplier::getProductInformationsBySupplier($this->object->id, $products[$i]->id, 0); $products[$i]->product_supplier_reference = $product_infos['product_supplier_reference']; $products[$i]->product_supplier_price_te = Tools::displayPrice($product_infos['product_supplier_price_te'], new Currency($product_infos['id_currency'])); } } $this->tpl_view_vars = array('supplier' => $this->object, 'products' => $products, 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'shopContext' => Shop::getContext()); return parent::renderView(); }
/** * @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(); }