28require_once DOL_DOCUMENT_ROOT.
'/core/modules/product/modules_product.class.php';
41 public $nom =
'Elephant';
46 public $name =
'Elephant';
48 public $code_modifiable;
50 public $code_modifiable_invalide;
52 public $code_modifiable_null;
60 public $version =
'dolibarr';
69 public $numbitcounter;
71 public $prefixIsRequired;
80 $this->code_modifiable = 1;
81 $this->code_modifiable_invalide = 1;
82 $this->code_modifiable_null = 1;
84 $this->prefixIsRequired = 0;
94 public function info($langs)
99 $langs->load(
"products");
101 $disabled = ((!empty($mc->sharings[
'referent']) && $mc->sharings[
'referent'] != $conf->entity) ?
' disabled' :
'');
103 $texte = $langs->trans(
'GenericNumRefModelDesc').
"<br>\n";
104 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
105 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
106 $texte .=
'<input type="hidden" name="page_y" value="">';
107 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
108 $texte .=
'<input type="hidden" name="param1" value="PRODUCT_ELEPHANT_MASK_PRODUCT">';
109 $texte .=
'<input type="hidden" name="param2" value="PRODUCT_ELEPHANT_MASK_SERVICE">';
110 $texte .=
'<table class="nobordernopadding" width="100%">';
112 $tooltip = $langs->trans(
"GenericMaskCodes", $langs->transnoentities(
"Product"), $langs->transnoentities(
"Product"));
113 $tooltip .= $langs->trans(
"GenericMaskCodes3");
114 $tooltip .= $langs->trans(
"GenericMaskCodes4c");
115 $tooltip .= $langs->trans(
"GenericMaskCodes5");
118 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"ProductCodeModel").
'):</td>';
119 $texte .=
'<td class="right">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value1" value="'.(
getDolGlobalString(
'PRODUCT_ELEPHANT_MASK_PRODUCT') ? $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT :
'').
'"'.$disabled.
'>', $tooltip, 1, 1).
'</td>';
121 $texte .=
'<td class="left" rowspan="2"> <input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.$langs->trans(
"Modify").
'"'.$disabled.
'></td>';
126 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"ServiceCodeModel").
'):</td>';
127 $texte .=
'<td class="right">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value2" value="'.(
getDolGlobalString(
'PRODUCT_ELEPHANT_MASK_SERVICE') ? $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE :
'').
'"'.$disabled.
'>', $tooltip, 1, 1).
'</td>';
130 $texte .=
'</table>';
145 public function getExample($langs, $objproduct = 0, $type = -1)
147 $exampleproduct = $exampleservice =
'';
149 if ($type == 0 || $type == -1) {
151 if (!$exampleproduct) {
152 $exampleproduct = $langs->trans(
'NotConfigured');
154 if ($exampleproduct ==
"ErrorBadMask") {
155 $langs->load(
"errors");
156 $exampleproduct = $langs->trans($exampleproduct);
159 if ($type == 1 || $type == -1) {
161 if (!$exampleservice) {
162 $exampleservice = $langs->trans(
'NotConfigured');
164 if ($exampleservice ==
"ErrorBadMask") {
165 $langs->load(
"errors");
166 $exampleservice = $langs->trans($exampleservice);
171 return $exampleproduct;
174 return $exampleservice;
176 return $exampleproduct.
'<br>'.$exampleservice;
190 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
195 $mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
197 $mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
201 $this->error =
'NotConfigured';
210 } elseif ($type == 1) {
220 $where =
' AND ('.dol_string_nospecial(
dol_string_unaccent($conf->global->PRODUCT_ELEPHANT_ADD_WHERE),
'_', array(
',',
'@',
'"',
"|",
";",
":")).
')';
223 $numFinal =
get_next_value($db, $mask,
'product', $field, $where,
'', $now);
240 $mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
241 if (preg_match(
'/\{pre\}/i', $mask)) {
245 $mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
246 if (preg_match(
'/\{pre\}/i', $mask)) {
268 public function verif($db, &$code, $product, $type)
272 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
275 $code = strtoupper(trim($code));
277 if (empty($code) && $this->code_null && !
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) {
279 } elseif (empty($code) && (!$this->code_null ||
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED'))) {
285 $mask = !
getDolGlobalString(
'PRODUCT_ELEPHANT_MASK_PRODUCT') ?
'' : $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
288 $mask = !
getDolGlobalString(
'PRODUCT_ELEPHANT_MASK_SERVICE') ?
'' : $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
291 $this->error =
'NotConfigured';
296 if (is_string($result)) {
297 $this->error = $result;
302 dol_syslog(
"mod_codeclient_elephant::verif type=".$type.
" result=".$result);
319 $sql =
"SELECT ref FROM ".MAIN_DB_PREFIX.
"product";
320 $sql .=
" WHERE ref = '".$db->escape($code).
"'";
321 if ($product->id > 0) {
322 $sql .=
" AND rowid <> ".$product->id;
325 $resql = $db->query($sql);
327 if ($db->num_rows($resql) == 0) {
Class template for classes of numbering product.
Class to manage product code with elephant rule.
getExample($langs, $objproduct=0, $type=-1)
Return an example of result returned by getNextValue.
verif_dispo($db, $code, $product)
Renvoi si un code est pris ou non (par autre tiers)
__construct()
Constructor.
verif_prefixIsUsed()
Check if mask/numbering use prefix.
info($langs)
Return description of module.
getNextValue($objproduct=0, $type=-1)
Return next value.
verif($db, &$code, $product, $type)
Check validity of code according to its rules.
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.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
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.