Skip to content

Commit

Permalink
// OrderInvoice PDF compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
fBrignoli committed Dec 1, 2011
1 parent 6924c18 commit 4ab6d4f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 13 deletions.
23 changes: 14 additions & 9 deletions admin-dev/pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,12 @@ function generateDeliverySlipPDF()

function generateInvoicesPDF()
{
$id_orders_list = Order::getOrdersIdInvoiceByDate($_GET['date_from'], $_GET['date_to'], NULL, 'invoice');
$id_orders_list = OrderInvoice::getByDateInterval($_GET['date_from'], $_GET['date_to'], NULL, 'invoice');

if (!is_array($id_orders_list))
die (Tools::displayError('No invoices found'));

$orders = array();
foreach ($id_orders_list as $id_order)
$orders[] = new Order((int)$id_order);

generatePDF($orders, PDF::TEMPLATE_INVOICE);
generateOrderInvoicesPDF($id_orders_list);
}

function generateInvoicesPDF2()
Expand All @@ -134,11 +131,19 @@ function generateInvoicesPDF2()
if (is_array($id_orders = Order::getOrderIdsByStatus((int)$id_order_state)))
$id_orders_list = array_merge($id_orders_list, $id_orders);

$orders = array();
generateOrderInvoicesPDF($id_orders_list);
}

function generateOrderInvoicesPDF($id_orders_list)
{
$orders_invoices = array();
foreach ($id_orders_list as $id_order)
$orders[] = new Order((int)$id_order);
{
$order = new Order((int)$id_order);
$orders_invoices = array_merge($orders_invoices, $order->getInvoicesCollection());
}

generatePDF($orders, PDF::TEMPLATE_INVOICE);
generatePDF($orders_invoices, PDF::TEMPLATE_INVOICE);
}

function generateOrderSlipsPDF()
Expand Down
12 changes: 12 additions & 0 deletions classes/order/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,20 @@ static public function getOrdersWithInformations($limit = NULL, Context $context
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
}

/**
* @deprecated since 1.5.0.2
*
* @static
* @param $date_from
* @param $date_to
* @param $id_customer
* @param $type
*
* @return array
*/
public static function getOrdersIdInvoiceByDate($date_from, $date_to, $id_customer = NULL, $type = NULL)
{
Tools::displayAsDeprecated();
$sql = 'SELECT `id_order`
FROM `'._DB_PREFIX_.'orders`
WHERE DATE_ADD(invoice_date, INTERVAL -1 DAY) <= \''.pSQL($date_to).'\' AND invoice_date >= \''.pSQL($date_from).'\'
Expand Down
22 changes: 22 additions & 0 deletions classes/order/OrderInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,26 @@ public function getEcoTaxTaxesBreakdown()
AND `id_order_invoice` = '.(int)$this->id
);
}

/**
* Returns all the order invoice that match the date interval
*
* @since 1.5.0.2
* @static
* @param $date_from
* @param $date_to
* @return array collection of OrderInvoice
*/
public static function getByDateInterval($date_from, $date_to)
{
$order_invoice_list = Db::getInstance()->ExecuteS('SELECT oi.*
FROM `'._DB_PREFIX_.'order_invoice` oi
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = oi.`id_order`)
WHERE DATE_ADD(oi.date_add, INTERVAL -1 DAY) <= \''.pSQL($date_to).'\'
AND oi.date_add >= \''.pSQL($date_from).'\'
'.Context::getContext()->shop->addSqlRestriction().
' ORDER BY oi.date_add ASC');

return ObjectModel::hydrateCollection('OrderInvoice', $order_invoice_list);
}
}
14 changes: 10 additions & 4 deletions controllers/admin/AdminInvoicesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ public function initFormByStatus()
SELECT COUNT(*) as nbOrders, (
SELECT oh.id_order_state
FROM '._DB_PREFIX_.'order_history oh
WHERE oh.id_order = o.id_order
WHERE oh.id_order = oi.id_order
ORDER BY oh.date_add DESC, oh.id_order_history DESC
LIMIT 1
) id_order_state
FROM '._DB_PREFIX_.'orders o
FROM '._DB_PREFIX_.'order_invoice oi
LEFT JOIN '._DB_PREFIX_.'orders o ON (oi.id_order = o.id_order)
WHERE o.id_shop IN('.implode(', ', $this->context->shop->getListOfID()).')
GROUP BY id_order_state
');
Expand Down Expand Up @@ -204,13 +205,17 @@ public function postProcess()
{
if (!Validate::isDate(Tools::getValue('date_from')))
$this->_errors[] = $this->l('Invalid from date');

if (!Validate::isDate(Tools::getValue('date_to')))
$this->_errors[] = $this->l('Invalid end date');

if (!count($this->_errors))
{
$orders = Order::getOrdersIdInvoiceByDate(Tools::getValue('date_from'), Tools::getValue('date_to'), null, 'invoice');
if (count($orders))
$order_invoice_list = OrderInvoice::getByDateInterval(Tools::getValue('date_from'), Tools::getValue('date_to'));

if (count($order_invoice_list))
Tools::redirectAdmin('pdf.php?invoices&date_from='.urlencode(Tools::getValue('date_from')).'&date_to='.urlencode(Tools::getValue('date_to')).'&token='.$this->token);

$this->_errors[] = $this->l('No invoice found for this period');
}
}
Expand All @@ -223,6 +228,7 @@ public function postProcess()
foreach ($status_array as $id_order_state)
if (count($orders = Order::getOrderIdsByStatus((int)$id_order_state)))
Tools::redirectAdmin('pdf.php?invoices2&id_order_state='.implode('-', $status_array).'&token='.$this->token);

$this->_errors[] = $this->l('No invoice found for this status');
}
}
Expand Down

0 comments on commit 4ab6d4f

Please sign in to comment.