From ec6fadf196a73ac8b5313a97a81437e3e71781f1 Mon Sep 17 00:00:00 2001 From: kamel Date: Fri, 9 Jul 2021 15:29:39 +0200 Subject: [PATCH 01/22] Fix hook constructCategory when several new categories is added by several modules --- htdocs/categories/class/categorie.class.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index b98cff5b3a5..3144f1f98c3 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -263,15 +263,16 @@ class Categorie extends CommonObject $parameters = array(); $reshook = $hookmanager->executeHooks('constructCategory', $parameters, $this); // Note that $action and $object may have been modified by some hooks if ($reshook >= 0 && !empty($hookmanager->resArray)) { - $mapList = $hookmanager->resArray; - $mapId = $mapList['id']; - $mapCode = $mapList['code']; - self::$MAP_ID_TO_CODE[$mapId] = $mapCode; - $this->MAP_ID[$mapCode] = $mapId; - $this->MAP_CAT_FK[$mapCode] = $mapList['cat_fk']; - $this->MAP_CAT_TABLE[$mapCode] = $mapList['cat_table']; - $this->MAP_OBJ_CLASS[$mapCode] = $mapList['obj_class']; - $this->MAP_OBJ_TABLE[$mapCode] = $mapList['obj_table']; + foreach ($hookmanager->resArray as $mapList) { + $mapId = $mapList['id']; + $mapCode = $mapList['code']; + self::$MAP_ID_TO_CODE[$mapId] = $mapCode; + $this->MAP_ID[$mapCode] = $mapId; + $this->MAP_CAT_FK[$mapCode] = $mapList['cat_fk']; + $this->MAP_CAT_TABLE[$mapCode] = $mapList['cat_table']; + $this->MAP_OBJ_CLASS[$mapCode] = $mapList['obj_class']; + $this->MAP_OBJ_TABLE[$mapCode] = $mapList['obj_table']; + } } } } From 073ace3a9e48c60d90b25717819d4b1ac3636a41 Mon Sep 17 00:00:00 2001 From: kamel Date: Fri, 9 Jul 2021 16:23:46 +0200 Subject: [PATCH 02/22] FIX get categories linked to another object type --- htdocs/categories/class/categorie.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index b98cff5b3a5..5bcfa903f75 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1497,7 +1497,7 @@ class Categorie extends CommonObject } else { $sql = "SELECT ct.fk_categorie, c.label, c.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type])." as ct, ".MAIN_DB_PREFIX."categorie as c"; - $sql .= " WHERE ct.fk_categorie = c.rowid AND ct.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])." = ".(int) $id." AND c.type = ".$this->MAP_ID[$type]; + $sql .= " WHERE ct.fk_categorie = c.rowid AND ct.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])." = ".(int) $id; $sql .= " AND c.entity IN (".getEntity('category').")"; $res = $this->db->query($sql); From 97ac547fe230d4773f295ff9d68c91f272c11e86 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Jul 2021 00:44:36 +0200 Subject: [PATCH 03/22] Fix/debug the numbering module to autocalculate a new lot. --- htdocs/core/modules/modProductBatch.class.php | 4 +- .../product_batch/mod_lot_advanced.php | 10 +- .../product_batch/mod_lot_standard.php | 27 +- .../modules/product_batch/mod_sn_advanced.php | 6 +- .../modules/product_batch/mod_sn_standard.php | 31 +- htdocs/langs/en_US/productbatch.lang | 8 +- htdocs/product/admin/product_lot.php | 287 +++++++++--------- .../product/stock/class/productlot.class.php | 2 +- 8 files changed, 198 insertions(+), 177 deletions(-) diff --git a/htdocs/core/modules/modProductBatch.class.php b/htdocs/core/modules/modProductBatch.class.php index 79529898bb0..4b508d79d7c 100644 --- a/htdocs/core/modules/modProductBatch.class.php +++ b/htdocs/core/modules/modProductBatch.class.php @@ -84,14 +84,14 @@ class modProductBatch extends DolibarrModules $this->const[$r][0] = "PRODUCTBATCH_LOT_ADDON"; $this->const[$r][1] = "chaine"; $this->const[$r][2] = "mod_lot_free"; - $this->const[$r][3] = 'Module to control product codes'; + $this->const[$r][3] = 'Module to control lot number'; $this->const[$r][4] = 0; $r++; $this->const[$r][0] = "PRODUCTBATCH_SN_ADDON"; $this->const[$r][1] = "chaine"; $this->const[$r][2] = "mod_sn_free"; - $this->const[$r][3] = 'Module to control product codes'; + $this->const[$r][3] = 'Module to control serial number'; $this->const[$r][4] = 0; $r++; diff --git a/htdocs/core/modules/product_batch/mod_lot_advanced.php b/htdocs/core/modules/product_batch/mod_lot_advanced.php index 0bbb124d14b..8ee857bfbea 100644 --- a/htdocs/core/modules/product_batch/mod_lot_advanced.php +++ b/htdocs/core/modules/product_batch/mod_lot_advanced.php @@ -128,27 +128,27 @@ class mod_lot_advanced extends ModeleNumRefBatch /** * Return next free value * - * @param Product $objprod Object product + * @param Societe $objsoc Object Societe * @param Object $object Object we need next value for * @return string Value if KO, <0 if KO */ - public function getNextValue($objprod, $object) + public function getNextValue($objsoc, $object) { global $db, $conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; // We get cursor rule - $mask = $conf->global->BATCH_ADVANCED_MASK; + $mask = $conf->global->LOT_ADVANCED_MASK; if (!$mask) { $this->error = 'NotConfigured'; return 0; } - $date = $object->date; + $date = dol_now(); - $numFinal = get_next_value($db, $mask, 'product_lot', 'ref', '', null, $date); + $numFinal = get_next_value($db, $mask, 'product_lot', 'batch', '', null, $date); return $numFinal; } diff --git a/htdocs/core/modules/product_batch/mod_lot_standard.php b/htdocs/core/modules/product_batch/mod_lot_standard.php index 0d2b5a55139..59de1965a6e 100644 --- a/htdocs/core/modules/product_batch/mod_lot_standard.php +++ b/htdocs/core/modules/product_batch/mod_lot_standard.php @@ -85,17 +85,21 @@ class mod_lot_standard extends ModeleNumRefBatch $coyymm = ''; $max = ''; $posindice = strlen($this->prefix) + 6; - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; + $sql = "SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.") AS SIGNED)) as max"; $sql .= " FROM ".MAIN_DB_PREFIX."product_lot"; - $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; + $sql .= " WHERE batch LIKE '".$db->escape($this->prefix)."____-%'"; $sql .= " AND entity = ".$conf->entity; $resql = $db->query($sql); if ($resql) { - $row = $db->fetch_row($resql); - if ($row) { $coyymm = substr($row[0], 0, 6); $max = $row[0]; } + $obj = $db->fetch_object($resql); + if ($obj) { + $max = intval($obj->max); + } else { + $max = 0; + } } - if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) { + if ($max && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $max)) { $langs->load("errors"); $this->error = $langs->trans('ErrorNumRefModel', $max); return false; @@ -117,23 +121,26 @@ class mod_lot_standard extends ModeleNumRefBatch // First, we get the max value $posindice = strlen($this->prefix) + 6; - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; + $sql = "SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.") AS SIGNED)) as max"; $sql .= " FROM ".MAIN_DB_PREFIX."product_lot"; - $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; + $sql .= " WHERE batch LIKE '".$db->escape($this->prefix)."____-%'"; $sql .= " AND entity = ".$conf->entity; $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); - if ($obj) $max = intval($obj->max); - else $max = 0; + if ($obj) { + $max = intval($obj->max); + } else { + $max = 0; + } } else { dol_syslog("mod_lot_standard::getNextValue", LOG_DEBUG); return -1; } //$date=time(); - $date = $object->date_creation; + $date = dol_now(); $yymm = strftime("%y%m", $date); if ($max >= (pow(10, 4) - 1)) $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is diff --git a/htdocs/core/modules/product_batch/mod_sn_advanced.php b/htdocs/core/modules/product_batch/mod_sn_advanced.php index 8117b9e6c6e..54c67291d9a 100644 --- a/htdocs/core/modules/product_batch/mod_sn_advanced.php +++ b/htdocs/core/modules/product_batch/mod_sn_advanced.php @@ -139,16 +139,16 @@ class mod_sn_advanced extends ModeleNumRefBatch require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; // We get cursor rule - $mask = $conf->global->BATCH_ADVANCED_MASK; + $mask = $conf->global->SN_ADVANCED_MASK; if (!$mask) { $this->error = 'NotConfigured'; return 0; } - $date = $object->date; + $date = dol_now(); - $numFinal = get_next_value($db, $mask, 'product_sn', 'ref', '', null, $date); + $numFinal = get_next_value($db, $mask, 'product_lot', 'batch', '', null, $date); return $numFinal; } diff --git a/htdocs/core/modules/product_batch/mod_sn_standard.php b/htdocs/core/modules/product_batch/mod_sn_standard.php index bef5efcd9f8..845044c39f3 100644 --- a/htdocs/core/modules/product_batch/mod_sn_standard.php +++ b/htdocs/core/modules/product_batch/mod_sn_standard.php @@ -85,17 +85,21 @@ class mod_sn_standard extends ModeleNumRefBatch $coyymm = ''; $max = ''; $posindice = strlen($this->prefix) + 6; - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; + $sql = "SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.") AS SIGNED)) as max"; $sql .= " FROM ".MAIN_DB_PREFIX."product_lot"; - $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; + $sql .= " WHERE batch LIKE '".$db->escape($this->prefix)."____-%'"; $sql .= " AND entity = ".$conf->entity; $resql = $db->query($sql); if ($resql) { - $row = $db->fetch_row($resql); - if ($row) { $coyymm = substr($row[0], 0, 6); $max = $row[0]; } + $obj = $db->fetch_object($resql); + if ($obj) { + $max = intval($obj->max); + } else { + $max = 0; + } } - if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) { + if ($max && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $max)) { $langs->load("errors"); $this->error = $langs->trans('ErrorNumRefModel', $max); return false; @@ -107,33 +111,36 @@ class mod_sn_standard extends ModeleNumRefBatch /** * Return next free value * - * @param Product $objprod Object product + * @param Societe $objsoc Object product * @param Object $object Object we need next value for * @return string Value if KO, <0 if KO */ - public function getNextValue($objprod, $object) + public function getNextValue($objsoc, $object) { global $db, $conf; // First, we get the max value $posindice = strlen($this->prefix) + 6; - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; + $sql = "SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.") AS SIGNED)) as max"; $sql .= " FROM ".MAIN_DB_PREFIX."product_lot"; - $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; + $sql .= " WHERE batch LIKE '".$db->escape($this->prefix)."____-%'"; $sql .= " AND entity = ".$conf->entity; $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); - if ($obj) $max = intval($obj->max); - else $max = 0; + if ($obj) { + $max = intval($obj->max); + } else { + $max = 0; + } } else { dol_syslog("mod_sn_standard::getNextValue", LOG_DEBUG); return -1; } //$date=time(); - $date = $object->date_creation; + $date = dol_now(); $yymm = strftime("%y%m", $date); if ($max >= (pow(10, 4) - 1)) $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is diff --git a/htdocs/langs/en_US/productbatch.lang b/htdocs/langs/en_US/productbatch.lang index 450d0285819..763af20c6b4 100644 --- a/htdocs/langs/en_US/productbatch.lang +++ b/htdocs/langs/en_US/productbatch.lang @@ -26,12 +26,10 @@ ShowLogOfMovementIfLot=Show log of movements for couple product/lot StockDetailPerBatch=Stock detail per lot SerialNumberAlreadyInUse=Serial number %s is already used for product %s TooManyQtyForSerialNumber=You can only have one product %s for serial number %s -BatchLotNumberingModules=Options for automatic generation of batch products managed by lots -BatchSerialNumberingModules=Options for automatic generation of batch products managed by serial numbers ManageLotMask=Custom mask -CustomMasks=Adds an option to define mask in the product card -LotProductTooltip=Adds an option in the product card to define a dedicated batch number mask -SNProductTooltip=Adds an option in the product card to define a dedicated serial number mask +CustomMasks=Option to define a different numbering mask for each product +BatchLotNumberingModules=Numbering rule for automatic generation of lot number +BatchSerialNumberingModules=Numbering rule for automatic generation of serial number (for products with property 1 unique lot/serial for each product) QtyToAddAfterBarcodeScan=Qty to add for each barcode/lot/serial scanned LifeTime=Life span (in days) EndOfLife=End of life diff --git a/htdocs/product/admin/product_lot.php b/htdocs/product/admin/product_lot.php index 8cafa97e077..3f4fd636de4 100644 --- a/htdocs/product/admin/product_lot.php +++ b/htdocs/product/admin/product_lot.php @@ -101,188 +101,197 @@ $head = product_lot_admin_prepare_head(); print dol_get_fiche_head($head, 'settings', $langs->trans("Batch"), -1, 'lot'); -/* - * Lot Numbering models - */ -print load_fiche_titre($langs->trans("BatchLotNumberingModules"), '', ''); +if ($conf->global->MAIN_FEATURES_LEVEL < 2) { + // The feature to define the numbering module of lot or serial is no enabled bcause it is not used anywhere in Dolibarr code: You can set it + // but the numbering module is not used. + // TODO Use it on lot creation page, when you create a lot and when the lot number is kept empty to define the lot according + // to the selected product. + print $langs->trans("NothingToSetup"); +} else { + /* + * Lot Numbering models + */ -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''."\n"; + print load_fiche_titre($langs->trans("BatchLotNumberingModules"), '', ''); -clearstatcache(); + print '
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Example").''.$langs->trans("Status").''.$langs->trans("ShortInfo").'
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''."\n"; -foreach ($dirmodels as $reldir) { - $dir = dol_buildpath($reldir."core/modules/product_batch/"); + clearstatcache(); - if (is_dir($dir)) { - $handle = opendir($dir); - if (is_resource($handle)) { - while (($file = readdir($handle)) !== false) { - if (substr($file, 0, 8) == 'mod_lot_' && substr($file, dol_strlen($file) - 3, 3) == 'php') { - $file = substr($file, 0, dol_strlen($file) - 4); + foreach ($dirmodels as $reldir) { + $dir = dol_buildpath($reldir."core/modules/product_batch/"); - require_once $dir.$file.'.php'; + if (is_dir($dir)) { + $handle = opendir($dir); + if (is_resource($handle)) { + while (($file = readdir($handle)) !== false) { + if (substr($file, 0, 8) == 'mod_lot_' && substr($file, dol_strlen($file) - 3, 3) == 'php') { + $file = substr($file, 0, dol_strlen($file) - 4); - $module = new $file($db); + require_once $dir.$file.'.php'; - // Show modules according to features level - if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; - if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; + $module = new $file($db); - if ($module->isEnabled()) { - print ''; + // Show modules according to features level + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; - // Show example of numbering model - print ''."\n"; + if ($module->isEnabled()) { + print ''; - print ''; + // Show example of numbering model + print ''."\n"; - $batch = new Productlot($db); - $batch->initAsSpecimen(); - - // Info - $htmltooltip = ''; - $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().'
'; - $nextval = $module->getNextValue($mysoc, $batch); - if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval - $htmltooltip .= ''.$langs->trans("NextValue").': '; - if ($nextval) { - if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') - $nextval = $langs->trans($nextval); - $htmltooltip .= $nextval.'
'; + print ''; + + $batch = new Productlot($db); + $batch->initAsSpecimen(); + + // Info + $htmltooltip = ''; + $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().'
'; + $nextval = $module->getNextValue($mysoc, $batch); + if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval + $htmltooltip .= ''.$langs->trans("NextValue").': '; + if ($nextval) { + if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') + $nextval = $langs->trans($nextval); + $htmltooltip .= $nextval.'
'; + } else { + $htmltooltip .= $langs->trans($module->error).'
'; + } + } + + print ''; + + print "\n"; } - - print ''; - - print "\n"; } } + closedir($handle); } - closedir($handle); } } -} -print "
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Example").''.$langs->trans("Status").''.$langs->trans("ShortInfo").'
'.$module->name."\n"; - print $module->info(); - print ''; - $tmp = $module->getExample(); - if (preg_match('/^Error/', $tmp)) print '
'.$langs->trans($tmp).'
'; - elseif ($tmp == 'NotConfigured') print $langs->trans($tmp); - else print $tmp; - print '
'.$module->name."\n"; + print $module->info(); + print ''; - if ($conf->global->PRODUCTBATCH_LOT_ADDON == $file) { - print img_picto($langs->trans("Activated"), 'switch_on'); - } else { - print ''; - print img_picto($langs->trans("Disabled"), 'switch_off'); - print ''; - } - print ''; + $tmp = $module->getExample(); + if (preg_match('/^Error/', $tmp)) print '
'.$langs->trans($tmp).'
'; + elseif ($tmp == 'NotConfigured') print $langs->trans($tmp); + else print $tmp; + print '
'; + if ($conf->global->PRODUCTBATCH_LOT_ADDON == $file) { + print img_picto($langs->trans("Activated"), 'switch_on'); } else { - $htmltooltip .= $langs->trans($module->error).'
'; + print ''; + print img_picto($langs->trans("Disabled"), 'switch_off'); + print ''; } + print '
'; + print $form->textwithpicto('', $htmltooltip, 1, 0); + print '
'; - print $form->textwithpicto('', $htmltooltip, 1, 0); - print '

\n"; + print "
\n"; -/* - * Serials Numbering models - */ + /* + * Serials Numbering models + */ -print load_fiche_titre($langs->trans("BatchSerialNumberingModules"), '', ''); + print load_fiche_titre($langs->trans("BatchSerialNumberingModules"), '', ''); -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''."\n"; + print '
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Example").''.$langs->trans("Status").''.$langs->trans("ShortInfo").'
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''."\n"; -clearstatcache(); + clearstatcache(); -foreach ($dirmodels as $reldir) { - $dir = dol_buildpath($reldir."core/modules/product_batch/"); + foreach ($dirmodels as $reldir) { + $dir = dol_buildpath($reldir."core/modules/product_batch/"); - if (is_dir($dir)) { - $handle = opendir($dir); - if (is_resource($handle)) { - while (($file = readdir($handle)) !== false) { - if (substr($file, 0, 7) == 'mod_sn_' && substr($file, dol_strlen($file) - 3, 3) == 'php') { - $file = substr($file, 0, dol_strlen($file) - 4); + if (is_dir($dir)) { + $handle = opendir($dir); + if (is_resource($handle)) { + while (($file = readdir($handle)) !== false) { + if (substr($file, 0, 7) == 'mod_sn_' && substr($file, dol_strlen($file) - 3, 3) == 'php') { + $file = substr($file, 0, dol_strlen($file) - 4); - require_once $dir.$file.'.php'; + require_once $dir.$file.'.php'; - $module = new $file($db); + $module = new $file($db); - // Show modules according to features level - if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; - if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; + // Show modules according to features level + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; - if ($module->isEnabled()) { - print ''; + if ($module->isEnabled()) { + print ''; - // Show example of numbering model - print ''."\n"; + // Show example of numbering model + print ''."\n"; - print ''; - - $batch = new Productlot($db); - $batch->initAsSpecimen(); - - // Info - $htmltooltip = ''; - $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().'
'; - $nextval = $module->getNextValue($mysoc, $batch); - if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval - $htmltooltip .= ''.$langs->trans("NextValue").': '; - if ($nextval) { - if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') - $nextval = $langs->trans($nextval); - $htmltooltip .= $nextval.'
'; + print ''; + + $batch = new Productlot($db); + $batch->initAsSpecimen(); + + // Info + $htmltooltip = ''; + $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().'
'; + $nextval = $module->getNextValue($mysoc, $batch); + if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval + $htmltooltip .= ''.$langs->trans("NextValue").': '; + if ($nextval) { + if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') + $nextval = $langs->trans($nextval); + $htmltooltip .= $nextval.'
'; + } else { + $htmltooltip .= $langs->trans($module->error).'
'; + } + } + + print ''; + + print "\n"; } - - print ''; - - print "\n"; } } + closedir($handle); } - closedir($handle); } } -} -print "
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Example").''.$langs->trans("Status").''.$langs->trans("ShortInfo").'
'.$module->name."\n"; - print $module->info(); - print '
'.$module->name."\n"; + print $module->info(); + print ''; - $tmp = $module->getExample(); - if (preg_match('/^Error/', $tmp)) print '
'.$langs->trans($tmp).'
'; - elseif ($tmp == 'NotConfigured') print $langs->trans($tmp); - else print $tmp; - print '
'; + $tmp = $module->getExample(); + if (preg_match('/^Error/', $tmp)) print '
'.$langs->trans($tmp).'
'; + elseif ($tmp == 'NotConfigured') print $langs->trans($tmp); + else print $tmp; + print '
'; - if ($conf->global->PRODUCTBATCH_SN_ADDON == $file) { - print img_picto($langs->trans("Activated"), 'switch_on'); - } else { - print ''; - print img_picto($langs->trans("Disabled"), 'switch_off'); - print ''; - } - print ''; + if ($conf->global->PRODUCTBATCH_SN_ADDON == $file) { + print img_picto($langs->trans("Activated"), 'switch_on'); } else { - $htmltooltip .= $langs->trans($module->error).'
'; + print ''; + print img_picto($langs->trans("Disabled"), 'switch_off'); + print ''; } + print '
'; + print $form->textwithpicto('', $htmltooltip, 1, 0); + print '
'; - print $form->textwithpicto('', $htmltooltip, 1, 0); - print '

\n"; + print "
\n"; +} // End of page llxFooter(); diff --git a/htdocs/product/stock/class/productlot.class.php b/htdocs/product/stock/class/productlot.class.php index 2a3b3cf2e20..52322cf4697 100644 --- a/htdocs/product/stock/class/productlot.class.php +++ b/htdocs/product/stock/class/productlot.class.php @@ -87,7 +87,7 @@ class Productlot extends CommonObject */ public $fields = array( 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'noteditable'=>1, 'notnull'=> 1, 'index'=>1, 'position'=>1, 'comment'=>'Id', 'css'=>'left'), - 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>15, 'notnull'=>1, 'index'=>1, 'searchall'=>1), + 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>5, 'notnull'=>1, 'index'=>1, 'searchall'=>1), 'batch' => array('type'=>'varchar(30)', 'label'=>'Batch', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'comment'=>'Batch', 'searchall'=>1), 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20), 'sellby' => array('type'=>'date', 'label'=>'SellByDate', 'enabled'=>'empty($conf->global->PRODUCT_DISABLE_SELLBY)?1:0', 'visible'=>5, 'position'=>60), From 2091120d77232de12b42c2482e9cf56f590b2e47 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Jul 2021 00:50:57 +0200 Subject: [PATCH 04/22] FIX #18122 --- htdocs/product/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index b1e892ae2da..9e1cf6af40c 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1628,7 +1628,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { $statutarray = array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch"), '2' => $langs->trans("ProductStatusOnSerial")); print $form->selectarray('status_batch', $statutarray, $object->status_batch); print ''; - if ($object->status_batch !== '0') { + if (!empty($object->status_batch) || !empty($conf->use_javascript_ajax)) { $langs->load("admin"); $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Batch"), $langs->transnoentities("Batch")); $tooltip .= '
'.$langs->trans("GenericMaskCodes2"); From e7b3280c172e9c3cb439ae39da27950d1de0b6b1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Jul 2021 01:12:52 +0200 Subject: [PATCH 05/22] Debug v14 with nojs --- htdocs/admin/accountant.php | 8 +- htdocs/admin/company.php | 8 +- htdocs/core/class/extrafields.class.php | 48 ++--- htdocs/core/class/html.form.class.php | 248 ++++++++++++----------- htdocs/core/tpl/extrafields_view.tpl.php | 1 - htdocs/product/card.php | 88 ++++---- htdocs/societe/card.php | 2 +- 7 files changed, 210 insertions(+), 193 deletions(-) diff --git a/htdocs/admin/accountant.php b/htdocs/admin/accountant.php index 7c82775abad..24df7e0cb68 100644 --- a/htdocs/admin/accountant.php +++ b/htdocs/admin/accountant.php @@ -99,14 +99,16 @@ print "
\n"; /** * Edit parameters */ -print "\n".''."\n"; + print ''."\n"; +} print '
'; print ''; diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index d2dac38b500..b33c0adde29 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -384,14 +384,16 @@ print "
\n"; /** * Edit parameters */ -print "\n".''."\n"; + print ''."\n"; +} print ''; print ''; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 54d812aeafb..f6a5ba93d61 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -2006,30 +2006,32 @@ class ExtraFields $collapse_display = ((isset($_COOKIE['DOLCOLLAPSE_'.$object->table_element.'_extrafields_'.$key]) || GETPOST('ignorecollapsesetup', 'int')) ? ($_COOKIE['DOLCOLLAPSE_'.$object->table_element.'_extrafields_'.$key] ? true : false) : ($extrafield_collapse_display_value == 2 ? false : true)); $extrafields_collapse_num = $this->attributes[$object->table_element]['pos'][$key].(!empty($object->id)?'_'.$object->id:''); - $out .= ''."\n"; - $out .= ''."\n"; } - $out .= ' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?'_'.$object->id:'').'").click(function(){'."\n"; - $out .= ' console.log("We click on collapse/uncollapse .trextrafields_collapse'.$extrafields_collapse_num.'");'."\n"; - $out .= ' jQuery(".trextrafields_collapse'.$extrafields_collapse_num.'").toggle(300, function(){'."\n"; - $out .= ' if (jQuery(".trextrafields_collapse'.$extrafields_collapse_num.'").is(":hidden")) {'."\n"; - $out .= ' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?'_'.$object->id:'').' '.$tagtype_dyn.' span").addClass("fa-plus-square").removeClass("fa-minus-square");'."\n"; - $out .= ' document.cookie = "DOLCOLLAPSE_'.$object->table_element.'_extrafields_'.$key.'=0; path='.$_SERVER["PHP_SELF"].'"'."\n"; - $out .= ' } else {'."\n"; - $out .= ' jQuery("#trextrafieldseparator'.$key.(!empty($object->id)?'_'.$object->id:'').' '.$tagtype_dyn.' span").addClass("fa-minus-square").removeClass("fa-plus-square");'."\n"; - $out .= ' document.cookie = "DOLCOLLAPSE_'.$object->table_element.'_extrafields_'.$key.'=1; path='.$_SERVER["PHP_SELF"].'"'."\n"; - $out .= ' }'."\n"; - $out .= ' });'."\n"; - $out .= ' });'."\n"; - $out .= '});'."\n"; - $out .= ''."\n"; } } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 048fbb0cad3..816e0a79225 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -7067,7 +7067,7 @@ class Form public static function selectArrayAjax($htmlname, $url, $id = '', $moreparam = '', $moreparamtourl = '', $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0) { global $conf, $langs; - global $delayedhtmlcontent; + global $delayedhtmlcontent; // Will be used later outside of this function // TODO Use an internal dolibarr component instead of select2 if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) { @@ -7076,68 +7076,71 @@ class Form $out = ''; - $tmpplugin = 'select2'; - $outdelayed = "\n".' - '; + }); + '; + } if ($acceptdelayedhtml) { $delayedhtmlcontent .= $outdelayed; @@ -7168,7 +7171,7 @@ class Form public static function selectArrayFilter($htmlname, $array, $id = '', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0) { global $conf, $langs; - global $delayedhtmlcontent; + global $delayedhtmlcontent; // Will be used later outside of this function // TODO Use an internal dolibarr component instead of select2 if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) { @@ -7187,74 +7190,77 @@ class Form $formattedarrayresult[] = $o; } - $tmpplugin = 'select2'; - $outdelayed = "\n".' - '; + '.($callurlonselect ? ' + /* Code to execute a GET when we select a value */ + $(".'.$htmlname.'").change(function() { + var selected = $(".'.$htmlname.'").val(); + console.log("We select "+selected) + + $(".'.$htmlname.'").val(""); /* reset visible combo value */ + $.each( saveRemoteData, function( key, value ) { + if (key == selected) + { + console.log("selectArrayFilter - Do a redirect to "+value.url) + location.assign(value.url); + } + }); + });' : '').' + + }); + '; + } if ($acceptdelayedhtml) { $delayedhtmlcontent .= $outdelayed; @@ -7297,7 +7303,7 @@ class Form } // Add code for jquery to use multiselect - if (!empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT')) { + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT')) { $out .= "\n".''; $out .= "\n".''."\n"; + print ''."\n"; + } // Load object modCodeProduct $module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard'); @@ -1551,14 +1553,16 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { //WYSIWYG Editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - print ''."\n"; + } // We set country_id, country_code and country for the selected country $object->country_id = GETPOST('country_id') ? GETPOST('country_id') : $object->country_id; @@ -1646,46 +1650,48 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { $inherited_mask_sn = getDolGlobalString('SN_ADVANCED_MASK'); print ''; print $form->textwithpicto('', $tooltip, 1, 1); - - print ''; + '; + } print ''; } } diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 76ae78fdb51..b62c277cdf2 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -1859,7 +1859,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { $sub2 = 1; } - if ($conf->use_javascript_ajax) { + if (!empty($conf->use_javascript_ajax)) { print "\n".'