30require_once DOL_DOCUMENT_ROOT.
'/core/modules/product/modules_product.class.php';
39 public $name =
'Elephant';
40 public $version =
'dolibarr';
45 public $position = 50;
57 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(
"products");
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="PRODUCT_ELEPHANT_MASK_PRODUCT">';
95 $texte .=
'<input type="hidden" name="param2" value="PRODUCT_ELEPHANT_MASK_SERVICE">';
96 $texte .=
'<table class="nobordernopadding centpercent">';
98 $tooltip = $langs->trans(
"GenericMaskCodes", $langs->transnoentities(
"Product"), $langs->transnoentities(
"Product"));
99 $tooltip .= $langs->trans(
"GenericMaskCodes1");
100 $tooltip .= $langs->trans(
"GenericMaskCodes3");
101 $tooltip .= $langs->trans(
"GenericMaskCodes4c");
102 $tooltip .= $langs->trans(
"GenericMaskCodes5");
106 $texte .=
'<tr><td>'.$langs->trans(
"ProductCodeModel").
'</td>';
107 $texte .=
'<td class="right nowraponall">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value1" placeholder="'.$langs->trans(
"Mask").
'" value="'.
getDolGlobalString(
'PRODUCT_ELEPHANT_MASK_PRODUCT').
'"'.$disabled.
'>', $tooltip, 1,
'help',
'valignmiddle', 0, 3, $this->name).
'</td>';
109 $texte .=
'<td class="left" rowspan="2"> <input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.$langs->trans(
"Modify").
'"'.$disabled.
'></td>';
114 $texte .=
'<tr><td>'.$langs->trans(
"ServiceCodeModel").
'</td>';
115 $texte .=
'<td class="right nowraponall">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value2" placeholder="'.$langs->trans(
"Mask").
'" value="'.
getDolGlobalString(
'PRODUCT_ELEPHANT_MASK_SERVICE').
'"'.$disabled.
'>', $tooltip, 1,
'help',
'valignmiddle', 0, 3, $this->name).
'</td>';
118 $texte .=
'</table>';
133 public function getExample($langs =
null, $objproduct =
'', $type = -1)
136 $langs = $GLOBALS[
'langs'];
137 '@phan-var-force Translate $langs';
139 $exampleproduct = $exampleservice =
'';
141 if ($type == 0 || $type == -1) {
143 if (!$exampleproduct) {
144 $exampleproduct = $langs->trans(
'NotConfigured');
146 if ($exampleproduct ==
"ErrorBadMask") {
147 $langs->load(
"errors");
148 $exampleproduct = $langs->trans($exampleproduct);
151 if ($type == 1 || $type == -1) {
153 if (!$exampleservice) {
154 $exampleservice = $langs->trans(
'NotConfigured');
156 if ($exampleservice ==
"ErrorBadMask") {
157 $langs->load(
"errors");
158 $exampleservice = $langs->trans($exampleservice);
163 return $exampleproduct;
166 return $exampleservice;
168 return $exampleproduct.
'<br>'.$exampleservice;
182 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
193 $this->error =
'NotConfigured';
202 } elseif ($type == 1) {
215 $numFinal =
get_next_value($db, $mask,
'product', $field, $where,
'', $now);
233 if (preg_match(
'/\{pre\}/i', $mask)) {
238 if (preg_match(
'/\{pre\}/i', $mask)) {
260 public function verif($db, &$code, $product, $type)
264 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
267 $code = strtoupper(trim($code));
269 if (empty($code) && $this->code_null && !
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) {
271 } elseif (empty($code) && (!$this->code_null ||
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED'))) {
283 $this->error =
'NotConfigured';
288 if (is_string($result)) {
289 $this->error = $result;
294 dol_syslog(
"mod_codeclient_elephant::verif type=".$type.
" result=".$result);
311 $sql =
"SELECT ref FROM ".MAIN_DB_PREFIX.
"product";
312 $sql .=
" WHERE ref = '".$db->escape($code).
"'";
313 if ($product->id > 0) {
314 $sql .=
" AND rowid <> ".$product->id;
317 $resql = $db->query($sql);
319 if ($db->num_rows($resql) == 0) {
Class template for classes of numbering product.
Class to manage translations.
Class to manage product code with elephant rule.
verif_dispo($db, $code, $product)
Indicate if the code is available or not (by another third party)
__construct()
Constructor.
verif_prefixIsUsed()
Check if mask/numbering use prefix.
getExample($langs=null, $objproduct='', $type=-1)
Return an example of result returned by getNextValue.
info($langs)
Return description of module.
getNextValue($objproduct=null, $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, $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.
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.