diff --git a/admin-dev/themes/template/orders/view.tpl b/admin-dev/themes/template/orders/view.tpl index 7a33fde02..118161dec 100755 --- a/admin-dev/themes/template/orders/view.tpl +++ b/admin-dev/themes/template/orders/view.tpl @@ -155,7 +155,7 @@

| Date | -Document | -Number | -+ | {l s='Date'} | +{l s='Document'} | +{l s='Number'} | +{l s='Amount'} | +{dateFormat date=$document->date_add} | Invoice | #{Configuration::get('PS_INVOICE_PREFIX', $current_id_lang)}{'%06d'|sprintf:$document->number} | -![]() |
+ + {*if TYPE DOCUMENT = INVOICE *} + {displayPrice price=$document->total_paid_tax_incl currency=$currency->id} + {if $document->getRestPaid()} + ({displayPrice price=$document->getRestPaid() currency=$currency->id} {l s='not paid'}) + {/if} + {*/if*} + | +
+ {*if TYPE DOCUMENT = INVOICE *}
+ {if $document->getRestPaid()}
+
+ {/if}
+
+ {*/if*}
+ |
+ {*if TYPE DOCUMENT = INVOICE *}
+ {*/if*}
{foreachelse}
|---|---|---|---|---|---|---|---|---|
| + |
{l s='No document is available'} |
@@ -288,7 +306,7 @@
{l s='paid instead of'} {displayPrice price=$order->total_paid_tax_incl currency=$currency->id}
-
diff --git a/classes/order/Order.php b/classes/order/Order.php
index 11153fdec..ba407844a 100644
--- a/classes/order/Order.php
+++ b/classes/order/Order.php
@@ -1397,6 +1397,20 @@ class OrderCore extends ObjectModel
return $order_invoices;
}
+ /**
+ * Get all not paid invoices for the current order
+ * @since 1.5.0.2
+ * @return Collection of Order invoice not paid
+ */
+ public function getNotPaidInvoicesCollection()
+ {
+ $invoices = $this->getInvoicesCollection();
+ foreach ($invoices as $key => $invoice)
+ if ($invoice->isPaid())
+ unset($invoices[$key]);
+ return $invoices;
+ }
+
/**
* Get total paid
*
diff --git a/classes/order/OrderHistory.php b/classes/order/OrderHistory.php
index 011d6d2af..955555103 100644
--- a/classes/order/OrderHistory.php
+++ b/classes/order/OrderHistory.php
@@ -143,6 +143,28 @@ class OrderHistoryCore extends ObjectModel
}
}
+ // Set order as paid
+ if ($newOS->paid == 1)
+ {
+ $invoices = $order->getInvoicesCollection();
+ $payment_method = Module::getInstanceByName($order->module);
+ foreach ($invoices as $invoice)
+ {
+ $rest_paid = $invoice->getRestPaid();
+ if ($rest_paid)
+ {
+ $payment = new OrderPayment();
+ $payment->id_order = $order->id;
+ $payment->id_order_invoice = $invoice->id;
+ $payment->id_currency = $order->id_currency;
+ $payment->amount = $rest_paid;
+ $payment->payment_method = $payment_method->displayName;
+ $payment->conversion_rate = 1;
+ $payment->save();
+ }
+ }
+ }
+
$this->id_order_state = (int)($new_order_state);
/* Change invoice number of order ? */
diff --git a/classes/order/OrderInvoice.php b/classes/order/OrderInvoice.php
index 1a2a34028..861a10132 100644
--- a/classes/order/OrderInvoice.php
+++ b/classes/order/OrderInvoice.php
@@ -69,6 +69,9 @@ class OrderInvoiceCore extends ObjectModel
/** @var intger */
public $date_add;
+ /** @var array Total paid cache */
+ protected static $_total_paid_cache = array();
+
/**
* @see ObjectModel::$definition
*/
@@ -449,4 +452,40 @@ class OrderInvoiceCore extends ObjectModel
throw new PrestashopException('Can\'t load Order Invoice object for id: '.$id);
return $order_invoice;
}
+
+ /**
+ * Amounts of payments
+ * @since 1.5.0.2
+ * @return float Total paid
+ */
+ public function getTotalPaid()
+ {
+ if (!array_key_exists($this->id, self::$_total_paid_cache))
+ {
+ self::$_total_paid_cache[$this->id] = 0;
+ $payments = OrderPayment::getByInvoiceId($this->id);
+ foreach ($payments as $payment)
+ self::$_total_paid_cache[$this->id] += $payment->amount;
+ }
+ return self::$_total_paid_cache[$this->id];
+ }
+
+ /**
+ * Rest Paid
+ * @since 1.5.0.2
+ * @return float Rest Paid
+ */
+ public function getRestPaid()
+ {
+ return $this->total_paid_tax_incl - $this->getTotalPaid();
+ }
+
+ /**
+ * @since 1.5.0.2
+ * @return bool Is paid ?
+ */
+ public function isPaid()
+ {
+ return $this->getTotalPaid() == $this->total_paid_tax_incl;
+ }
}
\ No newline at end of file
diff --git a/classes/order/OrderPayment.php b/classes/order/OrderPayment.php
index 0a60ddbc9..91e18c59a 100644
--- a/classes/order/OrderPayment.php
+++ b/classes/order/OrderPayment.php
@@ -81,8 +81,21 @@ class OrderPaymentCore extends ObjectModel
{
return Db::getInstance()->ExecuteS('
SELECT *
- FROM `'._DB_PREFIX_.'payment_order`
+ FROM `'._DB_PREFIX_.'order_payment`
WHERE `id_order` = '.(int)$id_order);
}
+
+ /**
+ * Get Order Payments By Invoice ID
+ * @static
+ * @param $id_invoice Invoice ID
+ * @return Collection Collection
+ */
+ public static function getByInvoiceId($id_invoice)
+ {
+ $payments = new Collection('OrderPayment');
+ $payments->where('a.id_order_invoice = '.(int)$id_invoice);
+ return $payments;
+ }
}
diff --git a/classes/order/OrderState.php b/classes/order/OrderState.php
index 07221fb24..93ae8ac34 100644
--- a/classes/order/OrderState.php
+++ b/classes/order/OrderState.php
@@ -56,6 +56,9 @@ class OrderStateCore extends ObjectModel
/** @var boolean Shipped */
public $shipped;
+ /** @var boolean Paid */
+ public $paid;
+
/**
* @see ObjectModel::$definition
*/
@@ -72,6 +75,7 @@ class OrderStateCore extends ObjectModel
'unremovable' =>array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'delivery' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'hidden' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
+ 'paid' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
// Lang fields
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index b26832788..5fe56c0b9 100755
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -588,7 +588,8 @@ class AdminOrdersControllerCore extends AdminController
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
- elseif (Tools::isSubmit('submitEditNote')) {
+ elseif (Tools::isSubmit('submitEditNote'))
+ {
$id_order_invoice = (int)Tools::getValue('id_order_invoice');
$note = Tools::getValue('note');
$order_invoice = new OrderInvoice($id_order_invoice);
@@ -829,6 +830,7 @@ class AdminOrdersControllerCore extends AdminController
'can_edit' => ($this->tabAccess['edit'] == 1),
'current_id_lang' => $this->context->language->id,
'invoices_collection' => $order->getInvoicesCollection(),
+ 'not_paid_invoices_collection' => $order->getNotPaidInvoicesCollection(),
'HOOK_INVOICE' => Hook::exec('invoice', array('id_order' => $order->id)),
'HOOK_ADMIN_ORDER' => Hook::exec('adminOrder', array('id_order' => $order->id))
);
diff --git a/controllers/admin/AdminStatusesController.php b/controllers/admin/AdminStatusesController.php
index 9a2dc3615..20484e67b 100644
--- a/controllers/admin/AdminStatusesController.php
+++ b/controllers/admin/AdminStatusesController.php
@@ -283,6 +283,21 @@ class AdminStatusesControllerCore extends AdminController
'name' => 'name'
)
),
+ array(
+ 'type' => 'checkbox',
+ 'name' => 'paid',
+ 'values' => array(
+ 'query' => array(
+ array(
+ 'id' => 'on',
+ 'name' => $this->l('Set order as paid'),
+ 'val' => '1'
+ ),
+ ),
+ 'id' => 'id',
+ 'name' => 'name'
+ )
+ ),
array(
'type' => 'select_template',
'label' => $this->l('Template:'),
@@ -311,7 +326,8 @@ class AdminStatusesControllerCore extends AdminController
'invoice_on' => $this->getFieldValue($obj, 'invoice'),
'hidden_on' => $this->getFieldValue($obj, 'hidden'),
'send_email_on' => $this->getFieldValue($obj, 'send_email'),
- 'shipped_on' => $this->getFieldValue($obj, 'shipped')
+ 'shipped_on' => $this->getFieldValue($obj, 'shipped'),
+ 'paid_on' => $this->getFieldValue($obj, 'paid')
);
return parent::renderForm();
@@ -491,6 +507,7 @@ class AdminStatusesControllerCore extends AdminController
$_POST['send_email'] = (int)Tools::getValue('send_email_on');
$_POST['hidden'] = (int)Tools::getValue('hidden_on');
$_POST['shipped'] = (int)Tools::getValue('shipped_on');
+ $_POST['paid'] = (int)Tools::getValue('paid_on');
if (!$_POST['send_email'])
{
$languages = Language::getLanguages(false);
diff --git a/install-dev/sql/db.sql b/install-dev/sql/db.sql
index 1a5e2c00c..ae1b1da2c 100644
--- a/install-dev/sql/db.sql
+++ b/install-dev/sql/db.sql
@@ -1234,6 +1234,7 @@ CREATE TABLE `PREFIX_order_state` (
`logable` tinyint(1) NOT NULL default '0',
`delivery` tinyint(1) UNSIGNED NOT NULL default '0',
`shipped` tinyint(1) UNSIGNED NOT NULL default '0',
+ `paid` tinyint(1) UNSIGNED NOT NULL default '0',
PRIMARY KEY (`id_order_state`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
diff --git a/install-dev/sql/db_settings_lite.sql b/install-dev/sql/db_settings_lite.sql
index 411faa90a..3cc39f932 100644
--- a/install-dev/sql/db_settings_lite.sql
+++ b/install-dev/sql/db_settings_lite.sql
@@ -364,9 +364,9 @@ INSERT INTO `PREFIX_category` (`id_category`, `id_parent`, `level_depth`, `nleft
INSERT INTO `PREFIX_category_lang` (`id_category`, `id_lang`, `name`, `description`, `link_rewrite`, `meta_title`, `meta_keywords`, `meta_description`) VALUES
(1, 1, 'Home', '', 'home', NULL, NULL, NULL),(1, 2, 'Accueil', '', 'home', NULL, NULL, NULL),(1, 3, 'Inicio', '', 'home', NULL, NULL, NULL),(1, 4, 'Start', '', 'home', NULL, NULL, NULL),(1, 5, 'Home page', '', 'home', NULL, NULL, NULL);
-INSERT INTO `PREFIX_order_state` (`id_order_state`, `invoice`, `send_email`, `color`, `unremovable`, `logable`, `delivery`, `shipped`) VALUES
-(1, 0, 1, 'RoyalBlue', 1, 0, 0, 0),(2, 1, 1, 'LimeGreen', 1, 1, 0, 0),(3, 1, 1, 'DarkOrange', 1, 1, 1, 0),(4, 1, 1, 'BlueViolet', 1, 1, 1, 1),(5, 1, 0, '#108510', 1, 1, 1, 1),
-(6, 0, 1, 'Crimson', 1, 0, 0, 0),(7, 1, 1, '#ec2e15', 1, 0, 0, 0),(8, 0, 1, '#8f0621', 1, 0, 0, 0),(9, 1, 1, 'HotPink', 1, 0, 0, 0),(10, 0, 1, 'RoyalBlue', 1, 0, 0, 0),(11, 0, 0, 'RoyalBlue', 1, 0, 0, 0),(12, 1, 0, 'LimeGreen', 1, 1, 0, 0);
+INSERT INTO `PREFIX_order_state` (`id_order_state`, `invoice`, `send_email`, `color`, `unremovable`, `logable`, `delivery`, `shipped`, `paid`) VALUES
+(1, 0, 1, 'RoyalBlue', 1, 0, 0, 0, 0),(2, 1, 1, 'LimeGreen', 1, 1, 0, 0, 1),(3, 1, 1, 'DarkOrange', 1, 1, 1, 0, 1),(4, 1, 1, 'BlueViolet', 1, 1, 1, 1, 1),(5, 1, 0, '#108510', 1, 1, 1, 1, 1),
+(6, 0, 1, 'Crimson', 1, 0, 0, 0, 0),(7, 1, 1, '#ec2e15', 1, 0, 0, 0, 0),(8, 0, 1, '#8f0621', 1, 0, 0, 0, 0),(9, 1, 1, 'HotPink', 1, 0, 0, 0, 1),(10, 0, 1, 'RoyalBlue', 1, 0, 0, 0, 0),(11, 0, 0, 'RoyalBlue', 1, 0, 0, 0, 0),(12, 1, 0, 'LimeGreen', 1, 1, 0, 0, 1);
INSERT INTO `PREFIX_order_state_lang` (`id_order_state`, `id_lang`, `name`, `template`) VALUES
(1, 1, 'Awaiting cheque payment', 'cheque'),
diff --git a/install-dev/sql/upgrade/1.5.0.2.sql b/install-dev/sql/upgrade/1.5.0.2.sql
index 2f2ff6787..302cd4600 100644
--- a/install-dev/sql/upgrade/1.5.0.2.sql
+++ b/install-dev/sql/upgrade/1.5.0.2.sql
@@ -47,6 +47,10 @@ ALTER TABLE `PREFIX_suplier` ADD COLUMN `id_address` int(10) unsigned NOT NULL A
ALTER TABLE `PREFIX_address` ADD COLUMN `id_warehouse` int(10) unsigned NOT NULL DEFAULT 0 AFTER `id_supplier`;
ALTER TABLE `PREFIX_order_invoice` ADD `note` TEXT NOT NULL AFTER `total_wrapping_tax_incl`;
+/* ORDER STATES */
+ALTER TABLE `PREFIX_order_state` ADD `paid` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `shipped`;
+UPDATE `PREFIX_order_state` SET `paid` = 1 WHERE `id_order_state` IN (2, 3, 4, 5, 9, 12);
+
/************************
* STOCK MANAGEMENT
*************************/
diff --git a/js/admin_order.js b/js/admin_order.js
index ce1b840aa..2ce9f96d6 100644
--- a/js/admin_order.js
+++ b/js/admin_order.js
@@ -478,6 +478,17 @@ $(document).ready(function() {
});
return false;
});
+
+ $('.js-set-payment').click(function() {
+ var amount = $(this).attr('data-amount');
+ $('input[name=payment_amount]').val(amount);
+ var id_invoice = $(this).attr('data-id-invoice');
+ $('select[name=payment_invoice] option[value='+id_invoice+']').attr('selected', true);
+
+ $.scrollTo('#formAddPayment', 1000);
+
+ return false;
+ })
});
function addProductRefreshTotal()
|||||||