// stock : update supplier orders interface + change state bug fix

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9975 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
dSevere
2011-11-08 17:55:17 +00:00
parent fc8b5cda7c
commit f8ba11c870
8 changed files with 94 additions and 59 deletions
@@ -24,4 +24,4 @@
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*} *}
<a href="{$href}"> <a href="{$href}">
<img src="../img/admin/cog.gif" alt="{$action}" title="{$action}" /></a> <img src="../img/admin/cms.gif" alt="{$action}" title="{$action}" /></a>
@@ -75,8 +75,9 @@
</div> </div>
{/if} {/if}
<div class="leadin">{block name="leadin"}{/block}</div> {if !$simple_header}
<div class="leadin">{block name="leadin"}{/block}</div>
{/if}
<form method="post" action="{$action}" class="form"> <form method="post" action="{$action}" class="form">
<input type="hidden" id="submitFilter{$table}" name="submitFilter{$table}" value="0"/> <input type="hidden" id="submitFilter{$table}" name="submitFilter{$table}" value="0"/>
@@ -35,9 +35,10 @@
{/block} {/block}
</h3> </h3>
</div> </div>
<div class="leadin">{block name="leadin"}{/block}</div>
</div> </div>
</div> </div>
{/if} {/if}
<div class="leadin">{block name="leadin"}{/block}</div>
{block name="override_tpl"}{/block} {block name="override_tpl"}{/block}
@@ -50,14 +50,14 @@
</table> </table>
</fieldset> </fieldset>
</div> </div>
<div style="margin-top: 20px;"> <div style="margin-top: 20px;">
<fieldset> <fieldset>
<legend>{l s='Products'}</legend> <legend>{l s='Products'}</legend>
{$supplier_order_detail_content} {$supplier_order_detail_content}
</fieldset> </fieldset>
</div> </div>
<div style="margin-top: 20px;"> <div style="margin-top: 20px;">
<fieldset> <fieldset>
<legend>{l s='Summary'}</legend> <legend>{l s='Summary'}</legend>
@@ -105,11 +105,5 @@
</table> </table>
</fieldset> </fieldset>
</div> </div>
<div style="margin-top: 20px;">
<a href="{$current}&token={$token}">
<img src="../img/admin/arrow2.gif" />{l s='Back to supplier orders'}
</a>
</div>
{/block} {/block}
+19 -3
View File
@@ -303,12 +303,28 @@ class SupplierOrderCore extends ObjectModel
return ObjectModel::hydrateCollection('SupplierOrderDetail', $results); 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 * Check if the current state allow to edit the current order
* *
* @return bool * @return bool
*/ */
protected function isEditable() public function isEditable()
{ {
// build query // build query
$query = new DbQuery(); $query = new DbQuery();
@@ -324,7 +340,7 @@ class SupplierOrderCore extends ObjectModel
* *
* @return bool * @return bool
*/ */
protected function isDeliveryNoteAvailable() public function isDeliveryNoteAvailable()
{ {
// build query // build query
$query = new DbQuery(); $query = new DbQuery();
@@ -340,7 +356,7 @@ class SupplierOrderCore extends ObjectModel
* *
* @return bool * @return bool
*/ */
protected function isInReceiptState() public function isInReceiptState()
{ {
// build query // build query
$query = new DbQuery(); $query = new DbQuery();
+4 -7
View File
@@ -151,16 +151,13 @@ class SupplierOrderStateCore extends ObjectModel
//check first if the order is editable //check first if the order is editable
if ($is_editable) if ($is_editable)
$query->where('s.editable = 0'); $query->where('s.editable = 1 OR s.delivery_note = 1');
//check if the delivery note is available //check if the delivery note is available or if the state correspond to a pending receipt state
else if ($is_delivery_note) else if ($is_delivery_note || $is_pending_receipt)
$query->where('s.delivery_note = 0 AND s.editable = 0'); $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 //check if the state correspond to a receipt state
else if ($is_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); return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
@@ -35,12 +35,12 @@ class AdminSupplierOrdersControllerCore extends AdminController
$this->context = Context::getContext(); $this->context = Context::getContext();
$this->table = 'supplier_order_state'; $this->table = 'supplier_order_state';
$this->className = 'SupplierOrderState'; $this->className = 'SupplierOrderState';
$this->colorOnBackground = true;
$this->lang = true; $this->lang = true;
$this->fieldsDisplay = array( $this->fieldsDisplay = array(
'name' => array( 'name' => array(
'title' => $this->l('Name'), 'title' => $this->l('Name'),
'color' => 'color',
), ),
'editable' => array( 'editable' => array(
'title' => $this->l('Editable?'), 'title' => $this->l('Editable?'),
@@ -127,7 +127,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
if ($this->tabAccess['edit'] === '1') if ($this->tabAccess['edit'] === '1')
$this->display = 'edit'; $this->display = 'edit';
else 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() 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( $this->fields_form = array(
'legend' => array( 'legend' => array(
@@ -434,11 +437,11 @@ class AdminSupplierOrdersControllerCore extends AdminController
$this->identifier = 'id_supplier_order'; $this->identifier = 'id_supplier_order';
$this->lang = false; $this->lang = false;
$this->addRowAction('edit');
$this->addRowAction('changestate');
$this->addRowAction('details');
$this->addRowAction('view');
$this->addRowAction('updatereceipt'); $this->addRowAction('updatereceipt');
$this->addRowAction('changestate');
$this->addRowAction('edit');
$this->addRowAction('view');
$this->addRowAction('details');
// test if a filter is applied for this list // test if a filter is applied for this list
if (Tools::isSubmit('submitFilter'.$this->table) || $this->context->cookie->{'submitFilter'.$this->table} !== false) if (Tools::isSubmit('submitFilter'.$this->table) || $this->context->cookie->{'submitFilter'.$this->table} !== false)
@@ -474,7 +477,8 @@ class AdminSupplierOrdersControllerCore extends AdminController
'state' => array( 'state' => array(
'title' => $this->l('State'), 'title' => $this->l('State'),
'width' => 150, 'width' => 150,
'filter_key' => 'stl!name' 'filter_key' => 'stl!name',
'color' => 'color',
), ),
'date_add' => array( 'date_add' => array(
'title' => $this->l('Creation date'), 'title' => $this->l('Creation date'),
@@ -555,14 +559,14 @@ class AdminSupplierOrdersControllerCore extends AdminController
if ($id_supplier_order <= 0) 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(); return parent::initContent();
} }
$supplier_order = new SupplierOrder($id_supplier_order); $supplier_order = new SupplierOrder($id_supplier_order);
if (!Validate::isLoadedObject($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(); return parent::initContent();
} }
@@ -1006,9 +1010,9 @@ class AdminSupplierOrdersControllerCore extends AdminController
{ {
// Checks access // Checks access
if (Tools::isSubmit('submitAddsupplier_order') && !($this->tabAccess['add'] === '1')) 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')) 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 // Global checks when add / update a supplier order
if (Tools::isSubmit('submitAddsupplier_order')) if (Tools::isSubmit('submitAddsupplier_order'))
{ {
@@ -1017,17 +1021,17 @@ class AdminSupplierOrdersControllerCore extends AdminController
// get supplier ID // get supplier ID
$id_supplier = (int)Tools::getValue('id_supplier', 0); $id_supplier = (int)Tools::getValue('id_supplier', 0);
if ($id_supplier <= 0 || !Supplier::supplierExists($id_supplier)) 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 // get warehouse id
$id_warehouse = (int)Tools::getValue('id_warehouse', 0); $id_warehouse = (int)Tools::getValue('id_warehouse', 0);
if ($id_warehouse <= 0 || !Warehouse::exists($id_warehouse)) 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 // get currency id
$id_currency = (int)Tools::getValue('id_currency', 0); $id_currency = (int)Tools::getValue('id_currency', 0);
if ($id_currency <= 0 || ( !($result = Currency::getCurrency($id_currency)) || empty($result) )) 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 // specify employee
$_POST['id_employee'] = $this->context->employee->id; $_POST['id_employee'] = $this->context->employee->id;
@@ -1048,17 +1052,17 @@ class AdminSupplierOrdersControllerCore extends AdminController
&& Tools::isSubmit('id_supplier_order_state')) && Tools::isSubmit('id_supplier_order_state'))
{ {
if ($this->tabAccess['edit'] != '1') 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 // get state ID
$id_state = (int)Tools::getValue('id_supplier_order_state', 0); $id_state = (int)Tools::getValue('id_supplier_order_state', 0);
if ($id_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 // get supplier order ID
$id_supplier_order = (int)Tools::getValue('id_supplier_order', 0); $id_supplier_order = (int)Tools::getValue('id_supplier_order', 0);
if ($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)) if (!count($this->_errors))
{ {
@@ -1074,18 +1078,27 @@ class AdminSupplierOrdersControllerCore extends AdminController
// if state is valid, change it in the order // if state is valid, change it in the order
if ($id_state == $state['id_supplier_order_state']) if ($id_state == $state['id_supplier_order_state'])
{ {
$supplier_order->id_supplier_order_state = $state['id_supplier_order_state']; // special case of validate state - check if there are products in the order
if ($supplier_order->save()) 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; $supplier_order->id_supplier_order_state = $state['id_supplier_order_state'];
$redirect = self::$currentIndex.'&token='.$token; if ($supplier_order->save())
Tools::redirectAdmin($redirect.'&conf=5'); {
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
$redirect = self::$currentIndex.'&token='.$token;
Tools::redirectAdmin($redirect.'&conf=5');
}
} }
} }
} }
} }
else 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'); $rows = Tools::getValue('supplier_order_detailBox');
if (!$rows) 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; return;
} }
@@ -1122,7 +1135,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
// checks if there is something to update // checks if there is something to update
if (!count($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; return;
} }
@@ -1135,7 +1148,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
// checks if quantity is valid // checks if quantity is valid
// It's possible to receive more quantity than expected in case of a shipping error from the supplier // It's possible to receive more quantity than expected in case of a shipping error from the supplier
if (!Validate::isInt($quantity) || $quantity <= 0) 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 else // everything is valid : updates
{ {
// creates the history // creates the history
@@ -1156,7 +1169,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
$warehouse = new Warehouse($supplier_order->id_warehouse); $warehouse = new Warehouse($supplier_order->id_warehouse);
if (!Validate::isLoadedObject($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; return;
} }
$manager = StockManagerFactory::getManager(); $manager = StockManagerFactory::getManager();
@@ -1175,7 +1188,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
$supplier_order->save(); $supplier_order->save();
} }
else 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 = '<span style="width:20px; margin-right:5px;">'; $content = '<span style="width:20px; margin-right:5px;">';
if ($supplier_order_state->editable == false) // @TODO Decide what states are allowed if ($supplier_order_state->editable == false) // @TODO Decide what states are allowed
$content .= '<a href="#"><img src="../img/admin/tab-invoice.gif" alt="invoice" /></a>'; $content .= '<a href="#"><img src="../img/admin/pdf.gif" alt="invoice" /></a>';
else else
$content .= '-'; $content .= '-';
$content .= '</span>'; $content .= '</span>';
@@ -1627,6 +1640,19 @@ class AdminSupplierOrdersControllerCore extends AdminController
'href' => '#', 'href' => '#',
'desc' => $this->l('Save') '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; break;
case 'add': case 'add':
+6 -6
View File
@@ -1531,12 +1531,12 @@ Country:name
phone' WHERE `PREFIX_address_format`.`id_country` = 4; 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 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'), (1, 0, 1, 0, 0, 0, '#faab00'),
(2, 1, 0, 0, 0, 0, '#e7fbff'), (2, 1, 0, 0, 0, 0, '#273cff'),
(3, 0, 0, 0, 1, 0, '#ffdbfd'), (3, 0, 0, 0, 1, 0, '#ff37f5'),
(4, 0, 0, 1, 1, 0, '#ffd3d3'), (4, 0, 0, 1, 1, 0, '#ff3e33'),
(5, 0, 0, 1, 0, 1, '#d8ffd7'), (5, 0, 0, 1, 0, 1, '#00d60c'),
(6, 0, 0, 0, 0, 1, '#cccccc'); (6, 0, 0, 0, 0, 1, '#666666');
INSERT INTO `PREFIX_supplier_order_state_lang` (`id_supplier_order_state`, `id_lang`, `name`) VALUES INSERT INTO `PREFIX_supplier_order_state_lang` (`id_supplier_order_state`, `id_lang`, `name`) VALUES
(1, 1, 'creation in progress'), (1, 1, 'creation in progress'),