diff --git a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql index 9bd984bba1b..e81027fd22f 100644 --- a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql +++ b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql @@ -149,4 +149,7 @@ ALTER TABLE llx_commande_fournisseurdet ADD COLUMN vat_src_code varchar(10) DEFA ALTER TABLE llx_propaldet ADD COLUMN vat_src_code varchar(10) DEFAULT '' AFTER tva_tx; ALTER TABLE llx_supplier_proposaldet ADD COLUMN vat_src_code varchar(10) DEFAULT '' AFTER tva_tx; - +ALTER TABLE llx_c_payment_term change fdm type_cdr tinyint; + +ALTER TABLE llx_entrepot ADD COLUMN fk_parent integer DEFAULT 0; + diff --git a/htdocs/install/mysql/tables/llx_entrepot.sql b/htdocs/install/mysql/tables/llx_entrepot.sql index a8898a7ec92..d93eb6e1575 100644 --- a/htdocs/install/mysql/tables/llx_entrepot.sql +++ b/htdocs/install/mysql/tables/llx_entrepot.sql @@ -34,5 +34,6 @@ create table llx_entrepot fk_pays integer DEFAULT 0, statut tinyint DEFAULT 1, -- 1 open, 0 close fk_user_author integer, - import_key varchar(14) + import_key varchar(14), + fk_parent integer DEFAULT 0 )ENGINE=innodb; diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 2c8d19a50c3..a3851b89339 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -62,6 +62,7 @@ ErrorCantLoadUserFromDolibarrDatabase=Failed to find user %s in Dolibarr ErrorNoVATRateDefinedForSellerCountry=Error, no vat rates defined for country '%s'. ErrorNoSocialContributionForSellerCountry=Error, no social/fiscal taxes type defined for country '%s'. ErrorFailedToSaveFile=Error, failed to save file. +ErrorCannotAddThisParentWarehouse=You are trying to add a parent warehouse which is already a child of current one NotAuthorized=You are not authorized to do that. SetDate=Set date SelectDate=Select a date diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 413e6c80088..d5fa618b1e0 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -2,6 +2,7 @@ WarehouseCard=Warehouse card Warehouse=Warehouse Warehouses=Warehouses +ParentWarehouse=Parent warehouse NewWarehouse=New warehouse / Stock area WarehouseEdit=Modify warehouse MenuNewWarehouse=New warehouse diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index cedf40678d2..d1fe225ba0e 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -56,15 +56,18 @@ class FormProduct * @param string $batch Add quantity of batch stock in label for product with batch name batch, batch name precedes batch_id. Nothing if ''. * @param int $status additional filter on status other then 1 * @param boolean $sumStock sum total stock of a warehouse, default true + * @param array $exclude warehouses ids to exclude * @return int Nb of loaded lines, 0 if already loaded, <0 if KO */ - function loadWarehouses($fk_product=0, $batch = '', $status=null, $sumStock = true) + function loadWarehouses($fk_product=0, $batch = '', $status=null, $sumStock = true, $exclude='') { global $conf, $langs; if (empty($fk_product) && count($this->cache_warehouses)) return 0; // Cache already loaded and we do not want a list with information specific to a product - - $sql = "SELECT e.rowid, e.label, e.description"; + + if (is_array($exclude)) $excludeGroups = implode("','",$exclude); + + $sql = "SELECT e.rowid, e.label, e.description, e.fk_parent"; if (!empty($fk_product)) { if (!empty($batch)) @@ -100,6 +103,8 @@ class FormProduct $sql.= " AND e.statut = 1"; } + if(!empty($exclude)) $sql.= ' AND e.rowid NOT IN('.implode(',', $exclude).')'; + if ($sumStock && empty($fk_product)) $sql.= " GROUP BY e.rowid, e.label, e.description"; $sql.= " ORDER BY e.label"; @@ -115,10 +120,17 @@ class FormProduct if ($sumStock) $obj->stock = price2num($obj->stock,5); $this->cache_warehouses[$obj->rowid]['id'] =$obj->rowid; $this->cache_warehouses[$obj->rowid]['label']=$obj->label; + $this->cache_warehouses[$obj->rowid]['parent_id']=$obj->fk_parent; $this->cache_warehouses[$obj->rowid]['description'] = $obj->description; $this->cache_warehouses[$obj->rowid]['stock'] = $obj->stock; $i++; } + + // Full label init + foreach($this->cache_warehouses as $obj_rowid=>$tab) { + $this->cache_warehouses[$obj_rowid]['full_label'] = $this->get_parent_path($tab); + } + return $num; } else @@ -127,6 +139,29 @@ class FormProduct return -1; } } + + /** + * Return full path to current warehouse in $tab (recursive function) + * + * @param array $tab warehouse data in $this->cache_warehouses line + * @param String $final_label full label with all parents, separated by ' >> ' (completed on each call) + * @return String full label with all parents, separated by ' >> ' + */ + private function get_parent_path($tab, $final_label='') { + + if(empty($final_label)) $final_label = $tab['label']; + + if(empty($tab['parent_id'])) return $final_label; + else { + if(!empty($this->cache_warehouses[$tab['parent_id']])) { + $final_label = $this->cache_warehouses[$tab['parent_id']]['label'].' >> '.$final_label; + return $this->get_parent_path($this->cache_warehouses[$tab['parent_id']], $final_label); + } + } + + return $final_label; + + } /** * Return list of warehouses @@ -142,9 +177,10 @@ class FormProduct * @param int $forcecombo force combo iso ajax select2 * @param array $events events to add to select2 * @param string $morecss Add more css classes + * @param array $exclude warehouses ids to exclude * @return string HTML select */ - function selectWarehouses($selected='',$htmlname='idwarehouse',$filtertype='',$empty=0,$disabled=0,$fk_product=0,$empty_label='', $showstock=0, $forcecombo=0, $events=array(), $morecss='minwidth200') + function selectWarehouses($selected='',$htmlname='idwarehouse',$filtertype='',$empty=0,$disabled=0,$fk_product=0,$empty_label='', $showstock=0, $forcecombo=0, $events=array(), $morecss='minwidth200', $exclude='') { global $conf,$langs,$user; @@ -152,7 +188,7 @@ class FormProduct $out=''; - $this->loadWarehouses($fk_product, '', + $filtertype); // filter on numeric status + $this->loadWarehouses($fk_product, '', + $filtertype, true, $exclude); // filter on numeric status $nbofwarehouses=count($this->cache_warehouses); if ($conf->use_javascript_ajax && ! $forcecombo) @@ -170,7 +206,7 @@ class FormProduct $out.=''; } diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index 60f7938de06..5adff357db1 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -31,10 +31,12 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; $langs->load("products"); $langs->load("stocks"); $langs->load("companies"); +$langs->load("categories"); $action=GETPOST('action'); $cancel=GETPOST('cancel'); @@ -64,6 +66,7 @@ $object = new Entrepot($db); if ($action == 'add' && $user->rights->stock->creer) { $object->ref = GETPOST("ref"); + $object->fk_parent = GETPOST("fk_parent"); $object->libelle = GETPOST("libelle"); $object->description = GETPOST("desc"); $object->statut = GETPOST("statut"); @@ -128,6 +131,7 @@ if ($action == 'update' && $cancel <> $langs->trans("Cancel")) if ($object->fetch($id)) { $object->libelle = GETPOST("libelle"); + $object->fk_parent = GETPOST("fk_parent"); $object->description = GETPOST("desc"); $object->statut = GETPOST("statut"); $object->lieu = GETPOST("lieu"); @@ -166,6 +170,7 @@ if ($cancel == $langs->trans("Cancel")) $productstatic=new Product($db); $form=new Form($db); +$formproduct=new FormProduct($db); $formcompany=new FormCompany($db); $help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; @@ -189,6 +194,11 @@ if ($action == 'create') print '