/** * @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; }