Skip to content

#903 [NumberingModule] add: custom numbering module from native dolibarr #904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions admin/object.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
$permissiontoread = $user->rights->$moduleNameLowerCase->adminpage->read;
saturne_check_access($permissiontoread);

/*
* Action
*/

// Actions set_mod, update_mask
require_once __DIR__ . '/../../saturne/core/tpl/actions/admin_conf_actions.tpl.php';

/*
* View
*/
Expand Down
49 changes: 42 additions & 7 deletions core/modules/saturne/modules_saturne.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -238,18 +239,29 @@ 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 = $modName[1];
$confName = 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')."<br>\n";
$texte .= '<form action="' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleNameLowerCase . '" method="POST">';
$texte .= '<form action="' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleNameLowerCase . '&object_type=' . $type . '" method="POST">';
$texte .= '<input type="hidden" name="token" value="'.newToken().'">';
$texte .= '<input type="hidden" name="action" value="update_mask">';
$texte .= '<input type="hidden" name="mask" value="'. $confName .'">';
$texte .= '<table class="nobordernopadding" width="100%">';

$tooltip = $langs->trans("SaturneGenericMaskCodes");

// Parametrage du prefix
$texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
$texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="addon_value" value="'.$conf->global->$confName.'">', $tooltip, 1, 1).'</td>';
Expand Down Expand Up @@ -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, $moduleName;

$type = dol_strtoupper($object->element);
$mask = getDolGlobalString(dol_strtoupper($moduleName) . '_' . $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
*
Expand Down
2 changes: 1 addition & 1 deletion core/tpl/actions/admin_conf_actions.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
} else {
dolibarr_set_const($db, $documentMaskConst, $documentMask, 'chaine', 0, '', $conf->entity);
setEventMessage('SavedConfig');
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName);
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '&object_type=' . $objectType);
exit;
}
}