From 73c2a7d75b94dbc4c89103751632c524fd3c81ee Mon Sep 17 00:00:00 2001 From: bMancone Date: Wed, 16 Nov 2011 14:12:58 +0000 Subject: [PATCH] // Warehouse: it is not possible to delete a warehouse of it has pending supply orders. --- admin-dev/themes/template/warehouses/view.tpl | 8 ++++-- classes/stock/StockMvt.php | 6 ++--- classes/stock/SupplyOrder.php | 27 +++++++++++++++++-- controllers/admin/AdminStockMvtController.php | 2 +- .../admin/AdminWarehousesController.php | 2 ++ 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/admin-dev/themes/template/warehouses/view.tpl b/admin-dev/themes/template/warehouses/view.tpl index 01916cbe6..2139eedea 100644 --- a/admin-dev/themes/template/warehouses/view.tpl +++ b/admin-dev/themes/template/warehouses/view.tpl @@ -39,6 +39,10 @@ {l s='Name:'} {$warehouse->name} + + {l s='Manager:'} + {$employee->lastname} {$employee->firstname} + {l s='Country:'} {if $address->country != ''}{$address->country}{else}{l s='N/D'}{/if} @@ -52,8 +56,8 @@ {$warehouse->management_type} - {l s='Manager:'} - {$employee->lastname} {$employee->firstname} + {l s='Valuation currency:'} + {$currency->name} ({$currency->sign}) {l s='Products:'} diff --git a/classes/stock/StockMvt.php b/classes/stock/StockMvt.php index eb356a827..04843da1e 100644 --- a/classes/stock/StockMvt.php +++ b/classes/stock/StockMvt.php @@ -174,9 +174,9 @@ class StockMvtCore extends ObjectModel $fields['id_stock_mvt_reason'] = (int)$this->id_stock_mvt_reason; $fields['id_order'] = (int)$this->id_order; $fields['sign'] = (int)$this->sign; - $fields['last_wa'] = (float)round($this->last_wa, 6); - $fields['current_wa'] = (float)round($this->current_wa, 6); - $fields['price_te'] = (float)round($this->price_te, 6); + $fields['last_wa'] = (float)Tools::ps_round($this->last_wa, 6); + $fields['current_wa'] = (float)Tools::ps_round($this->current_wa, 6); + $fields['price_te'] = (float)Tools::ps_round($this->price_te, 6); $fields['referer'] = (int)$this->referer; return $fields; } diff --git a/classes/stock/SupplyOrder.php b/classes/stock/SupplyOrder.php index 10b5a22e5..8adc592ce 100755 --- a/classes/stock/SupplyOrder.php +++ b/classes/stock/SupplyOrder.php @@ -365,7 +365,7 @@ class SupplyOrderCore extends ObjectModel } /** - * Historizes + * Historizes the order : its id, its state, and the employee responsible for the current action */ protected function addHistory() { @@ -381,7 +381,7 @@ class SupplyOrderCore extends ObjectModel } /** - * Removes all products ordered + * Removes all products from the order */ public function resetProducts() { @@ -390,4 +390,27 @@ class SupplyOrderCore extends ObjectModel foreach ($products as $p) $p->delete(); } + + /** + * For a given $id_warehouse, tells if it has pending supply orders + * + * @param int $id_warehouse + * @return bool + */ + public static function warehouseHasPendingOrders($id_warehouse) + { + if (!$id_warehouse) + return false; + + $query = new DbQuery(); + $query->select('COUNT(so.id_supply_order) as supply_orders'); + $query->from('supply_order so'); + $query->leftJoin('supply_order_state sos ON (so.id_supply_order_state = sos.id_supply_order_state)'); + $query->where('sos.enclosed != 1'); + $query->where('so.id_warehouse = '.(int)$id_warehouse); + + $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); + return ($res > 0); + } + } \ No newline at end of file diff --git a/controllers/admin/AdminStockMvtController.php b/controllers/admin/AdminStockMvtController.php index e4081947f..b557c58ee 100644 --- a/controllers/admin/AdminStockMvtController.php +++ b/controllers/admin/AdminStockMvtController.php @@ -101,7 +101,7 @@ class AdminStockMvtControllerCore extends AdminController 'visibility' => Shop::CONTEXT_ALL ), 'PS_STOCK_MVT_SUPPLY_ORDER' => array( - 'title' => $this->l('Default reason when incrementing stock when a supplier order is received:'), + 'title' => $this->l('Default reason when incrementing stock when a supply order is received:'), 'cast' => 'intval', 'type' => 'select', 'list' => $reasons_inc, diff --git a/controllers/admin/AdminWarehousesController.php b/controllers/admin/AdminWarehousesController.php index e27c41400..2d52fda3b 100644 --- a/controllers/admin/AdminWarehousesController.php +++ b/controllers/admin/AdminWarehousesController.php @@ -440,6 +440,8 @@ class AdminWarehousesControllerCore extends AdminController return; else if ($obj->getQuantitiesOfProducts() > 0) $this->_errors[] = $this->l('It is not possible to delete a Warehosue when there are products in it.'); + else if (SupplyOrder::warehouseHasPendingOrders($obj->id)) + $this->_errors[] = $this->l('It is not possible to delete a Warehouse if it has pending supply orders.'); else return parent::postProcess(); }