From f8b92e507c6c38d8a96fc0e752cf85556d33fa06 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 28 May 2020 19:10:06 +0200 Subject: [PATCH] Clean code --- htdocs/admin/stock.php | 124 ++++++++++++------------------- htdocs/langs/en_US/stocks.lang | 6 +- htdocs/user/card.php | 6 +- htdocs/user/class/user.class.php | 22 +++--- 4 files changed, 67 insertions(+), 91 deletions(-) diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index fbe67e62e8d..238812d8a58 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -42,6 +42,7 @@ $action = GETPOST('action', 'alpha'); /* * Action */ + if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) { $code = $reg[1]; @@ -76,6 +77,7 @@ if ($action == 'warehouse') if (!$res > 0) $error++; } + /* * View */ @@ -108,6 +110,11 @@ print info_admin($langs->trans("IfYouUsePointOfSaleCheckModule")); print '
'; //} + +print '
'; +print ''; +print ''; + // Title rule for stock decrease print ''; print ''; @@ -295,14 +302,6 @@ if (!empty($conf->reception->enabled)) $found++; } -/*if (! $found) -{ - - print ''; - print ''; - print "\n"; -}*/ - print '
'.$langs->trans("NoModuleToManageStockIncrease").'
'; print '
'; @@ -403,72 +402,10 @@ if ($virtualdiffersfromphysical) print "\n"; print "\n"; print ''; + print '
'; } -print ''; -print ''; -print ''; - -$rowspan = 4; - -print ''; - -print ''; -print "\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; - -print ''; -print ''; -print '"; -print ''; -print "\n"; - -print ''; -print ''; -print '\n"; -print "\n"; - -print ''; -print ''; -print '"; -print "\n"; - -print ''; -print ''; -print '\n"; -print "\n"; -print '
".$langs->trans("RuleForWarehouse")."'.$langs->trans("Status").' 
'.$langs->trans("WarehouseAskWarehouseDuringOrder").''; -if ($conf->use_javascript_ajax) { - print ajax_constantonoff('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER'); -} else { - $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); - print $form->selectarray("WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER", $arrval, $conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER); -} -print "'; -print ''; -print '
'.$langs->trans("UserDefaultWarehouse").''; -if ($conf->use_javascript_ajax) { - print ajax_constantonoff('USER_DEFAULT_WAREHOUSE'); -} else { - $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); - print $form->selectarray("USER_DEFAULT_WAREHOUSE", $arrval, $conf->global->USER_DEFAULT_WAREHOUSE); -} -print "
'.$langs->trans("MainDefaultWarehouse").''; -print $formproduct->selectWarehouses($conf->global->MAIN_DEFAULT_WAREHOUSE, 'default_warehouse', '', 1); -print "
'.$form->textwithpicto($langs->trans("MainDefaultWarehouseUser"), $langs->trans("MainDefaultWarehouseUserDesc")).''; -if ($conf->use_javascript_ajax) { - print ajax_constantonoff('MAIN_DEFAULT_WAREHOUSE_USER'); -} else { - $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); - print $form->selectarray("MAIN_DEFAULT_WAREHOUSE_USER", $arrval, $conf->global->MAIN_DEFAULT_WAREHOUSE_USER); -} -print "
'; -print '
'; -print '
'; - print ''; print ''; @@ -477,17 +414,52 @@ print ''."\n"; print ''."\n"; print ''; -print ''; +print ''; +print '"; +print "\n"; + +print ''; +print ''; print '\n"; print "\n"; +if (! empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) { + print ''; + print ''; + print '\n"; + print "\n"; +} + +print ''; +print ''; +print '"; +print ''; +print "\n"; + print ''; print '\n"; print "\n"; print '
'.$langs->trans("Status").'
'.$langs->trans("UserWarehouseAutoCreate").''.$langs->trans("MainDefaultWarehouse").''; +print $formproduct->selectWarehouses($conf->global->MAIN_DEFAULT_WAREHOUSE, 'default_warehouse', '', 1, 0, 0, '', 0, 0, array(), 'left reposition'); +print ''; +print "
'.$langs->trans("UserDefaultWarehouse").''; if ($conf->use_javascript_ajax) { - print ajax_constantonoff('STOCK_USERSTOCK_AUTOCREATE'); + print ajax_constantonoff('MAIN_DEFAULT_WAREHOUSE_USER', array(), null, 0, 0, 1); } else { - $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); - print $form->selectarray("STOCK_USERSTOCK_AUTOCREATE", $arrval, $conf->global->STOCK_USERSTOCK_AUTOCREATE); + $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); + print $form->selectarray("MAIN_DEFAULT_WAREHOUSE_USER", $arrval, $conf->global->MAIN_DEFAULT_WAREHOUSE_USER); } print "
'.$langs->trans("UserWarehouseAutoCreate").''; + if ($conf->use_javascript_ajax) { + print ajax_constantonoff('STOCK_USERSTOCK_AUTOCREATE'); + } else { + $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); + print $form->selectarray("STOCK_USERSTOCK_AUTOCREATE", $arrval, $conf->global->STOCK_USERSTOCK_AUTOCREATE); + } + print "
'.$langs->trans("WarehouseAskWarehouseDuringOrder").''; +if ($conf->use_javascript_ajax) { + print ajax_constantonoff('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER'); +} else { + $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); + print $form->selectarray("WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER", $arrval, $conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER); +} +print "
'; print $form->textwithpicto($langs->trans("StockSupportServices"), $langs->trans("StockSupportServicesDesc")); @@ -527,6 +499,8 @@ print "
'; +print ''; + /* print '
'; if ($conf->global->MAIN_FEATURES_LEVEL >= 2) diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index de1ef0a2720..9ec13c20c4a 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -57,10 +57,10 @@ EnhancedValueOfWarehouses=Warehouses value UserWarehouseAutoCreate=Create a user warehouse automatically when creating a user AllowAddLimitStockByWarehouse=Manage also value for minimum and desired stock per pairing (product-warehouse) in addition to the value for minimum and desired stock per product RuleForWarehouse=Rule for warehouses -WarehouseAskWarehouseDuringOrder=Assign order on a warehouse -UserDefaultWarehouse=Assign a default warehouse on user +WarehouseAskWarehouseDuringOrder=Set a warehouse on Sale orders +UserDefaultWarehouse=Set a warehouse on Users DefaultWarehouseActive=Default warehouse active -MainDefaultWarehouse=Warehouse default +MainDefaultWarehouse=Default warehouse MainDefaultWarehouseUser=Use user warehouse asign default MainDefaultWarehouseUserDesc=/!\ By activating this option the gold of the creation of an article, the warehouse assigned to the user will be defined on this one. If no warehouse is defined on the user, the default warehouse is defined. IndependantSubProductStock=Product stock and subproduct stock are independent diff --git a/htdocs/user/card.php b/htdocs/user/card.php index b3a3739b2c1..c5ac2748978 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -1225,7 +1225,7 @@ if ($action == 'create' || $action == 'adduserldap') // TODO Move this into tab RH (HierarchicalResponsible must be on both tab) // Default warehouse - if (!empty($conf->stock->enabled) && !empty($conf->global->USER_DEFAULT_WAREHOUSE)) // TODO What is goal of this. How it is used ? + if (!empty($conf->stock->enabled) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) { print ''.$langs->trans("DefaultWarehouse").''; print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1); @@ -1597,7 +1597,7 @@ if ($action == 'create' || $action == 'adduserldap') print "\n"; // Default warehouse - if (!empty($conf->stock->enabled) && !empty($conf->global->USER_DEFAULT_WAREHOUSE)) // TODO What is goal of this. How it is used ? + if (!empty($conf->stock->enabled) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; $warehousestatic = new Entrepot($db); @@ -2591,7 +2591,7 @@ if ($action == 'create' || $action == 'adduserldap') // TODO Move this into tab RH (HierarchicalResponsible must be on both tab) // Default warehouse - if (!empty($conf->stock->enabled) && !empty($conf->global->USER_DEFAULT_WAREHOUSE)) // TODO What is goal of this. How it is used ? + if (!empty($conf->stock->enabled) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) { print ''.$langs->trans("DefaultWarehouse").''; print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 8b62c501294..a0263e547e9 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1174,15 +1174,7 @@ class User extends CommonObject return -5; } - // Update minor fields - $result = $this->update($user, 1, 1); - if ($result < 0) - { - $this->db->rollback(); - return -4; - } - - if (!empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) + if (! empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER) && !empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; $langs->load("stocks"); @@ -1192,7 +1184,17 @@ class User extends CommonObject $entrepot->description = $langs->trans("ThisWarehouseIsPersonalStock", $this->getFullName($langs)); $entrepot->statut = 1; $entrepot->country_id = $mysoc->country_id; - $entrepot->create($user); + $warehouseid = $entrepot->create($user); + + $this->fk_warehouse = $warehouseid; + } + + // Update minor fields + $result = $this->update($user, 1, 1); + if ($result < 0) + { + $this->db->rollback(); + return -4; } if (!$notrigger)