From 769c6b9cbd548c4e8d499fa9944dd384bbd564fe Mon Sep 17 00:00:00 2001 From: evarisk-micka Date: Thu, 11 Apr 2024 12:03:45 +0200 Subject: [PATCH] #903 [NumberingModule] add: custom numbering module from native dolibarr --- core/modules/saturne/modules_saturne.php | 47 +++++++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/core/modules/saturne/modules_saturne.php b/core/modules/saturne/modules_saturne.php index d2620c2a..976505df 100644 --- a/core/modules/saturne/modules_saturne.php +++ b/core/modules/saturne/modules_saturne.php @@ -226,9 +226,10 @@ abstract class CustomModeleNumRefSaturne extends ModeleNumRefSaturne /** * Return description of module * - * @return string Texte descripif + * @param String $mode Either "standard" for normal prefix or "custom" + * @return String Descriptive text */ - public function info(): string + public function info($mode = 'standard'): string { global $conf, $langs, $db, $moduleNameLowerCase; @@ -238,8 +239,21 @@ public function info(): string $form = new Form($db); $className = get_class($this); - $modName = str_replace('mod_', '', $className); - $confName = strtoupper($moduleNameLowerCase . '_' . $modName . '_ADDON'); + if ($mode == 'custom') { + $modName = explode('_', $className); + $type = dol_strtoupper($modName[1]); + $confName = strtoupper(dol_strtoupper($moduleNameLowerCase) . '_' . $type . '_CUSTOM_ADDON'); + + $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities(ucfirst($modName[1])), $langs->transnoentities(ucfirst($modName[1]))); + $tooltip .= $langs->trans("GenericMaskCodes2"); + $tooltip .= $langs->trans("GenericMaskCodes3"); + $tooltip .= $langs->trans("GenericMaskCodes5"); + } else { + $modName = str_replace('mod_', '', $className); + $confName = strtoupper($moduleNameLowerCase . '_' . $modName . '_ADDON'); + + $tooltip = $langs->trans("SaturneGenericMaskCodes"); + } $texte = $langs->trans('GenericNumRefModelDesc')."
\n"; $texte .= '
'; @@ -248,8 +262,6 @@ public function info(): string $texte .= ''; $texte .= ''; - $tooltip = $langs->trans("SaturneGenericMaskCodes"); - // Parametrage du prefix $texte .= ''; $texte .= ''; @@ -341,6 +353,29 @@ public function getNextValue(object $object): string return $this->prefix . $num; } + /** + * Return next custom value + * + * @return string Value if OK, 0 if KO + */ + public function getNextCustomValue(object $object): string + { + global $conf, $db, $moduleNameUpperCase; + + $type = dol_strtoupper($object->element); + $mask = getDolGlobalString($moduleNameUpperCase . '_' . $type . '_CUSTOM_ADDON'); + + if (dol_strlen($mask) <= 0) { + $this->error = 'NotConfigured'; + return 0; + } + + $date = (empty($object->date_c) ? (empty($object->date_creation) ? dol_now() : $object->date_creation) : $object->date_c); + $ret = get_next_value($db, $mask, $object->table_element, 'ref', '', (is_object($object) ? $object : ''), $date, 'next', false, null, $conf->entity); + + return $ret; + } + /** * Set prefix and suffix for custom value *
'.$langs->trans("Mask").':'.$form->textwithpicto('', $tooltip, 1, 1).'