diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index 2524fe7b4a83e..f132459386432 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -813,6 +813,19 @@ print "\n"; print "\n"; +// warehouse_usage activation +print ''; +print ''.$langs->trans("ActivateWarehouseUsage").''; +print ''; +if ($conf->use_javascript_ajax) { + print ajax_constantonoff('STOCK_USE_WAREHOUSE_USAGE'); +} else { + $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); + print $form->selectarray("STOCK_USE_WAREHOUSE_USAGE", $arrval, $conf->global->STOCK_USE_WAREHOUSE_USAGE); +} +print "\n"; +print "\n"; + /* Disabled. Would be better to be managed with a user cookie if (isModEnabled('productbatch')) { print ''; diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index c436d911ed69b..19f68a8518212 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -337,3 +337,6 @@ LatestModifiedWarehouses=Latest %s modified warehouses LatestStockMovements=Latest %s stock movements QtyCurrentlyKnownInStock=System estimated quantity you have in stock. As long as the inventory is not closed, this is a realtime value and it may change if you continue to make stock movement during the inventory (not recommended). QtyInStockWhenInventoryWasValidated=System estimated quantity you had in stock when the inventory was validated (before the stock correction) +ActivateWarehouseUsage=Activate the option that products in a warehouse do not count towards the stock (e.g., quarantine warehouse) +WarehouseUsageCount=included in stock +WarehouseUsageNoCount=excluded from stock diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 8fa39941e4ffa..e76333aa0acec 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5877,6 +5877,9 @@ public function load_stock($option = '', $includedraftpoforvirtual = null, $date if (count($warehouseStatus)) { $sql .= " AND w.statut IN (".$this->db->sanitize(implode(',', $warehouseStatus)).")"; } + if (getDolGlobalString('STOCK_USE_WAREHOUSE_USAGE')) { + $sql .= " AND w.warehouse_usage = 1"; + } $sql .= " ORDER BY ps.reel ".(getDolGlobalString('DO_NOT_TRY_TO_DEFRAGMENT_STOCKS_WAREHOUSE') ? 'DESC' : 'ASC'); // Note : qty ASC is important for expedition card, to avoid stock fragmentation; diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index 7e2f9fb290356..324c4038186a4 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -213,6 +213,7 @@ $object->country_id = GETPOST("country_id"); $object->phone = GETPOST("phone"); $object->fax = GETPOST("fax"); + $object->warehouse_usage = GETPOST("warehouse_usage"); // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); @@ -966,6 +967,22 @@ print ''; + // warehouse usage + if (getDolGlobalString('STOCK_USE_WAREHOUSE_USAGE')) { + print ''.$langs->trans("WarehouseUsage").''; + print ''; + print ajax_combobox('warehouseusage'); + print ''; + } + // Other attributes $parameters = array('colspan' => ' colspan="3"', 'cols' => '3'); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 4994a46251920..5befcca592b9d 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -114,6 +114,11 @@ class Entrepot extends CommonObject */ public $warehouse_usage; + /** + * @var array Warehouse usage ID labels + */ + public $warehouse_usage_label; + /** * 'type' field format: * 'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]', @@ -175,7 +180,7 @@ class Entrepot extends CommonObject //'fk_user_author' =>array('type'=>'integer', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-2, 'position'=>82), 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 300), 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 301), - 'warehouse_usage' => array('type' => 'integer', 'label' => 'WarehouseUsage', 'enabled' => 'getDolGlobalInt("MAIN_FEATURES_LEVEL")', 'visible' => 1, 'position' => 400, 'default' => 1, 'arrayofkeyval' => array(1 => 'InternalWarehouse', 2 => 'ExternalWarehouse')), + 'warehouse_usage' => array('type' => 'integer', 'label' => 'WarehouseUsage', 'enabled' => 'getDolGlobalInt("STOCK_USE_WAREHOUSE_USAGE")', 'visible' => 1, 'position' => 400, 'default' => 1, 'arrayofkeyval' => array(1 => 'InternalWarehouse', 2 => 'ExternalWarehouse')), //'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000), //'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>1010), 'statut' => array('type' => 'tinyint(4)', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'position' => 500, 'css' => 'minwidth50'), @@ -203,7 +208,15 @@ class Entrepot extends CommonObject */ const STATUS_OPENEXT_ALL = 3; // TODO Implement this + /** + * Warehouse is being used for stock calculations + */ + const WAREHOUSE_COUNT = 1; + /** + * Warehouse is NOT being used for stock calculations + */ + const WAREHOUSE_NOCOUNT = 2; /** * Constructor @@ -223,6 +236,10 @@ public function __construct($db) } else { $this->labelStatus[self::STATUS_OPEN_ALL] = 'Opened'; } + $this->warehouse_usage_label[self::WAREHOUSE_COUNT] = 'WarehouseUsageCount'; + if (getDolGlobalString('STOCK_USE_WAREHOUSE_USAGE')) { + $this->warehouse_usage_label[self::WAREHOUSE_NOCOUNT] = 'WarehouseUsageNoCount'; + } } /** @@ -355,6 +372,7 @@ public function update($id, $user, $notrigger = 0) $sql .= ", fk_pays = ".((int) $this->country_id); $sql .= ", phone = '".$this->db->escape($this->phone)."'"; $sql .= ", fax = '".$this->db->escape($this->fax)."'"; + $sql .= ", warehouse_usage = '".$this->db->escape($this->warehouse_usage)."'"; $sql .= " WHERE rowid = ".((int) $id); $this->db->begin(); @@ -507,7 +525,7 @@ public function fetch($id, $ref = '') return -1; } - $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,"; + $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax, warehouse_usage,"; $sql .= " model_pdf, import_key"; $sql .= " FROM ".$this->db->prefix()."entrepot"; if ($id) { @@ -539,6 +557,7 @@ public function fetch($id, $ref = '') $this->country_id = $obj->country_id; $this->phone = $obj->phone; $this->fax = $obj->fax; + $this->warehouse_usage= $obj->warehouse_usage; $this->model_pdf = $obj->model_pdf; $this->import_key = $obj->import_key;