// add delivery slip
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11693 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+49
-14
@@ -1117,16 +1117,28 @@ class OrderCore extends ObjectModel
|
||||
|
||||
public function setDelivery()
|
||||
{
|
||||
// Set delivery number
|
||||
$number = (int)(Configuration::get('PS_DELIVERY_NUMBER'));
|
||||
if (!(int)($number))
|
||||
die(Tools::displayError('Invalid delivery number'));
|
||||
$this->delivery_number = $number;
|
||||
Configuration::updateValue('PS_DELIVERY_NUMBER', $number + 1);
|
||||
// Get all invoice
|
||||
$order_invoice_collection = $this->getInvoicesCollection();
|
||||
foreach($order_invoice_collection as $order_invoice)
|
||||
{
|
||||
$number = (int)Configuration::get('PS_DELIVERY_NUMBER');
|
||||
if (!$number)
|
||||
throw new PrestashopException('Invalid delivery number');
|
||||
|
||||
// Set delivery number on invoice
|
||||
$order_invoice->delivery_number = $number;
|
||||
$order_invoice->delivery_date = date('Y-m-d H:i:s');
|
||||
// Update Order Invoice
|
||||
$order_invoice->update();
|
||||
|
||||
// Keep for backward compatibility
|
||||
$this->delivery_number = $number;
|
||||
Configuration::updateValue('PS_DELIVERY_NUMBER', $number + 1);
|
||||
}
|
||||
|
||||
// Keep it for backward compatibility, to remove on 1.6 version
|
||||
// Set delivery date
|
||||
$this->delivery_date = date('Y-m-d H:i:s');
|
||||
|
||||
// Update object
|
||||
$this->update();
|
||||
}
|
||||
@@ -1156,7 +1168,7 @@ class OrderCore extends ObjectModel
|
||||
$sql = 'SELECT id_order
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
WHERE `delivery_number` = '.(int)($id_delivery).'
|
||||
'.Context::getContext()->shop->addSqlRestriction();
|
||||
'.Context::getContext()->shop->addSqlRestriction();
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||
return new Order((int)($res['id_order']));
|
||||
}
|
||||
@@ -1395,14 +1407,24 @@ class OrderCore extends ObjectModel
|
||||
public function getDocuments()
|
||||
{
|
||||
$invoices = $this->getInvoicesCollection()->getResults();
|
||||
$delivery_slips = $this->getDeliverySlipsCollection()->getResults();
|
||||
// @TODO review
|
||||
foreach($delivery_slips as $delivery)
|
||||
{
|
||||
$delivery->is_delivery = true;
|
||||
$delivery->date_add = $delivery->delivery_date;
|
||||
}
|
||||
$order_slips = $this->getOrderSlipsCollection()->getResults();
|
||||
$documents = array_merge($invoices, $order_slips);
|
||||
|
||||
// @TODO review
|
||||
function sortDocuments($a, $b)
|
||||
{
|
||||
if ($a->date_add == $b->date_add)
|
||||
return 0;
|
||||
return ($a->date_add < $b->date_add) ? -1 : 1;
|
||||
if ($a->date_add == $b->date_add)
|
||||
return 0;
|
||||
return ($a->date_add < $b->date_add) ? -1 : 1;
|
||||
}
|
||||
|
||||
$documents = array_merge($invoices, $order_slips, $delivery_slips);
|
||||
usort($documents, "sortDocuments");
|
||||
|
||||
return $documents;
|
||||
@@ -1436,7 +1458,7 @@ class OrderCore extends ObjectModel
|
||||
/**
|
||||
*
|
||||
* Get all order_slips for the current order
|
||||
* @since 1.5.0.1
|
||||
* @since 1.5.0.2
|
||||
* @return Collection of Order slip
|
||||
*/
|
||||
public function getOrderSlipsCollection()
|
||||
@@ -1446,7 +1468,6 @@ class OrderCore extends ObjectModel
|
||||
return $order_slips;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Get all invoices for the current order
|
||||
@@ -1460,6 +1481,20 @@ class OrderCore extends ObjectModel
|
||||
return $order_invoices;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get all delivery slips for the current order
|
||||
* @since 1.5.0.2
|
||||
* @return Collection of Order invoice
|
||||
*/
|
||||
public function getDeliverySlipsCollection()
|
||||
{
|
||||
$order_invoices = new Collection('OrderInvoice');
|
||||
$order_invoices->where('id_order', '=', $this->id);
|
||||
$order_invoices->where('delivery_number', '!=', '0');
|
||||
return $order_invoices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all not paid invoices for the current order
|
||||
* @since 1.5.0.2
|
||||
|
||||
@@ -33,6 +33,12 @@ class OrderInvoiceCore extends ObjectModel
|
||||
/** @var integer */
|
||||
public $number;
|
||||
|
||||
/** @var integer */
|
||||
public $delivery_number;
|
||||
|
||||
/** @var integer */
|
||||
public $delivery_date;
|
||||
|
||||
/** @var float */
|
||||
public $total_discount_tax_excl;
|
||||
|
||||
@@ -81,6 +87,8 @@ class OrderInvoiceCore extends ObjectModel
|
||||
'fields' => array(
|
||||
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'number' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'delivery_number' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'delivery_date' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'total_discount_tax_excl' =>array('type' => self::TYPE_FLOAT),
|
||||
'total_discount_tax_incl' =>array('type' => self::TYPE_FLOAT),
|
||||
'total_paid_tax_excl' => array('type' => self::TYPE_FLOAT),
|
||||
|
||||
@@ -32,17 +32,18 @@ class HTMLTemplateDeliverySlipCore extends HTMLTemplate
|
||||
{
|
||||
public $order;
|
||||
|
||||
public function __construct(Order $order, $smarty)
|
||||
public function __construct(OrderInvoice $order_invoice, $smarty)
|
||||
{
|
||||
$this->order = $order;
|
||||
$this->smarty = $smarty;
|
||||
$this->order_invoice = $order_invoice;
|
||||
$this->order = new Order($this->order_invoice->id_order);
|
||||
$this->smarty = $smarty;
|
||||
|
||||
// header informations
|
||||
$this->date = Tools::displayDate($order->invoice_date, (int)$order->id_lang);
|
||||
$this->title = 'Invoice '.Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $order->invoice_number);
|
||||
$this->date = Tools::displayDate($this->order->invoice_date, (int)$this->order->id_lang);
|
||||
$this->title = self::l('Delivery').' #'.Configuration::get('PS_DELIVERY_PREFIX', Context::getContext()->language->id).sprintf('%06d', $this->order_invoice->delivery_number);
|
||||
|
||||
// footer informations
|
||||
$shop = new Shop((int)$order->id_shop);
|
||||
$shop = new Shop((int)$this->order->id_shop);
|
||||
$this->address = $shop->getAddress();
|
||||
}
|
||||
|
||||
@@ -68,9 +69,10 @@ class HTMLTemplateDeliverySlipCore extends HTMLTemplate
|
||||
|
||||
$this->smarty->assign(array(
|
||||
'order' => $this->order,
|
||||
'order_details' => $this->order->getProducts(),
|
||||
'order_details' => $this->order_invoice->getProducts(),
|
||||
'delivery_address' => $formatted_delivery_address,
|
||||
'invoice_address' => $formatted_invoice_address,
|
||||
'order_invoice' => $this->order_invoice
|
||||
));
|
||||
|
||||
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/delivery-slip.tpl');
|
||||
|
||||
@@ -42,7 +42,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
||||
|
||||
// header informations
|
||||
$this->date = Tools::displayDate($order_invoice->date_add, (int)$this->order->id_lang);
|
||||
$this->title = self::l('Invoice ').Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $order_invoice->number);
|
||||
$this->title = self::l('Invoice ').' #'.Configuration::get('PS_INVOICE_PREFIX', Context::getContext()->language->id).sprintf('%06d', $order_invoice->number);
|
||||
|
||||
// footer informations
|
||||
$shop = new Shop((int)$this->order->id_shop);
|
||||
|
||||
Reference in New Issue
Block a user