From 48c76d5889e5c5f14c2201801a07ff0fe3ecdad4 Mon Sep 17 00:00:00 2001 From: dSevere Date: Mon, 31 Oct 2011 16:52:40 +0000 Subject: [PATCH] // Stock : add state management on orders + bugs fix --- ...ist_action_supplier_order_change_state.tpl | 27 +++++++++++++ classes/stock/SupplierOrder.php | 29 +++++++++++++- classes/stock/SupplierOrderDetail.php | 2 +- classes/stock/SupplierOrderState.php | 38 ++++++++++++++++++- 4 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 admin-dev/themes/template/helper/list/list_action_supplier_order_change_state.tpl diff --git a/admin-dev/themes/template/helper/list/list_action_supplier_order_change_state.tpl b/admin-dev/themes/template/helper/list/list_action_supplier_order_change_state.tpl new file mode 100644 index 000000000..3017535b1 --- /dev/null +++ b/admin-dev/themes/template/helper/list/list_action_supplier_order_change_state.tpl @@ -0,0 +1,27 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 9197 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{$action} \ No newline at end of file diff --git a/classes/stock/SupplierOrder.php b/classes/stock/SupplierOrder.php index 90499b9b6..01c423b4c 100755 --- a/classes/stock/SupplierOrder.php +++ b/classes/stock/SupplierOrder.php @@ -182,7 +182,12 @@ class SupplierOrderCore extends ObjectModel { $this->calculatePrices(); - return parent::update($null_values); + $return = parent::update($null_values); + + if ($return) + $this->addHistory(); + + return $return; } /** @@ -192,7 +197,12 @@ class SupplierOrderCore extends ObjectModel { $this->calculatePrices(); - return parent::add($autodate, $null_values); + $return = parent::add($autodate, $null_values); + + if ($return) + $this->addHistory(); + + return $return; } /** @@ -301,4 +311,19 @@ class SupplierOrderCore extends ObjectModel return (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query) == 1); } + + /** + * Add order history + * + * @return bool + */ + protected function addHistory() + { + $history = new SupplierOrderHistory(); + $history->id_supplier_order = $this->id; + $history->id_state = $this->id_supplier_order_state; + $history->id_employee = $this->id_employee; + + $history->save(); + } } \ No newline at end of file diff --git a/classes/stock/SupplierOrderDetail.php b/classes/stock/SupplierOrderDetail.php index 60a7526ad..b6a5874e9 100755 --- a/classes/stock/SupplierOrderDetail.php +++ b/classes/stock/SupplierOrderDetail.php @@ -228,7 +228,7 @@ class SupplierOrderDetailCore extends ObjectModel // calcul tax value $this->tax_value = $this->price_with_discount_te * ((float)$this->tax_rate / 100); - $this->price_ti = $this->price_with_discount_te - $this->tax_value; + $this->price_ti = $this->price_with_discount_te + $this->tax_value; // define default values for order discount fields $this->tax_value_with_order_discount = $this->tax_value; diff --git a/classes/stock/SupplierOrderState.php b/classes/stock/SupplierOrderState.php index fd771391c..700f4a345 100755 --- a/classes/stock/SupplierOrderState.php +++ b/classes/stock/SupplierOrderState.php @@ -109,12 +109,13 @@ class SupplierOrderStateCore extends ObjectModel /** * Gets the list of supplier order states * + * @param int $id_state_referrer The state refferer id used to know what state is available after the current state refferer * @param int $id_lang The language id * @return array */ - public static function getSupplierOrderStates($id_lang = 0) + public static function getSupplierOrderStates($id_state_referrer = null, $id_lang = null) { - if ($id_lang == 0) + if ($id_lang == null) $id_lang = Context::getContext()->language->id; $query = new DbQuery(); @@ -122,6 +123,39 @@ class SupplierOrderStateCore extends ObjectModel $query->from('supplier_order_state s'); $query->leftjoin('supplier_order_state_lang sl ON (s.id_supplier_order_state = sl.id_supplier_order_state AND sl.id_lang='.(int)$id_lang.')'); + if (!is_null($id_state_referrer)) + { + $is_receipt_state = false; + $is_editable = false; + $is_delivery_note = false; + $is_pending_receipt = false; + + //check current state to see what state is available + $state = new SupplierOrderState((int)$id_state_referrer); + if (Validate::isLoadedObject($state)) + { + $is_receipt_state = $state->receipt_state; + $is_editable = $state->editable; + $is_delivery_note = $state->delivery_note; + $is_pending_receipt = $state->pending_receipt; + } + + $query->where('s.id_supplier_order_state <> '.$id_state_referrer); + + //check first if the order is editable + if ($is_editable) + $query->where(' s.editable = 0'); + //check if the delivery note is available + else if ($is_delivery_note) + $query->where(' s.delivery_note = 0 AND s.editable = 0'); + //check if the state correspond to a pending receipt state + else if ($is_pending_receipt) + $query->where(' s.receipt_state = 1 OR (s.receipt_state = 0 AND s.pending_receipt = 0)) AND s.delivery_note = 0 AND s.editable = 0'); + //check if the state correspond to a receipt state + else if ($is_receipt_state) + $query->where(' s.receipt_state = 1 OR (s.receipt_state = 0 AND s.pending_receipt = 0 AND s.delivery_note = 0 AND s.editable = 0)'); + } + return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); } } \ No newline at end of file