From c98c62f1e02477d58b1f264485cf139d8eb35f27 Mon Sep 17 00:00:00 2001 From: bMancone Date: Mon, 21 Nov 2011 18:31:44 +0000 Subject: [PATCH] // Supply Orders: the supply order form is now generated (PDF) --- admin-dev/pdf.php | 17 +- classes/pdf/HTMLTemplateSupplyOrderForm.php | 108 ++++++++++++ classes/pdf/PDF.php | 1 + .../admin/AdminSupplyOrdersController.php | 4 +- themes/prestashop/pdf/en.php | 0 themes/prestashop/pdf/supply-order.tpl | 158 ++++++++++++++++++ 6 files changed, 285 insertions(+), 3 deletions(-) create mode 100644 classes/pdf/HTMLTemplateSupplyOrderForm.php create mode 100644 themes/prestashop/pdf/en.php create mode 100644 themes/prestashop/pdf/supply-order.tpl diff --git a/admin-dev/pdf.php b/admin-dev/pdf.php index 5ed11ab79..c20a7ba32 100644 --- a/admin-dev/pdf.php +++ b/admin-dev/pdf.php @@ -39,7 +39,8 @@ $functionArray = array( 'invoices' => 'generateInvoicesPDF', 'invoices2' => 'generateInvoicesPDF2', 'slips' => 'generateOrderSlipsPDF', - 'deliveryslips' => 'generateDeliverySlipsPDF' + 'deliveryslips' => 'generateDeliverySlipsPDF', + 'id_supply_order' => 'generateSupplyOrderFormPDF' ); foreach ($functionArray as $var => $function) @@ -49,6 +50,20 @@ foreach ($functionArray as $var => $function) die; } +function generateSupplyOrderFormPDF() +{ + if (!isset($_GET['id_supply_order'])) + die (Tools::displayError('Missing supply order ID')); + + $id_supply_order = (int)$_GET['id_supply_order']; + $supply_order = new SupplyOrder($id_supply_order); + + if (!Validate::isLoadedObject($supply_order)) + die(Tools::displayError('Cannot find this supply order in the database')); + + generatePDF($supply_order, PDF::TEMPLATE_SUPPLY_ORDER_FORM); +} + function generateInvoicePDF() { if (!isset($_GET['id_order'])) diff --git a/classes/pdf/HTMLTemplateSupplyOrderForm.php b/classes/pdf/HTMLTemplateSupplyOrderForm.php new file mode 100644 index 000000000..80f617625 --- /dev/null +++ b/classes/pdf/HTMLTemplateSupplyOrderForm.php @@ -0,0 +1,108 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +/** + * @since 1.5 + */ +class HTMLTemplateSupplyOrderForm extends HTMLTemplate +{ + public $supply_order; + public $warehouse; + public $address_warehouse; + public $context; + + public function __construct(SupplyOrder $supply_order, $smarty) + { + $this->supply_order = $supply_order; + $this->smarty = $smarty; + $this->context = Context::getContext(); + $this->warehouse = new Warehouse($supply_order->id_warehouse); + $this->address_warehouse = new Address($this->warehouse->id_address); + + // header informations + $this->date = Tools::displayDate($supply_order->date_add, (int)$this->context->language->id); + $this->title = self::l('Supply order form').sprintf(' #%s', $supply_order->reference); + + // footer informations : displays the address of the warehouse + $this->address = $this->address_warehouse; + } + + /** + * Returns the template's HTML content + * @return string HTML content + */ + public function getContent() + { + $supply_order_details = $this->supply_order->getEntriesCollection($this->context->language->id); + $tax_order_summary = $this->getTaxOrderSummary(); + $currency = new Currency($this->supply_order->id_currency); + + $this->smarty->assign(array( + 'warehouse' => $this->warehouse, + 'address_warehouse' => $this->address_warehouse, + 'supply_order' => $this->supply_order, + 'supply_order_details' => $supply_order_details, + 'tax_order_summary' => $tax_order_summary, + 'currency' => $currency, + )); + return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/supply-order.tpl'); + } + + /** + * Returns the template filename when using bulk rendering + * @return string filename + */ + public function getBulkFilename() + { + return 'supply_order.pdf'; + } + + /** + * Returns the template filename + * @return string filename + */ + public function getFilename() + { + return ($this->l('SupplyOrderForm').sprintf('_%s', $this->supply_order->reference).'.pdf'); + } + + protected function getTaxOrderSummary() + { + $query = new DbQuery(); + $query->select(' + SUM(price_with_order_discount_te) as base_te, + tax_rate, + SUM(tax_value_with_order_discount) as total_tax_value + '); + $query->from('supply_order_detail'); + $query->where('id_supply_order = '.(int)$this->supply_order->id); + $query->groupBy('tax_rate'); + + $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); + return $results; + } +} diff --git a/classes/pdf/PDF.php b/classes/pdf/PDF.php index a7175ee45..f0749e7aa 100755 --- a/classes/pdf/PDF.php +++ b/classes/pdf/PDF.php @@ -39,6 +39,7 @@ class PDFCore const TEMPLATE_ORDER_RETURN = 'OrderReturn'; const TEMPLATE_ORDER_SLIP = 'OrderSlip'; const TEMPLATE_DELIVERY_SLIP = 'DeliverySlip'; + const TEMPLATE_SUPPLY_ORDER_FORM = 'SupplyOrderForm'; public function __construct($objects, $template, $smarty) { diff --git a/controllers/admin/AdminSupplyOrdersController.php b/controllers/admin/AdminSupplyOrdersController.php index 9cb7e5cf3..d366c0f2d 100644 --- a/controllers/admin/AdminSupplyOrdersController.php +++ b/controllers/admin/AdminSupplyOrdersController.php @@ -1765,8 +1765,8 @@ class AdminSupplyOrdersControllerCore extends AdminController return; $content = ''; - if ($supply_order_state->editable == false) // @TODO Decide what states are allowed - $content .= 'invoice'; + if ($supply_order_state->editable == false) + $content .= 'invoice'; else $content .= '-'; $content .= ''; diff --git a/themes/prestashop/pdf/en.php b/themes/prestashop/pdf/en.php new file mode 100644 index 000000000..e69de29bb diff --git a/themes/prestashop/pdf/supply-order.tpl b/themes/prestashop/pdf/supply-order.tpl new file mode 100644 index 000000000..9df0e3957 --- /dev/null +++ b/themes/prestashop/pdf/supply-order.tpl @@ -0,0 +1,158 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Open Software License (OSL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/osl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +
+ + +
+ + + + + + + + {* if the address has two parts *} + {if !empty($address_warehouse->address2)} + + + + {/if} + + + +
{$shop_name}
{$address_warehouse->address1}
{$address_warehouse->address2}
{$address_warehouse->postcode} {$address_warehouse->city}
+
+ + + +
+ + + + +
{$supply_order->supplier_name}
+
+ + + + +
 
