[-] BO : fixed bug on Invoice generation in AdminInvoices
This commit is contained in:
@@ -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();
|
||||
}
|
||||
@@ -65,7 +65,7 @@
|
||||
<div class="margin-form">
|
||||
{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])}
|
||||
<input type="checkbox"
|
||||
name="{$input.name}[]"
|
||||
id="{$id_checkbox}"
|
||||
|
||||
@@ -880,8 +880,16 @@ class OrderCore extends ObjectModel
|
||||
return $orders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 1.5.0.3
|
||||
*
|
||||
* @static
|
||||
* @param $id_order_state
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderIdsByStatus($id_order_state)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
$sql = 'SELECT id_order
|
||||
FROM '._DB_PREFIX_.'orders o
|
||||
WHERE '.(int)$id_order_state.' = (
|
||||
|
||||
@@ -429,6 +429,32 @@ class OrderInvoiceCore extends ObjectModel
|
||||
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
|
||||
* @static
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user