30require_once DOL_DOCUMENT_ROOT.
'/core/modules/product/modules_product.class.php';
39 public $name =
'Elephant';
40 public $version =
'dolibarr';
52 public $numbitcounter;
61 $this->code_modifiable = 1;
62 $this->code_modifiable_invalide = 1;
63 $this->code_modifiable_null = 1;
65 $this->prefixIsRequired = 0;
75 public function info($langs)
80 $langs->load(
"products");
82 $disabled = ((!empty($mc->sharings[
'referent']) && $mc->sharings[
'referent'] !=
$conf->entity) ?
' disabled' :
'');
84 $texte = $langs->trans(
'GenericNumRefModelDesc').
"<br>\n";
85 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
86 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
87 $texte .=
'<input type="hidden" name="page_y" value="">';
88 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
89 $texte .=
'<input type="hidden" name="param1" value="PRODUCT_ELEPHANT_MASK_PRODUCT">';
90 $texte .=
'<input type="hidden" name="param2" value="PRODUCT_ELEPHANT_MASK_SERVICE">';
91 $texte .=
'<table class="nobordernopadding" width="100%">';
93 $tooltip = $langs->trans(
"GenericMaskCodes", $langs->transnoentities(
"Product"), $langs->transnoentities(
"Product"));
94 $tooltip .= $langs->trans(
"GenericMaskCodes3");
95 $tooltip .= $langs->trans(
"GenericMaskCodes4c");
96 $tooltip .= $langs->trans(
"GenericMaskCodes5");
100 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"ProductCodeModel").
'):</td>';
101 $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>';
103 $texte .=
'<td class="left" rowspan="2"> <input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.$langs->trans(
"Modify").
'"'.$disabled.
'></td>';
108 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"ServiceCodeModel").
'):</td>';
109 $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>';
112 $texte .=
'</table>';
127 public function getExample($langs =
null, $objproduct =
'', $type = -1)
130 $langs = $GLOBALS[
'langs'];
131 '@phan-var-force Translate $langs';
133 $exampleproduct = $exampleservice =
'';
135 if ($type == 0 || $type == -1) {
137 if (!$exampleproduct) {
138 $exampleproduct = $langs->trans(
'NotConfigured');
140 if ($exampleproduct ==
"ErrorBadMask") {
141 $langs->load(
"errors");
142 $exampleproduct = $langs->trans($exampleproduct);
145 if ($type == 1 || $type == -1) {
147 if (!$exampleservice) {
148 $exampleservice = $langs->trans(
'NotConfigured');
150 if ($exampleservice ==
"ErrorBadMask") {
151 $langs->load(
"errors");
152 $exampleservice = $langs->trans($exampleservice);
157 return $exampleproduct;
160 return $exampleservice;
162 return $exampleproduct.
'<br>'.$exampleservice;
176 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
187 $this->error =
'NotConfigured';
196 } elseif ($type == 1) {
206 $where =
' AND ('.dol_string_nospecial(
dol_string_unaccent(
$conf->global->PRODUCT_ELEPHANT_ADD_WHERE),
'_', array(
',',
'@',
'"',
"|",
";",
":")).
')';
209 $numFinal =
get_next_value($db, $mask,
'product', $field, $where,
'', $now);
227 if (preg_match(
'/\{pre\}/i', $mask)) {
232 if (preg_match(
'/\{pre\}/i', $mask)) {
254 public function verif($db, &$code, $product, $type)
258 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
261 $code = strtoupper(trim($code));
263 if (empty($code) && $this->code_null && !
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) {
265 } elseif (empty($code) && (!$this->code_null ||
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED'))) {
271 $mask = !
getDolGlobalString(
'PRODUCT_ELEPHANT_MASK_PRODUCT') ?
'' :
$conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
274 $mask = !
getDolGlobalString(
'PRODUCT_ELEPHANT_MASK_SERVICE') ?
'' :
$conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
277 $this->error =
'NotConfigured';
282 if (is_string($result)) {
283 $this->error = $result;
288 dol_syslog(
"mod_codeclient_elephant::verif type=".$type.
" result=".$result);
305 $sql =
"SELECT ref FROM ".MAIN_DB_PREFIX.
"product";
306 $sql .=
" WHERE ref = '".$db->escape($code).
"'";
307 if ($product->id > 0) {
308 $sql .=
" AND rowid <> ".$product->id;
311 $resql = $db->query($sql);
313 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)
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...