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(
"GenericMaskCodes2b").
'<br>';
105 $tooltip .= $langs->trans(
"GenericMaskCodes3");
107 $tooltip .= $langs->trans(
"GenericMaskCodes4b");
108 $tooltip .= $langs->trans(
"GenericMaskCodes5");
112 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"CustomerCodeModel").
'):</td>';
113 $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,
'', 0, 3,
'tooltipelephantcutomer').
'</td>';
115 $texte .=
'<td class="left" rowspan="2"> <input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.$langs->trans(
"Modify").
'"'.$disabled.
'></td>';
120 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"SupplierCodeModel").
'):</td>';
121 $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,
'', 0, 3,
'tooltipelephantsupplier').
'</td>';
127 if (!empty($datedb)) {
128 if (!is_numeric($datedb) && GETPOSTISSET(
'value3')) {
131 $res =
dolibarr_set_const($this->db,
'COMPANY_ELEPHANT_DATE_START', $dateinput,
'chaine', 0,
'',
$conf->entity);
136 $dateinput = $datedb;
139 if (empty($dateinput)) {
142 $texte .=
'<tr><td>';
143 $texte .= $form->textwithpicto($langs->trans(
"DateStartThatModel"), $langs->trans(
"DateStartThatModelHelp")).
'</td>';
144 $texte .=
'<td class="nowraponall right">';
145 $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;"/>';
146 $texte .=
'<div style="display: none;" id="elephantchoosedate">';
147 $texte .= $form->selectDate($dateinput,
'value3', 0, 0, 1,
'', 1, 0, $disabled ? 1 : 0);
153 $texte .=
'</table>';
168 public function getExample($langs =
null, $objsoc =
'', $type = -1)
171 $langs = $GLOBALS[
'langs'];
172 '@phan-var-force Translate $langs';
178 "ErrorCantUseRazIfNoYearInMask",
179 "ErrorCantUseRazInStartedYearIfNoYearMonthInMask",
180 "ErrorCounterMustHaveMoreThan3Digits",
181 "ErrorBadMaskBadRazMonth",
182 "ErrorCantUseRazWithYearOnOneDigit",
185 $cssforerror = (
getDolGlobalString(
'SOCIETE_CODECLIENT_ADDON') ==
'mod_codeclient_elephant' ?
'error' :
'opacitymedium');
189 if (!$examplecust && ($cssforerror ==
'error' || $this->error !=
'NotConfigured')) {
190 $langs->load(
"errors");
191 $examplecust =
'<span class="'.$cssforerror.
'">'.$langs->trans(
'ErrorBadMask').
'</span>';
193 if (in_array($examplecust, $errmsg)) {
194 $langs->load(
"errors");
195 $examplecust =
'<span class="'.$cssforerror.
'">'.$langs->trans($examplecust).
'</span>';
200 if (!$examplesup && ($cssforerror ==
'error' || $this->error !=
'NotConfigured')) {
201 $langs->load(
"errors");
202 $examplesup =
'<span class="'.$cssforerror.
'">'.$langs->trans(
'ErrorBadMask').
'</span>';
204 if (in_array($examplesup, $errmsg)) {
205 $langs->load(
"errors");
206 $examplesup =
'<span class="'.$cssforerror.
'">'.$langs->trans($examplesup).
'</span>';
212 } elseif ($type == 1) {
215 return $examplecust.
'<br>'.$examplesup;
230 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
241 $this->error =
'NotConfigured';
248 $field =
'code_client';
250 } elseif ($type == 1) {
251 $field =
'code_fournisseur';
259 $numFinal =
get_next_value($db, $mask,
'societe', $field, $where,
'', $now);
277 if (preg_match(
'/\{pre\}/i', $mask)) {
282 if (preg_match(
'/\{pre\}/i', $mask)) {
305 public function verif($db, &$code, $soc, $type)
309 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
312 $code = strtoupper(trim($code));
317 if (empty($code) && $this->code_null && !
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) {
319 } elseif (empty($code) && (!$this->code_null ||
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED'))) {
325 $mask = !
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_CUSTOMER') ?
'' :
$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
328 $mask = !
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_SUPPLIER') ?
'' :
$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
331 $this->error =
'NotConfigured';
335 if (is_string($result)) {
336 $this->error = $result;
339 $is_dispo = $this->
verif_dispo($db, $code, $soc, $type);
340 if ($is_dispo != 0) {
346 dol_syslog(
"mod_codeclient_elephant::verif type=".$type.
" result=".$result);
364 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
366 $sql .=
" WHERE code_fournisseur = '".$db->escape($code).
"'";
368 $sql .=
" WHERE code_client = '".$db->escape($code).
"'";
371 $sql .=
" AND rowid <> ".((int) $soc->id);
373 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
375 $resql = $db->query($sql);
377 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 translations.
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=null, $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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...