diff --git a/admin-dev/pdf.php b/admin-dev/pdf.php index 1ae93b28f..699818792 100644 --- a/admin-dev/pdf.php +++ b/admin-dev/pdf.php @@ -146,34 +146,25 @@ function generateDeliverySlipPDFByIdOrderInvoice($id_order_invoice) function generateInvoicesPDF() { - $id_orders_list = OrderInvoice::getByDateInterval($_GET['date_from'], $_GET['date_to'], NULL, 'invoice'); + $order_invoice_collection = OrderInvoice::getByDateInterval($_GET['date_from'], $_GET['date_to'], NULL, 'invoice'); - if (!is_array($id_orders_list)) - die (Tools::displayError('No invoices found')); + if (!sizeof($order_invoice_collection)) + die(Tools::displayError('No invoices found')); - generateOrderInvoicesPDF($id_orders_list); + generatePDF($order_invoice_collection, PDF::TEMPLATE_INVOICE); } function generateInvoicesPDF2() { - $id_orders_list = array(); + $order_invoice_collection = array(); foreach (explode('-', Tools::getValue('id_order_state')) as $id_order_state) - if (is_array($id_orders = Order::getOrderIdsByStatus((int)$id_order_state))) - $id_orders_list = array_merge($id_orders_list, $id_orders); + if (is_array($order_invoices = OrderInvoice::getByStatus($id_order_state))) + $order_invoice_collection = array_merge($order_invoices, $order_invoice_collection); - generateOrderInvoicesPDF($id_orders_list); -} + if (!sizeof($order_invoice_collection)) + die(Tools::displayError('No invoices found')); -function generateOrderInvoicesPDF($id_orders_list) -{ - $orders_invoices = array(); - foreach ($id_orders_list as $id_order) - { - $order = new Order((int)$id_order); - $orders_invoices = array_merge($orders_invoices, $order->getInvoicesCollection()); - } - - generatePDF($orders_invoices, PDF::TEMPLATE_INVOICE); + generatePDF($order_invoice_collection, PDF::TEMPLATE_INVOICE); } function generateOrderSlipsPDF() @@ -182,24 +173,23 @@ function generateOrderSlipsPDF() if (!count($id_order_slips_list)) die (Tools::displayError('No order slips found')); - $order_slips = array(); - foreach ($id_order_slips_list as $id_order_slips) - $order_slips[] = new OrderSlip((int)$id_order_slips); + $order_slips = array(); + foreach ($id_order_slips_list as $id_order_slips) + $order_slips[] = new OrderSlip((int)$id_order_slips); - generatePDF($order_slips, PDF::TEMPLATE_ORDER_SLIP); + generatePDF($order_slips, PDF::TEMPLATE_ORDER_SLIP); } function generateDeliverySlipsPDF() { $slips = unserialize(urldecode($_GET['deliveryslips'])); if (is_array($slips)) - generatePDF($slips, PDF::TEMPLATE_DELIVERY_SLIP); + generatePDF($slips, PDF::TEMPLATE_DELIVERY_SLIP); } - function generatePDF($object, $template) { - global $smarty; - $pdf = new PDF($object, $template, $smarty); - $pdf->render(); + global $smarty; + $pdf = new PDF($object, $template, $smarty); + $pdf->render(); } \ No newline at end of file diff --git a/admin-dev/themes/default/template/invoices/form.tpl b/admin-dev/themes/default/template/invoices/form.tpl index e50da7b13..1b296009d 100644 --- a/admin-dev/themes/default/template/invoices/form.tpl +++ b/admin-dev/themes/default/template/invoices/form.tpl @@ -65,7 +65,7 @@
{if $input.type == 'checkboxStatuses'} {foreach $input.values.query as $value} - {assign var=id_checkbox value=$input.name|cat:'_'|cat:$value[$input.values.id]|intval} + {assign var=id_checkbox value=$input.name|cat:'_'|cat:intval($value[$input.values.id])} executeS(' + SELECT oi.* + FROM `'._DB_PREFIX_.'order_invoice` oi + LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = oi.`id_order`) + WHERE '.(int)$id_order_state.' = ( + SELECT id_order_state + FROM '._DB_PREFIX_.'order_history oh + WHERE oh.id_order = o.id_order + ORDER BY date_add DESC, id_order_history DESC + LIMIT 1 + ) + '.Context::getContext()->shop->addSqlRestriction(false, 'o').' + ORDER BY oi.`date_add` ASC + '); + + return ObjectModel::hydrateCollection('OrderInvoice', $order_invoice_list); + } + /** * @since 1.5 * @static diff --git a/classes/pdf/PDF.php b/classes/pdf/PDF.php index 5a98695af..eb5b4d6fb 100755 --- a/classes/pdf/PDF.php +++ b/classes/pdf/PDF.php @@ -32,14 +32,14 @@ class PDFCore { public $filename; public $pdf_renderer; - public $objects; - public $template; + public $objects; + public $template; - const TEMPLATE_INVOICE = 'Invoice'; - const TEMPLATE_ORDER_RETURN = 'OrderReturn'; - const TEMPLATE_ORDER_SLIP = 'OrderSlip'; - const TEMPLATE_DELIVERY_SLIP = 'DeliverySlip'; - const TEMPLATE_SUPPLY_ORDER_FORM = 'SupplyOrderForm'; + const TEMPLATE_INVOICE = 'Invoice'; + 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) { @@ -48,26 +48,26 @@ class PDFCore $this->smarty = $smarty; $this->objects = $objects; - if (!($objects instanceof Iterator)) + if (!($objects instanceof Iterator) && !is_array($objects)) $this->objects = array($objects); } public function render($display = true) { - $render = false; + $render = false; $this->pdf_renderer->setFontForLang('fr'); foreach ($this->objects as $object) { - $template = $this->getTemplateObject($object); - if (!$template) - continue; + $template = $this->getTemplateObject($object); + if (!$template) + continue; - if (empty($this->filename)) - { - $this->filename = $template->getFilename(); - if (count($this->objects) > 1) - $this->filename = $template->getBulkFilename(); - } + if (empty($this->filename)) + { + $this->filename = $template->getFilename(); + if (count($this->objects) > 1) + $this->filename = $template->getBulkFilename(); + } $template->assignHookData($object); diff --git a/controllers/admin/AdminInvoicesController.php b/controllers/admin/AdminInvoicesController.php index 965909377..85ac6af68 100644 --- a/controllers/admin/AdminInvoicesController.php +++ b/controllers/admin/AdminInvoicesController.php @@ -49,7 +49,7 @@ class AdminInvoicesControllerCore extends AdminController ), 'PS_INVOICE_START_NUMBER' => array( 'title' => $this->l('Invoice number:'), - 'desc' => $this->l('The next invoice will begin with this number, and then increase with each additional invoice. + 'desc' => $this->l('The next invoice will begin with this number, and then increase with each additional invoice. Set to 0 if you want to keep the current number (#').(Order::getLastInvoiceNumber() + 1).').', 'size' => 6, 'type' => 'text', @@ -150,7 +150,7 @@ class AdminInvoicesControllerCore extends AdminController ); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' - SELECT COUNT(*) as nbOrders, ( + SELECT COUNT(o.id_order) as nbOrders, ( SELECT oh.id_order_state FROM '._DB_PREFIX_.'order_history oh WHERE oh.id_order = oi.id_order