31require_once DOL_DOCUMENT_ROOT.
'/core/modules/societe/modules_societe.class.php';
40 public $name =
'Elephant';
41 public $version =
'dolibarr';
53 public $numbitcounter;
66 $this->code_modifiable = 1;
67 $this->code_modifiable_invalide = 1;
68 $this->code_modifiable_null = 1;
70 $this->prefixIsRequired = 0;
80 public function info($langs)
85 $langs->load(
"companies");
87 $disabled = ((!empty($mc->sharings[
'referent']) && $mc->sharings[
'referent'] != $conf->entity) ?
' disabled' :
'');
89 $texte = $langs->trans(
'GenericNumRefModelDesc').
"<br>\n";
90 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
91 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
92 $texte .=
'<input type="hidden" name="page_y" value="">';
93 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
94 $texte .=
'<input type="hidden" name="param1" value="COMPANY_ELEPHANT_MASK_CUSTOMER">';
95 $texte .=
'<input type="hidden" name="param2" value="COMPANY_ELEPHANT_MASK_SUPPLIER">';
96 $texte .=
'<table class="nobordernopadding" width="100%">';
98 $tooltip = $langs->trans(
"GenericMaskCodes", $langs->transnoentities(
"ThirdParty"), $langs->transnoentities(
"ThirdParty"));
100 $tooltip .= $langs->trans(
"GenericMaskCodes2b").
'<br>';
102 $tooltip .= $langs->trans(
"GenericMaskCodes3");
104 $tooltip .= $langs->trans(
"GenericMaskCodes4b");
105 $tooltip .= $langs->trans(
"GenericMaskCodes5");
109 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"CustomerCodeModel").
'):</td>';
110 $texte .=
'<td class="right">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value1" value="'.
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_CUSTOMER').
'"'.$disabled.
'>', $tooltip, 1, 1,
'', 0, 3,
'tooltipelephantcutomer').
'</td>';
112 $texte .=
'<td class="left" rowspan="2"> <input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.$langs->trans(
"Modify").
'"'.$disabled.
'></td>';
117 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"SupplierCodeModel").
'):</td>';
118 $texte .=
'<td class="right">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value2" value="'.
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_SUPPLIER').
'"'.$disabled.
'>', $tooltip, 1, 1,
'', 0, 3,
'tooltipelephantsupplier').
'</td>';
121 $texte .=
'</table>';
142 "ErrorCantUseRazIfNoYearInMask",
143 "ErrorCantUseRazInStartedYearIfNoYearMonthInMask",
144 "ErrorCounterMustHaveMoreThan3Digits",
145 "ErrorBadMaskBadRazMonth",
146 "ErrorCantUseRazWithYearOnOneDigit",
149 $cssforerror = (
getDolGlobalString(
'SOCIETE_CODECLIENT_ADDON') ==
'mod_codeclient_elephant' ?
'error' :
'opacitymedium');
153 if (!$examplecust && ($cssforerror ==
'error' || $this->error !=
'NotConfigured')) {
154 $langs->load(
"errors");
155 $examplecust =
'<span class="'.$cssforerror.
'">'.$langs->trans(
'ErrorBadMask').
'</span>';
157 if (in_array($examplecust, $errmsg)) {
158 $langs->load(
"errors");
159 $examplecust =
'<span class="'.$cssforerror.
'">'.$langs->trans($examplecust).
'</span>';
164 if (!$examplesup && ($cssforerror ==
'error' || $this->error !=
'NotConfigured')) {
165 $langs->load(
"errors");
166 $examplesup =
'<span class="'.$cssforerror.
'">'.$langs->trans(
'ErrorBadMask').
'</span>';
168 if (in_array($examplesup, $errmsg)) {
169 $langs->load(
"errors");
170 $examplesup =
'<span class="'.$cssforerror.
'">'.$langs->trans($examplesup).
'</span>';
176 } elseif ($type == 1) {
179 return $examplecust.
'<br>'.$examplesup;
194 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
205 $this->error =
'NotConfigured';
212 $field =
'code_client';
214 } elseif ($type == 1) {
215 $field =
'code_fournisseur';
223 $numFinal =
get_next_value($db, $mask,
'societe', $field, $where,
'', $now);
241 if (preg_match(
'/\{pre\}/i', $mask)) {
246 if (preg_match(
'/\{pre\}/i', $mask)) {
269 public function verif($db, &$code, $soc, $type)
273 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
276 $code = strtoupper(trim($code));
278 if (empty($code) && $this->code_null && !
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) {
280 } elseif (empty($code) && (!$this->code_null ||
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED'))) {
286 $mask = !
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_CUSTOMER') ?
'' : $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
289 $mask = !
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_SUPPLIER') ?
'' : $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
292 $this->error =
'NotConfigured';
296 if (is_string($result)) {
297 $this->error = $result;
300 $is_dispo = $this->
verif_dispo($db, $code, $soc, $type);
301 if ($is_dispo != 0) {
307 dol_syslog(
"mod_codeclient_elephant::verif type=".$type.
" result=".$result);
325 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
327 $sql .=
" WHERE code_fournisseur = '".$db->escape($code).
"'";
329 $sql .=
" WHERE code_client = '".$db->escape($code).
"'";
332 $sql .=
" AND rowid <> ".$soc->id;
334 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
336 $resql = $db->query($sql);
338 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.
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)
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.