[-] BO : fixed bug on Invoice generation in AdminInvoices

This commit is contained in:
aFolletete
2012-01-02 17:30:11 +00:00
parent fca37421ac
commit 8923947406
6 changed files with 73 additions and 49 deletions
+18 -28
View File
@@ -146,34 +146,25 @@ function generateDeliverySlipPDFByIdOrderInvoice($id_order_invoice)
function generateInvoicesPDF() 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)) if (!sizeof($order_invoice_collection))
die (Tools::displayError('No invoices found')); die(Tools::displayError('No invoices found'));
generateOrderInvoicesPDF($id_orders_list); generatePDF($order_invoice_collection, PDF::TEMPLATE_INVOICE);
} }
function generateInvoicesPDF2() function generateInvoicesPDF2()
{ {
$id_orders_list = array(); $order_invoice_collection = array();
foreach (explode('-', Tools::getValue('id_order_state')) as $id_order_state) foreach (explode('-', Tools::getValue('id_order_state')) as $id_order_state)
if (is_array($id_orders = Order::getOrderIdsByStatus((int)$id_order_state))) if (is_array($order_invoices = OrderInvoice::getByStatus($id_order_state)))
$id_orders_list = array_merge($id_orders_list, $id_orders); $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) generatePDF($order_invoice_collection, PDF::TEMPLATE_INVOICE);
{
$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);
} }
function generateOrderSlipsPDF() function generateOrderSlipsPDF()
@@ -182,24 +173,23 @@ function generateOrderSlipsPDF()
if (!count($id_order_slips_list)) if (!count($id_order_slips_list))
die (Tools::displayError('No order slips found')); die (Tools::displayError('No order slips found'));
$order_slips = array(); $order_slips = array();
foreach ($id_order_slips_list as $id_order_slips) foreach ($id_order_slips_list as $id_order_slips)
$order_slips[] = new OrderSlip((int)$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() function generateDeliverySlipsPDF()
{ {
$slips = unserialize(urldecode($_GET['deliveryslips'])); $slips = unserialize(urldecode($_GET['deliveryslips']));
if (is_array($slips)) if (is_array($slips))
generatePDF($slips, PDF::TEMPLATE_DELIVERY_SLIP); generatePDF($slips, PDF::TEMPLATE_DELIVERY_SLIP);
} }
function generatePDF($object, $template) function generatePDF($object, $template)
{ {
global $smarty; global $smarty;
$pdf = new PDF($object, $template, $smarty); $pdf = new PDF($object, $template, $smarty);
$pdf->render(); $pdf->render();
} }
@@ -65,7 +65,7 @@
<div class="margin-form"> <div class="margin-form">
{if $input.type == 'checkboxStatuses'} {if $input.type == 'checkboxStatuses'}
{foreach $input.values.query as $value} {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])}
<input type="checkbox" <input type="checkbox"
name="{$input.name}[]" name="{$input.name}[]"
id="{$id_checkbox}" id="{$id_checkbox}"
+8
View File
@@ -880,8 +880,16 @@ class OrderCore extends ObjectModel
return $orders; return $orders;
} }
/**
* @deprecated 1.5.0.3
*
* @static
* @param $id_order_state
* @return array
*/
public static function getOrderIdsByStatus($id_order_state) public static function getOrderIdsByStatus($id_order_state)
{ {
Tools::displayAsDeprecated();
$sql = 'SELECT id_order $sql = 'SELECT id_order
FROM '._DB_PREFIX_.'orders o FROM '._DB_PREFIX_.'orders o
WHERE '.(int)$id_order_state.' = ( WHERE '.(int)$id_order_state.' = (
+26
View File
@@ -429,6 +429,32 @@ class OrderInvoiceCore extends ObjectModel
return ObjectModel::hydrateCollection('OrderInvoice', $order_invoice_list); return ObjectModel::hydrateCollection('OrderInvoice', $order_invoice_list);
} }
/**
* @since 1.5.0.3
* @static
* @param $id_order_state
* @return array collection of OrderInvoice
*/
public static function getByStatus($id_order_state)
{
$order_invoice_list = Db::getInstance(_PS_USE_SQL_SLAVE_)->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 * @since 1.5
* @static * @static
+18 -18
View File
@@ -32,14 +32,14 @@ class PDFCore
{ {
public $filename; public $filename;
public $pdf_renderer; public $pdf_renderer;
public $objects; public $objects;
public $template; public $template;
const TEMPLATE_INVOICE = 'Invoice'; const TEMPLATE_INVOICE = 'Invoice';
const TEMPLATE_ORDER_RETURN = 'OrderReturn'; const TEMPLATE_ORDER_RETURN = 'OrderReturn';
const TEMPLATE_ORDER_SLIP = 'OrderSlip'; const TEMPLATE_ORDER_SLIP = 'OrderSlip';
const TEMPLATE_DELIVERY_SLIP = 'DeliverySlip'; const TEMPLATE_DELIVERY_SLIP = 'DeliverySlip';
const TEMPLATE_SUPPLY_ORDER_FORM = 'SupplyOrderForm'; const TEMPLATE_SUPPLY_ORDER_FORM = 'SupplyOrderForm';
public function __construct($objects, $template, $smarty) public function __construct($objects, $template, $smarty)
{ {
@@ -48,26 +48,26 @@ class PDFCore
$this->smarty = $smarty; $this->smarty = $smarty;
$this->objects = $objects; $this->objects = $objects;
if (!($objects instanceof Iterator)) if (!($objects instanceof Iterator) && !is_array($objects))
$this->objects = array($objects); $this->objects = array($objects);
} }
public function render($display = true) public function render($display = true)
{ {
$render = false; $render = false;
$this->pdf_renderer->setFontForLang('fr'); $this->pdf_renderer->setFontForLang('fr');
foreach ($this->objects as $object) foreach ($this->objects as $object)
{ {
$template = $this->getTemplateObject($object); $template = $this->getTemplateObject($object);
if (!$template) if (!$template)
continue; continue;
if (empty($this->filename)) if (empty($this->filename))
{ {
$this->filename = $template->getFilename(); $this->filename = $template->getFilename();
if (count($this->objects) > 1) if (count($this->objects) > 1)
$this->filename = $template->getBulkFilename(); $this->filename = $template->getBulkFilename();
} }
$template->assignHookData($object); $template->assignHookData($object);
@@ -150,7 +150,7 @@ class AdminInvoicesControllerCore extends AdminController
); );
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT COUNT(*) as nbOrders, ( SELECT COUNT(o.id_order) as nbOrders, (
SELECT oh.id_order_state SELECT oh.id_order_state
FROM '._DB_PREFIX_.'order_history oh FROM '._DB_PREFIX_.'order_history oh
WHERE oh.id_order = oi.id_order WHERE oh.id_order = oi.id_order