diff --git a/admin-dev/themes/template/orders/view.tpl b/admin-dev/themes/template/orders/view.tpl
index 7bdbb7c6b..5cb6d7afc 100755
--- a/admin-dev/themes/template/orders/view.tpl
+++ b/admin-dev/themes/template/orders/view.tpl
@@ -279,6 +279,7 @@
{l s='Payment method'} |
{l s='Transaction ID'} |
{l s='Amount'} |
+ {l s='Invoice'} |
|
@@ -289,6 +290,13 @@
{$payment->payment_method} |
{$payment->transaction_id} |
{displayPrice price=$payment->amount currency=$payment->id_currency} |
+
+ {if $payment->id_order_invoice}
+ #{Configuration::get('PS_INVOICE_PREFIX', $current_id_lang)}{'%06d'|sprintf:OrderInvoice::retrieveOneById($payment->id_order_invoice)->number}
+ {else}
+ {l s='No invoice'}
+ {/if}
+ |
|
{/foreach}
@@ -313,6 +321,17 @@
{/foreach}
+
+ {if sizeof($invoices_collection)}
+
+ {else}
+ {l s='No invoice available'}
+ {/if}
+ |
|
diff --git a/classes/order/Order.php b/classes/order/Order.php
index 94cfcc934..11153fdec 100644
--- a/classes/order/Order.php
+++ b/classes/order/Order.php
@@ -1065,6 +1065,12 @@ class OrderCore extends ObjectModel
SET `id_order_invoice` = '.(int)$order_invoice->id.'
WHERE `id_order` = '.(int)$order_invoice->id_order);
+ // Update order payment
+ Db::getInstance()->execute('
+ UPDATE `'._DB_PREFIX_.'order_payment`
+ SET `id_order_invoice` = '.(int)$order_invoice->id.'
+ WHERE `id_order` = '.(int)$order_invoice->id_order);
+
$this->invoice_date = $order_invoice->date_add;
$this->invoice_number = $order_invoice->number;
$this->update();
@@ -1313,12 +1319,14 @@ class OrderCore extends ObjectModel
* @param string $payment_transaction_id
* @param Currency $currency
* @param string $date
+ * @param OrderInvoice $order_invoice
* @return bool
*/
- public function addOrderPayment($amount_paid, $payment_method = null, $payment_transaction_id = null, $currency = null, $date = null)
+ public function addOrderPayment($amount_paid, $payment_method = null, $payment_transaction_id = null, $currency = null, $date = null, $order_invoice = null)
{
$order_payment = new OrderPayment();
$order_payment->id_order = $this->id;
+ $order_payment->id_order_invoice = (!is_null($order_invoice) ? $order_invoice->id : null);
$order_payment->id_currency = ($currency ? $currency->id : $this->id_currency);
// we kept the currency rate for historization reasons
$order_payment->conversion_rate = ($currency ? $currency->conversion_rate : 1);
@@ -1567,10 +1575,10 @@ class OrderCore extends ObjectModel
return true;
return false;
}
-
+
/**
* Get warehouse associated to the order
- *
+ *
* return array List of warehouse
*/
public function getWarehouseList()
@@ -1582,11 +1590,11 @@ class OrderCore extends ObjectModel
GROUP BY id_warehouse');
if (!$results)
return array();
-
+
$warehouse_list = array();
foreach ($results as $row)
$warehouse_list[] = $row['id_warehouse'];
-
+
return $warehouse_list;
}
}
diff --git a/classes/order/OrderInvoice.php b/classes/order/OrderInvoice.php
index 7358ee6ff..074cd3404 100644
--- a/classes/order/OrderInvoice.php
+++ b/classes/order/OrderInvoice.php
@@ -381,54 +381,68 @@ class OrderInvoiceCore extends ObjectModel
);
}
- /**
- * Returns all the order invoice that match the date interval
- *
- * @since 1.5
- * @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');
+ /**
+ * Returns all the order invoice that match the date interval
+ *
+ * @since 1.5
+ * @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);
- }
+ return ObjectModel::hydrateCollection('OrderInvoice', $order_invoice_list);
+ }
+ /**
+ * @since 1.5
+ * @static
+ * @param $id_order_invoice
+ */
+ public static function getCarrier($id_order_invoice)
+ {
+ $carrier = false;
+ if ($id_carrier = OrderInvoice::getCarrierId($id_order_invoice))
+ $carrier = new Carrier((int)$id_carrier);
+
+ return $carrier;
+ }
/**
* @since 1.5
* @static
* @param $id_order_invoice
*/
- public static function getCarrier($id_order_invoice)
- {
- $carrier = false;
- if ($id_carrier = OrderInvoice::getCarrierId($id_order_invoice))
- $carrier = new Carrier((int)$id_carrier);
+ public static function getCarrierId($id_order_invoice)
+ {
+ $sql = 'SELECT `id_carrier`
+ FROM `'._DB_PREFIX_.'order_carrier`
+ WHERE `id_order_invoice` = '.(int)$id_order_invoice;
- return $carrier;
- }
+ return Db::getInstance()->getValue($sql);
+ }
- /**
- * @since 1.5
- * @static
- * @param $id_order_invoice
- */
- public static function getCarrierId($id_order_invoice)
- {
- $sql = 'SELECT `id_carrier`
- FROM `'._DB_PREFIX_.'order_carrier`
- WHERE `id_order_invoice` = '.(int)$id_order_invoice;
-
- return Db::getInstance()->getValue($sql);
- }
+ /**
+ * @static
+ * @param $id
+ * @return OrderInvoice
+ */
+ public static function retrieveOneById($id)
+ {
+ $order_invoice = new OrderInvoice($id);
+ if (!Validate::isLoadedObject($order_invoice))
+ throw new PrestashopException('Can\'t load Order Invoice object for id: '.$id);
+ return $order_invoice;
+ }
}
\ No newline at end of file
diff --git a/classes/order/OrderPayment.php b/classes/order/OrderPayment.php
index 721f60974..0a60ddbc9 100644
--- a/classes/order/OrderPayment.php
+++ b/classes/order/OrderPayment.php
@@ -29,6 +29,7 @@ class OrderPaymentCore extends ObjectModel
{
public $id_order;
public $id_currency;
+ public $id_order_invoice;
public $amount;
public $payment_method;
public $conversion_rate;
@@ -48,6 +49,7 @@ class OrderPaymentCore extends ObjectModel
'fields' => array(
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
+ 'id_order_invoice' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true),
'payment_method' => array('type' => self::TYPE_STRING, 'validate' => 'isName'),
'conversion_rate' => array('type' => self::TYPE_INT, 'validate' => 'isFloat'),
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index 79eb3d84f..ebd367a71 100755
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -559,6 +559,10 @@ class AdminOrdersControllerCore extends AdminController
$order = new Order(Tools::getValue('id_order'));
$amount = str_replace(',', '.', Tools::getValue('payment_amount'));
$currency = new Currency(Tools::getValue('payment_currency'));
+ if ($order->hasInvoice())
+ $order_invoice = new OrderInvoice(Tools::getValue('payment_invoice'));
+ else
+ $order_invoice = null;
if (!Validate::isLoadedObject($order))
$this->_errors[] = Tools::displayError('Order can\'t be found');
elseif (!Validate::isPrice($amount))
@@ -569,11 +573,13 @@ class AdminOrdersControllerCore extends AdminController
$this->_errors[] = Tools::displayError('Transaction ID is invalid');
elseif (!Validate::isLoadedObject($currency))
$this->_errors[] = Tools::displayError('Currency is invalid');
+ elseif ($order->hasInvoice() && !Validate::isLoadedObject($order_invoice))
+ $this->_errors[] = Tools::displayError('Invoice is invalid');
elseif (!Validate::isDate(Tools::getValue('payment_date')))
$this->_errors[] = Tools::displayError('Date is invalid');
else
{
- if (!$order->addOrderPayment($amount, Tools::getValue('payment_method'), Tools::getValue('payment_transaction_id'), $currency, Tools::getValue('payment_date')))
+ if (!$order->addOrderPayment($amount, Tools::getValue('payment_method'), Tools::getValue('payment_transaction_id'), $currency, Tools::getValue('payment_date'), $order_invoice))
$this->_errors[] = Tools::displayError('An error occured on adding of order payment');
else
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
@@ -839,9 +845,9 @@ class AdminOrdersControllerCore extends AdminController
// Tax rate for this customer
if (Tools::isSubmit('id_address'))
$product['tax_rate'] = $productObj->getTaxesRate(new Address(Tools::getValue('id_address')));
-
+
$product['warehouse_list'] = array();
-
+
foreach($attributes AS $attribute)
{
if (!isset($combinations[$attribute['id_product_attribute']]['attributes']))
@@ -859,23 +865,23 @@ class AdminOrdersControllerCore extends AdminController
}
if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock']))
$combinations[$attribute['id_product_attribute']]['qty_in_stock']= StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], $attribute['id_product_attribute'], (int)$this->context->shop->getID());
-
+
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
$product['warehouse_list'][$attribute['id_product_attribute']] = Warehouse::getProductWarehouseList($product['id_product'], $attribute['id_product_attribute']);
else
$product['warehouse_list'][$attribute['id_product_attribute']] = array();
-
+
$product['stock'][$attribute['id_product_attribute']] = Product::getRealQuantity($product['id_product'], $attribute['id_product_attribute']);
-
+
}
-
+
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
$product['warehouse_list'][0] = Warehouse::getProductWarehouseList($product['id_product']);
else
$product['warehouse_list'][0] = array();
-
+
$product['stock'][0] = Product::getRealQuantity($product['id_product'], 0, 0);
-
+
foreach ($combinations AS &$combination)
$combination['attributes'] = rtrim($combination['attributes'], ' - ');