30require_once DOL_DOCUMENT_ROOT.
'/core/modules/societe/modules_societe.class.php';
41 public $name =
'Elephant';
46 public $code_modifiable;
51 public $code_modifiable_invalide;
56 public $code_modifiable_null;
67 public $version =
'dolibarr';
82 public $numbitcounter;
87 public $prefixIsRequired;
96 $this->code_modifiable = 1;
97 $this->code_modifiable_invalide = 1;
98 $this->code_modifiable_null = 1;
100 $this->prefixIsRequired = 0;
115 $langs->load(
"companies");
117 $disabled = ((!empty($mc->sharings[
'referent']) && $mc->sharings[
'referent'] != $conf->entity) ?
' disabled' :
'');
119 $texte = $langs->trans(
'GenericNumRefModelDesc').
"<br>\n";
120 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
121 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
122 $texte .=
'<input type="hidden" name="page_y" value="">';
123 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
124 $texte .=
'<input type="hidden" name="param1" value="COMPANY_ELEPHANT_MASK_CUSTOMER">';
125 $texte .=
'<input type="hidden" name="param2" value="COMPANY_ELEPHANT_MASK_SUPPLIER">';
126 $texte .=
'<table class="nobordernopadding" width="100%">';
128 $tooltip = $langs->trans(
"GenericMaskCodes", $langs->transnoentities(
"ThirdParty"), $langs->transnoentities(
"ThirdParty"));
130 $tooltip .= $langs->trans(
"GenericMaskCodes3");
131 $tooltip .= $langs->trans(
"GenericMaskCodes4b");
132 $tooltip .= $langs->trans(
"GenericMaskCodes5");
135 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"CustomerCodeModel").
'):</td>';
136 $texte .=
'<td class="right">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value1" value="'.
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_CUSTOMER').
'"'.$disabled.
'>', $tooltip, 1, 1).
'</td>';
138 $texte .=
'<td class="left" rowspan="2"> <input type="submit" class="button button-edit reposition" name="modify" value="'.$langs->trans(
"Modify").
'"'.$disabled.
'></td>';
143 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"SupplierCodeModel").
'):</td>';
144 $texte .=
'<td class="right">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value2" value="'.
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_SUPPLIER').
'"'.$disabled.
'>', $tooltip, 1, 1).
'</td>';
147 $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>';
185 if (in_array($examplecust, $errmsg)) {
186 $langs->load(
"errors");
187 $examplecust =
'<span class="'.$cssforerror.
'">'.$langs->trans($examplecust).
'</span>';
193 if (!$examplesup && ($cssforerror ==
'error' || $this->error !=
'NotConfigured')) {
194 $langs->load(
"errors");
195 $examplesup =
'<span class="'.$cssforerror.
'">'.$langs->trans(
'ErrorBadMask').
'</span>';
198 if (in_array($examplesup, $errmsg)) {
199 $langs->load(
"errors");
200 $examplesup =
'<span class="'.$cssforerror.
'">'.$langs->trans($examplesup).
'</span>';
207 } elseif ($type == 1) {
210 return $examplecust.
'<br>'.$examplesup;
225 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
230 $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER) ?
'' : $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
233 $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER) ?
'' : $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
236 $this->error =
'NotConfigured';
243 $field =
'code_client';
245 } elseif ($type == 1) {
246 $field =
'code_fournisseur';
254 $numFinal =
get_next_value($db, $mask,
'societe', $field, $where,
'', $now);
271 $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
272 if (preg_match(
'/\{pre\}/i', $mask)) {
276 $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
277 if (preg_match(
'/\{pre\}/i', $mask)) {
300 public function verif($db, &$code, $soc, $type)
304 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
307 $code = strtoupper(trim($code));
309 if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) {
311 } elseif (empty($code) && (!$this->code_null || !empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))) {
317 $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER) ?
'' : $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
320 $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER) ?
'' : $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
323 $this->error =
'NotConfigured';
327 if (is_string($result)) {
328 $this->error = $result;
331 $is_dispo = $this->
verif_dispo($db, $code, $soc, $type);
332 if ($is_dispo <> 0) {
338 dol_syslog(
"mod_codeclient_elephant::verif type=".$type.
" result=".$result);
356 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
358 $sql .=
" WHERE code_fournisseur = '".$db->escape($code).
"'";
360 $sql .=
" WHERE code_client = '".$db->escape($code).
"'";
363 $sql .=
" AND rowid <> ".$soc->id;
365 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
367 $resql = $db->query($sql);
369 if ($db->num_rows($resql) == 0) {
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.
getNextValue($objsoc=0, $type=-1)
Return next value.
__construct()
Constructor.
info($langs)
Return description of module.
getExample($langs, $objsoc=0, $type=-1)
Return an example of result returned by getNextValue.
verif_dispo($db, $code, $soc, $type=0)
Renvoi si un code est pris ou non (par autre tiers)
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)
dol_now($mode='auto')
Return date for now.
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.