+ + {l s='Products to order:'} + +
+ + + + + + + + + + + + + {* for each product ordered *} + {foreach $supply_order_details as $supply_order_detail} + + + + + + + + + + + + {/foreach} +
{l s='Reference'}{l s='Designation'}{l s='Qty'}{l s='Unit Price TE'}{l s='Total TE BD'}{l s='Discount Rate'}{l s='Total TE AD'}{l s='Tax rate'}{l s='Total TI'}
{$supply_order_detail->supplier_reference}{$supply_order_detail->name}{$supply_order_detail->quantity_expected}{$supply_order_detail->unit_price_te}{$supply_order_detail->price_te}{$supply_order_detail->discount_rate}{$supply_order_detail->price_with_discount_te}{$supply_order_detail->tax_rate}{$supply_order_detail->price_ti}
+
+ + + + +
 
+ + {l s='Taxes:'} + +
+ + + + + + + {foreach $tax_order_summary as $entry} + + + + + + {/foreach} +
{l s='Base TE'}{l s='Tax Rate'}{l s='Tax Value'}
{$entry['base_te']}{$entry['tax_rate']}{$entry['total_tax_value']}
+
+ + + + +
 
+ + {l s='Summary'} + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
{l s='Total TE'}{$supply_order->total_te}
{l s='Order Discount'}{$supply_order->discount_value_te}
{l s='Total AD TE'}{$supply_order->total_with_discount_te}
{l s='Tax value'}{$supply_order->total_tax}
{l s='Total TI'}{$supply_order->total_ti}
{l s='TOTAL TO PAY'}{$currency->prefix} {$supply_order->total_ti} {$currency->suffix}
+
+ + + +
\ No newline at end of file