32require_once DOL_DOCUMENT_ROOT.
'/core/modules/societe/modules_societe.class.php';
41 public $name =
'Elephant';
42 public $version =
'dolibarr';
54 public $numbitcounter;
67 $this->code_modifiable = 1;
68 $this->code_modifiable_invalide = 1;
69 $this->code_modifiable_null = 1;
71 $this->prefixIsRequired = 0;
81 public function info($langs)
86 $langs->load(
"companies");
88 $disabled = ((!empty($mc->sharings[
'referent']) && $mc->sharings[
'referent'] != $conf->entity) ?
' disabled' :
'');
90 $texte = $langs->trans(
'GenericNumRefModelDesc').
"<br>\n";
91 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
92 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
93 $texte .=
'<input type="hidden" name="page_y" value="">';
94 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
95 $texte .=
'<input type="hidden" name="param1" value="COMPANY_ELEPHANT_MASK_CUSTOMER">';
96 $texte .=
'<input type="hidden" name="param2" value="COMPANY_ELEPHANT_MASK_SUPPLIER">';
97 $texte .=
'<input type="hidden" name="param3" value="COMPANY_ELEPHANT_DATE_START">';
98 $texte .=
'<input type="hidden" name="param4" value="COMPANY_ELEPHANT_DATE_START_ENABLE">';
99 $texte .=
'<table class="nobordernopadding" width="100%">';
101 $tooltip = $langs->trans(
"GenericMaskCodes", $langs->transnoentities(
"ThirdParty"), $langs->transnoentities(
"ThirdParty"));
103 $tooltip .= $langs->trans(
"GenericMaskCodes3");
104 $tooltip .= $langs->trans(
"GenericMaskCodes4b");
105 $tooltip .= $langs->trans(
"GenericMaskCodes5");
108 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"CustomerCodeModel").
'):</td>';
109 $texte .=
'<td class="right nowraponall">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value1" value="'.
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_CUSTOMER').
'"'.$disabled.
'>', $tooltip, 1, 1).
'</td>';
111 $texte .=
'<td class="left" rowspan="2"> <input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.$langs->trans(
"Modify").
'"'.$disabled.
'></td>';
116 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"SupplierCodeModel").
'):</td>';
117 $texte .=
'<td class="right nowraponall">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value2" value="'.
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_SUPPLIER').
'"'.$disabled.
'>', $tooltip, 1, 1).
'</td>';
123 if (!empty($datedb)) {
124 if (!is_numeric($datedb) && GETPOSTISSET(
'value3')) {
127 $res =
dolibarr_set_const($this->db,
'COMPANY_ELEPHANT_DATE_START', $dateinput,
'chaine', 0,
'', $conf->entity);
129 $res =
dolibarr_set_const($this->db,
'COMPANY_ELEPHANT_DATE_START',
'',
'chaine', 0,
'', $conf->entity);
132 $dateinput = $datedb;
135 if (empty($dateinput)) {
138 $texte .=
'<tr><td>';
139 $texte .= $form->textwithpicto($langs->trans(
"DateStartThatModel"), $langs->trans(
"DateStartThatModelHelp")).
'</td>';
140 $texte .=
'<td class="nowraponall right">';
141 $texte .=
'<input type="checkbox" onclick="let d=document.getElementById(\'elephantchoosedate\'); if(this.checked){d.style.cssText = \'display: block;\'}else{{d.style.cssText = \'display: none;\'}}" name="value4" value="1" style="float: left;"/>';
142 $texte .=
'<div style="display: none;" id="elephantchoosedate">';
143 $texte .= $form->selectDate($dateinput,
'value3', 0, 0, 1,
'', 1, 0, $disabled ? 1 : 0);
148 $texte .=
'</table>';
169 "ErrorCantUseRazIfNoYearInMask",
170 "ErrorCantUseRazInStartedYearIfNoYearMonthInMask",
171 "ErrorCounterMustHaveMoreThan3Digits",
172 "ErrorBadMaskBadRazMonth",
173 "ErrorCantUseRazWithYearOnOneDigit",
176 $cssforerror = (
getDolGlobalString(
'SOCIETE_CODECLIENT_ADDON') ==
'mod_codeclient_elephant' ?
'error' :
'opacitymedium');
180 if (!$examplecust && ($cssforerror ==
'error' || $this->error !=
'NotConfigured')) {
181 $langs->load(
"errors");
182 $examplecust =
'<span class="'.$cssforerror.
'">'.$langs->trans(
'ErrorBadMask').
'</span>';
184 if (in_array($examplecust, $errmsg)) {
185 $langs->load(
"errors");
186 $examplecust =
'<span class="'.$cssforerror.
'">'.$langs->trans($examplecust).
'</span>';
191 if (!$examplesup && ($cssforerror ==
'error' || $this->error !=
'NotConfigured')) {
192 $langs->load(
"errors");
193 $examplesup =
'<span class="'.$cssforerror.
'">'.$langs->trans(
'ErrorBadMask').
'</span>';
195 if (in_array($examplesup, $errmsg)) {
196 $langs->load(
"errors");
197 $examplesup =
'<span class="'.$cssforerror.
'">'.$langs->trans($examplesup).
'</span>';
203 } elseif ($type == 1) {
206 return $examplecust.
'<br>'.$examplesup;
221 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
232 $this->error =
'NotConfigured';
239 $field =
'code_client';
241 } elseif ($type == 1) {
242 $field =
'code_fournisseur';
250 $numFinal =
get_next_value($db, $mask,
'societe', $field, $where,
'', $now);
268 if (preg_match(
'/\{pre\}/i', $mask)) {
273 if (preg_match(
'/\{pre\}/i', $mask)) {
296 public function verif($db, &$code, $soc, $type)
300 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
303 $code = strtoupper(trim($code));
308 if (empty($code) && $this->code_null && !
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) {
310 } elseif (empty($code) && (!$this->code_null ||
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED'))) {
316 $mask = !
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_CUSTOMER') ?
'' : $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
319 $mask = !
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_SUPPLIER') ?
'' : $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
322 $this->error =
'NotConfigured';
326 if (is_string($result)) {
327 $this->error = $result;
330 $is_dispo = $this->
verif_dispo($db, $code, $soc, $type);
331 if ($is_dispo != 0) {
337 dol_syslog(
"mod_codeclient_elephant::verif type=".$type.
" result=".$result);
355 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
357 $sql .=
" WHERE code_fournisseur = '".$db->escape($code).
"'";
359 $sql .=
" WHERE code_client = '".$db->escape($code).
"'";
362 $sql .=
" AND rowid <> ".((int) $soc->id);
364 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
366 $resql = $db->query($sql);
368 if ($db->num_rows($resql) == 0) {
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Parent class for third parties code generators.
Class to manage third party code with elephant rule.
verif_prefixIsUsed()
Check if mask/numbering use prefix.
verif($db, &$code, $soc, $type)
Check validity of code according to its rules.
getExample($langs, $objsoc='', $type=-1)
Return an example of result returned by getNextValue.
getNextValue($objsoc='', $type=-1)
Return next value.
__construct($db)
Constructor.
info($langs)
Return description of module.
verif_dispo($db, $code, $soc, $type=0)
Indicate if the code is available or not (by another third party)
check_value($mask, $value)
Check value.
get_next_value($db, $mask, $table, $field, $where='', $objsoc='', $date='', $mode='next', $bentityon=true, $objuser=null, $forceentity=null)
Return last or next value for a mask (according to area we should not reset)
GETPOSTDATE($prefix, $hourTime='', $gm='auto')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.