From 43e1e225d709de887161dbe0681df909a9b68d77 Mon Sep 17 00:00:00 2001 From: dSevere Date: Tue, 8 Nov 2011 17:55:17 +0000 Subject: [PATCH] // stock : update supplier orders interface + change state bug fix --- ...ist_action_supplier_order_change_state.tpl | 2 +- .../template/helper/list/list_header.tpl | 5 +- .../themes/template/helper/view/view.tpl | 3 +- .../themes/template/supplier_orders/view.tpl | 10 +-- classes/stock/SupplierOrder.php | 22 ++++- classes/stock/SupplierOrderState.php | 11 +-- .../admin/AdminSupplierOrdersController.php | 88 ++++++++++++------- install-dev/sql/db_settings_lite.sql | 12 +-- 8 files changed, 94 insertions(+), 59 deletions(-) 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 index 3017535b1..ba21670b4 100644 --- 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 @@ -24,4 +24,4 @@ * International Registered Trademark & Property of PrestaShop SA *} -{$action} \ No newline at end of file +{$action} \ No newline at end of file diff --git a/admin-dev/themes/template/helper/list/list_header.tpl b/admin-dev/themes/template/helper/list/list_header.tpl index 11a14108a..6526ff5ab 100644 --- a/admin-dev/themes/template/helper/list/list_header.tpl +++ b/admin-dev/themes/template/helper/list/list_header.tpl @@ -75,8 +75,9 @@ {/if} -
{block name="leadin"}{/block}
- +{if !$simple_header} +
{block name="leadin"}{/block}
+{/if}
diff --git a/admin-dev/themes/template/helper/view/view.tpl b/admin-dev/themes/template/helper/view/view.tpl index f61d2099e..058656b32 100644 --- a/admin-dev/themes/template/helper/view/view.tpl +++ b/admin-dev/themes/template/helper/view/view.tpl @@ -35,9 +35,10 @@ {/block} -
{block name="leadin"}{/block}
{/if} +
{block name="leadin"}{/block}
+ {block name="override_tpl"}{/block} diff --git a/admin-dev/themes/template/supplier_orders/view.tpl b/admin-dev/themes/template/supplier_orders/view.tpl index f07008ccc..ef3c4245b 100755 --- a/admin-dev/themes/template/supplier_orders/view.tpl +++ b/admin-dev/themes/template/supplier_orders/view.tpl @@ -50,14 +50,14 @@ - +
{l s='Products'} {$supplier_order_detail_content}
- +
{l s='Summary'} @@ -105,11 +105,5 @@
- -
- - {l s='Back to supplier orders'} - -
{/block} diff --git a/classes/stock/SupplierOrder.php b/classes/stock/SupplierOrder.php index e72c73898..a06a8c62c 100755 --- a/classes/stock/SupplierOrder.php +++ b/classes/stock/SupplierOrder.php @@ -303,12 +303,28 @@ class SupplierOrderCore extends ObjectModel return ObjectModel::hydrateCollection('SupplierOrderDetail', $results); } + + /** + * Check if the order has entries + * + * @return bool + */ + public function hasEntries() + { + $query = new DbQuery(); + $query->select('COUNT(*)'); + $query->from('supplier_order_detail s'); + $query->where('s.id_supplier_order = '.(int)$this->id); + + return (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query) > 0); + } + /** * Check if the current state allow to edit the current order * * @return bool */ - protected function isEditable() + public function isEditable() { // build query $query = new DbQuery(); @@ -324,7 +340,7 @@ class SupplierOrderCore extends ObjectModel * * @return bool */ - protected function isDeliveryNoteAvailable() + public function isDeliveryNoteAvailable() { // build query $query = new DbQuery(); @@ -340,7 +356,7 @@ class SupplierOrderCore extends ObjectModel * * @return bool */ - protected function isInReceiptState() + public function isInReceiptState() { // build query $query = new DbQuery(); diff --git a/classes/stock/SupplierOrderState.php b/classes/stock/SupplierOrderState.php index 0aa87d399..bf9233f4c 100755 --- a/classes/stock/SupplierOrderState.php +++ b/classes/stock/SupplierOrderState.php @@ -151,16 +151,13 @@ class SupplierOrderStateCore extends ObjectModel //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.editable = 1 OR s.delivery_note = 1'); + //check if the delivery note is available or if the state correspond to a pending receipt state + else if ($is_delivery_note || $is_pending_receipt) $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)'); + $query->where('s.receipt_state = 1 OR s.enclosed = 1'); } return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); diff --git a/controllers/admin/AdminSupplierOrdersController.php b/controllers/admin/AdminSupplierOrdersController.php index bfc358009..356151347 100644 --- a/controllers/admin/AdminSupplierOrdersController.php +++ b/controllers/admin/AdminSupplierOrdersController.php @@ -35,12 +35,12 @@ class AdminSupplierOrdersControllerCore extends AdminController $this->context = Context::getContext(); $this->table = 'supplier_order_state'; $this->className = 'SupplierOrderState'; - $this->colorOnBackground = true; $this->lang = true; $this->fieldsDisplay = array( 'name' => array( 'title' => $this->l('Name'), + 'color' => 'color', ), 'editable' => array( 'title' => $this->l('Editable?'), @@ -127,7 +127,7 @@ class AdminSupplierOrdersControllerCore extends AdminController if ($this->tabAccess['edit'] === '1') $this->display = 'edit'; else - $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); + $this->_errors[] = Tools::displayError($this->l('You do not have permission to edit here.')); } } @@ -137,9 +137,12 @@ class AdminSupplierOrdersControllerCore extends AdminController */ public function initForm() { - if (Tools::isSubmit('addsupplier_order_state')) + if (Tools::isSubmit('addsupplier_order_state') || Tools::isSubmit('updatesupplier_order_state')) { - $this->toolbar_title = $this->l('Stock : Add Supplier order state'); + if (Tools::isSubmit('updatesupplier_order_state')) + $this->toolbar_title = $this->l('Stock : Update Supplier order state'); + else + $this->toolbar_title = $this->l('Stock : Add Supplier order state'); $this->fields_form = array( 'legend' => array( @@ -434,11 +437,11 @@ class AdminSupplierOrdersControllerCore extends AdminController $this->identifier = 'id_supplier_order'; $this->lang = false; - $this->addRowAction('edit'); - $this->addRowAction('changestate'); - $this->addRowAction('details'); - $this->addRowAction('view'); $this->addRowAction('updatereceipt'); + $this->addRowAction('changestate'); + $this->addRowAction('edit'); + $this->addRowAction('view'); + $this->addRowAction('details'); // test if a filter is applied for this list if (Tools::isSubmit('submitFilter'.$this->table) || $this->context->cookie->{'submitFilter'.$this->table} !== false) @@ -474,7 +477,8 @@ class AdminSupplierOrdersControllerCore extends AdminController 'state' => array( 'title' => $this->l('State'), 'width' => 150, - 'filter_key' => 'stl!name' + 'filter_key' => 'stl!name', + 'color' => 'color', ), 'date_add' => array( 'title' => $this->l('Creation date'), @@ -555,14 +559,14 @@ class AdminSupplierOrdersControllerCore extends AdminController if ($id_supplier_order <= 0) { - $this->_errors[] = Tools::displayError('The specified supplier order is not valid'); + $this->_errors[] = Tools::displayError($this->l('The specified supplier order is not valid')); return parent::initContent(); } $supplier_order = new SupplierOrder($id_supplier_order); if (!Validate::isLoadedObject($supplier_order)) { - $this->_errors[] = Tools::displayError('The specified supplier order is not valid'); + $this->_errors[] = Tools::displayError($this->l('The specified supplier order is not valid')); return parent::initContent(); } @@ -1006,9 +1010,9 @@ class AdminSupplierOrdersControllerCore extends AdminController { // Checks access if (Tools::isSubmit('submitAddsupplier_order') && !($this->tabAccess['add'] === '1')) - $this->_errors[] = Tools::displayError('You do not have the required permission to add a supplier order.'); + $this->_errors[] = Tools::displayError($this->l('You do not have the required permission to add a supplier order.')); if (Tools::isSubmit('submitUpdateReceipt') && !($this->tabAccess['edit'] === '1')) - $this->_errors[] = Tools::displayError('You do not have the required permission to edit an order.'); + $this->_errors[] = Tools::displayError($this->l('You do not have the required permission to edit an order.')); // Global checks when add / update a supplier order if (Tools::isSubmit('submitAddsupplier_order')) { @@ -1017,17 +1021,17 @@ class AdminSupplierOrdersControllerCore extends AdminController // get supplier ID $id_supplier = (int)Tools::getValue('id_supplier', 0); if ($id_supplier <= 0 || !Supplier::supplierExists($id_supplier)) - $this->_errors[] = Tools::displayError('The selected supplier is not valid.'); + $this->_errors[] = Tools::displayError($this->l('The selected supplier is not valid.')); // get warehouse id $id_warehouse = (int)Tools::getValue('id_warehouse', 0); if ($id_warehouse <= 0 || !Warehouse::exists($id_warehouse)) - $this->_errors[] = Tools::displayError('The selected warehouse is not valid.'); + $this->_errors[] = Tools::displayError($this->l('The selected warehouse is not valid.')); // get currency id $id_currency = (int)Tools::getValue('id_currency', 0); if ($id_currency <= 0 || ( !($result = Currency::getCurrency($id_currency)) || empty($result) )) - $this->_errors[] = Tools::displayError('The selected currency is not valid.'); + $this->_errors[] = Tools::displayError($this->l('The selected currency is not valid.')); // specify employee $_POST['id_employee'] = $this->context->employee->id; @@ -1048,17 +1052,17 @@ class AdminSupplierOrdersControllerCore extends AdminController && Tools::isSubmit('id_supplier_order_state')) { if ($this->tabAccess['edit'] != '1') - $this->_errors[] = Tools::displayError('You do not have permissions to change order state.'); + $this->_errors[] = Tools::displayError($this->l('You do not have permissions to change order state.')); // get state ID $id_state = (int)Tools::getValue('id_supplier_order_state', 0); if ($id_state <= 0) - $this->_errors[] = Tools::displayError('The selected supplier order state is not valid.'); + $this->_errors[] = Tools::displayError($this->l('The selected supplier order state is not valid.')); // get supplier order ID $id_supplier_order = (int)Tools::getValue('id_supplier_order', 0); if ($id_supplier_order <= 0) - $this->_errors[] = Tools::displayError('The supplier order id is not valid.'); + $this->_errors[] = Tools::displayError($this->l('The supplier order id is not valid.')); if (!count($this->_errors)) { @@ -1074,18 +1078,27 @@ class AdminSupplierOrdersControllerCore extends AdminController // if state is valid, change it in the order if ($id_state == $state['id_supplier_order_state']) { - $supplier_order->id_supplier_order_state = $state['id_supplier_order_state']; - if ($supplier_order->save()) + // special case of validate state - check if there are products in the order + if ($supplier_order->isEditable() && !$supplier_order->hasEntries()) + $this->_errors[] = Tools::displayError( + $this->l('It is not possible to change the state of this order because of no product are present in it') + ); + + if (!count($this->_errors)) { - $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; - $redirect = self::$currentIndex.'&token='.$token; - Tools::redirectAdmin($redirect.'&conf=5'); + $supplier_order->id_supplier_order_state = $state['id_supplier_order_state']; + if ($supplier_order->save()) + { + $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; + $redirect = self::$currentIndex.'&token='.$token; + Tools::redirectAdmin($redirect.'&conf=5'); + } } } } } else - $this->_errors[] = Tools::displayError('The selected supplier is not valid.'); + $this->_errors[] = Tools::displayError($this->l('The selected supplier is not valid.')); } } @@ -1106,7 +1119,7 @@ class AdminSupplierOrdersControllerCore extends AdminController $rows = Tools::getValue('supplier_order_detailBox'); if (!$rows) { - $this->_errors[] = Tools::displayError('You did not select any product to update'); + $this->_errors[] = Tools::displayError($this->l('You did not select any product to update')); return; } @@ -1122,7 +1135,7 @@ class AdminSupplierOrdersControllerCore extends AdminController // checks if there is something to update if (!count($to_update)) { - $this->_errors[] = Tools::displayError('You did not select any product to update'); + $this->_errors[] = Tools::displayError($this->l('You did not select any product to update')); return; } @@ -1135,7 +1148,7 @@ class AdminSupplierOrdersControllerCore extends AdminController // checks if quantity is valid // It's possible to receive more quantity than expected in case of a shipping error from the supplier if (!Validate::isInt($quantity) || $quantity <= 0) - $this->_errors[] = sprintf(Tools::displayError('Quantity (%d) for product #%d is not valid'), (int)$quantity, (int)$id_supplier_order_detail); + $this->_errors[] = sprintf(Tools::displayError($this->l('Quantity (%d) for product #%d is not valid')), (int)$quantity, (int)$id_supplier_order_detail); else // everything is valid : updates { // creates the history @@ -1156,7 +1169,7 @@ class AdminSupplierOrdersControllerCore extends AdminController $warehouse = new Warehouse($supplier_order->id_warehouse); if (!Validate::isLoadedObject($warehouse)) { - $this->_errors[] = Tools::displayError('Warehouse could not be loaded'); + $this->_errors[] = Tools::displayError($this->l('Warehouse could not be loaded')); return; } $manager = StockManagerFactory::getManager(); @@ -1175,7 +1188,7 @@ class AdminSupplierOrdersControllerCore extends AdminController $supplier_order->save(); } else - $this->_errors[] = Tools::displayError('Something went wrong when adding products in warehouse'); + $this->_errors[] = Tools::displayError($this->l('Something went wrong when adding products in warehouse')); } } } @@ -1605,7 +1618,7 @@ class AdminSupplierOrdersControllerCore extends AdminController $content = ''; if ($supplier_order_state->editable == false) // @TODO Decide what states are allowed - $content .= 'invoice'; + $content .= 'invoice'; else $content .= '-'; $content .= ''; @@ -1627,6 +1640,19 @@ class AdminSupplierOrdersControllerCore extends AdminController 'href' => '#', 'desc' => $this->l('Save') ); + + // Default cancel button - like old back link + if (!isset($this->no_back) || $this->no_back == false) + { + $back = Tools::safeOutput(Tools::getValue('back', '')); + if (empty($back)) + $back = self::$currentIndex.'&token='.$this->token; + + $this->toolbar_btn['cancel'] = array( + 'href' => $back, + 'desc' => $this->l('Cancel') + ); + } break; case 'add': diff --git a/install-dev/sql/db_settings_lite.sql b/install-dev/sql/db_settings_lite.sql index 2aec14c45..18bf5e962 100644 --- a/install-dev/sql/db_settings_lite.sql +++ b/install-dev/sql/db_settings_lite.sql @@ -1531,12 +1531,12 @@ Country:name phone' WHERE `PREFIX_address_format`.`id_country` = 4; INSERT INTO `PREFIX_supplier_order_state` (`id_supplier_order_state`, `delivery_note`, `editable`, `receipt_state`, `pending_receipt`, `enclosed`, `color`) VALUES -(1, 0, 1, 0, 0, 0, 'lightblue'), -(2, 1, 0, 0, 0, 0, '#e7fbff'), -(3, 0, 0, 0, 1, 0, '#ffdbfd'), -(4, 0, 0, 1, 1, 0, '#ffd3d3'), -(5, 0, 0, 1, 0, 1, '#d8ffd7'), -(6, 0, 0, 0, 0, 1, '#cccccc'); +(1, 0, 1, 0, 0, 0, '#faab00'), +(2, 1, 0, 0, 0, 0, '#273cff'), +(3, 0, 0, 0, 1, 0, '#ff37f5'), +(4, 0, 0, 1, 1, 0, '#ff3e33'), +(5, 0, 0, 1, 0, 1, '#00d60c'), +(6, 0, 0, 0, 0, 1, '#666666'); INSERT INTO `PREFIX_supplier_order_state_lang` (`id_supplier_order_state`, `id_lang`, `name`) VALUES (1, 1, 'creation in progress'),