33require_once DOL_DOCUMENT_ROOT.
'/core/modules/societe/modules_societe.class.php';
42 public $name =
'Elephant';
43 public $version =
'dolibarr';
55 public $numbitcounter;
68 $this->code_modifiable = 1;
69 $this->code_modifiable_invalide = 1;
70 $this->code_modifiable_null = 1;
72 $this->prefixIsRequired = 0;
82 public function info($langs)
87 $langs->load(
"companies");
89 $disabled = ((!empty($mc->sharings[
'referent']) && $mc->sharings[
'referent'] !=
$conf->entity) ?
' disabled' :
'');
91 $texte = $langs->trans(
'GenericNumRefModelDesc').
"<br>\n";
92 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
93 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
94 $texte .=
'<input type="hidden" name="page_y" value="">';
95 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
96 $texte .=
'<input type="hidden" name="param1" value="COMPANY_ELEPHANT_MASK_CUSTOMER">';
97 $texte .=
'<input type="hidden" name="param2" value="COMPANY_ELEPHANT_MASK_SUPPLIER">';
98 $texte .=
'<input type="hidden" name="param3" value="COMPANY_ELEPHANT_DATE_START">';
99 $texte .=
'<input type="hidden" name="param4" value="COMPANY_ELEPHANT_DATE_START_ENABLE">';
100 $texte .=
'<table class="nobordernopadding" width="100%">';
102 $tooltip = $langs->trans(
"GenericMaskCodes", $langs->transnoentities(
"ThirdParty"), $langs->transnoentities(
"ThirdParty"));
103 $tooltip .= $langs->trans(
"GenericMaskCodes1");
105 $tooltip .= $langs->trans(
"GenericMaskCodes2b").
'<br>';
107 $tooltip .= $langs->trans(
"GenericMaskCodes3");
109 $tooltip .= $langs->trans(
"GenericMaskCodes4b");
110 $tooltip .= $langs->trans(
"GenericMaskCodes5");
114 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"CustomerCodeModel").
'):</td>';
115 $texte .=
'<td class="nowraponall">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value1" value="'.
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_CUSTOMER').
'"'.$disabled.
'>', $tooltip, 1,
'help',
'', 0, 3,
'tooltipelephantcutomer').
'</td>';
117 $texte .=
'<td class="left" rowspan="2"> <input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.$langs->trans(
"Modify").
'"'.$disabled.
'></td>';
122 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"SupplierCodeModel").
'):</td>';
123 $texte .=
'<td class="nowraponall">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value2" value="'.
getDolGlobalString(
'COMPANY_ELEPHANT_MASK_SUPPLIER').
'"'.$disabled.
'>', $tooltip, 1,
'help',
'', 0, 3,
'tooltipelephantsupplier').
'</td>';
129 if (!empty($datedb)) {
133 $res =
dolibarr_set_const($this->db,
'COMPANY_ELEPHANT_DATE_START', $dateinput,
'chaine', 0,
'',
$conf->entity);
140 $dateinput = $datedb;
143 if (empty($dateinput)) {
147 $texte .=
'<tr><td>';
148 $texte .=
'<input type="checkbox"';
150 $texte .=
' checked="checked"';
152 $texte .=
' onclick="if (this.checked) { jQuery(\'#elephantchoosedate\').show(); } else { jQuery(\'#elephantchoosedate\').hide(); }" id="elephantdisablebefore" name="value4" value="1" class="inline-block"/>';
153 $texte .=
'<label for="elephantdisablebefore" class="small">';
154 $texte .= $form->textwithpicto($langs->trans(
"DateStartThatModel"), $langs->trans(
"DateStartThatModelHelp"));
155 $texte .=
'</label>';
157 $texte .=
'<td class="nowraponall">';
158 $texte .=
'<div class="'.($isEnabled ?
'' :
'hideobject ').
' inline-block" id="elephantchoosedate">';
159 $texte .= $form->selectDate($dateinput,
'value3', 0, 0, 1,
'', 1, 0, $disabled ? 1 : 0);
165 $texte .=
'</table>';
180 public function getExample($langs =
null, $objsoc =
'', $type = -1)
183 $langs = $GLOBALS[
'langs'];
184 '@phan-var-force Translate $langs';
190 "ErrorCantUseRazIfNoYearInMask",
191 "ErrorCantUseRazInStartedYearIfNoYearMonthInMask",
192 "ErrorCounterMustHaveMoreThan3Digits",
193 "ErrorBadMaskBadRazMonth",
194 "ErrorCantUseRazWithYearOnOneDigit",
197 $cssforerror = (
getDolGlobalString(
'SOCIETE_CODECLIENT_ADDON') ==
'mod_codeclient_elephant' ?
'error' :
'opacitymedium');
201 if (!$examplecust && ($cssforerror ==
'error' || $this->error !=
'NotConfigured')) {
202 $langs->load(
"errors");
203 $examplecust =
'<span class="'.$cssforerror.
'">'.$langs->trans(
'ErrorBadMask').
'</span>';
205 if (in_array($examplecust, $errmsg)) {
206 $langs->load(
"errors");
207 $examplecust =
'<span class="'.$cssforerror.
'">'.$langs->trans($examplecust).
'</span>';
212 if (!$examplesup && ($cssforerror ==
'error' || $this->error !=
'NotConfigured')) {
213 $langs->load(
"errors");
214 $examplesup =
'<span class="'.$cssforerror.
'">'.$langs->trans(
'ErrorBadMask').
'</span>';
216 if (in_array($examplesup, $errmsg)) {
217 $langs->load(
"errors");
218 $examplesup =
'<span class="'.$cssforerror.
'">'.$langs->trans($examplesup).
'</span>';
224 } elseif ($type == 1) {
227 return $examplecust.
'<br>'.$examplesup;
242 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
253 $this->error =
'NotConfigured';
260 $field =
'code_client';
262 } elseif ($type == 1) {
263 $field =
'code_fournisseur';
271 $numFinal =
get_next_value($db, $mask,
'societe', $field, $where,
'', $now);
289 if (preg_match(
'/\{pre\}/i', $mask)) {
294 if (preg_match(
'/\{pre\}/i', $mask)) {
317 public function verif($db, &$code, $soc, $type)
319 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
322 $code = strtoupper(trim($code));
327 if (empty($code) && $this->code_null && !
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) {
329 } elseif (empty($code) && (!$this->code_null ||
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED'))) {
341 $this->error =
'NotConfigured';
345 if (is_string($result)) {
346 $this->error = $result;
349 $is_dispo = $this->
verif_dispo($db, $code, $soc, $type);
350 if ($is_dispo != 0) {
356 dol_syslog(
"mod_codeclient_elephant::verif type=".$type.
" result=".$result);
374 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
376 $sql .=
" WHERE code_fournisseur = '".$db->escape($code).
"'";
378 $sql .=
" WHERE code_client = '".$db->escape($code).
"'";
381 $sql .=
" AND rowid <> ".((int) $soc->id);
383 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
385 $resql = $db->query($sql);
387 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, $objbookkeeping=null)
Return last or next value for a mask (according to area we should not reset)
dol_now($mode='gmt')
Return date for now.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.