28require_once DOL_DOCUMENT_ROOT.
'/core/modules/product/modules_product.class.php';
42 public $nom =
'Elephant';
47 public $name =
'Elephant';
49 public $code_modifiable;
51 public $code_modifiable_invalide;
53 public $code_modifiable_null;
61 public $version =
'dolibarr';
70 public $numbitcounter;
72 public $prefixIsRequired;
81 $this->code_modifiable = 1;
82 $this->code_modifiable_invalide = 1;
83 $this->code_modifiable_null = 1;
85 $this->prefixIsRequired = 0;
95 public function info($langs)
100 $langs->load(
"products");
102 $disabled = ((!empty($mc->sharings[
'referent']) && $mc->sharings[
'referent'] != $conf->entity) ?
' disabled' :
'');
104 $texte = $langs->trans(
'GenericNumRefModelDesc').
"<br>\n";
105 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
106 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
107 $texte .=
'<input type="hidden" name="page_y" value="">';
108 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
109 $texte .=
'<input type="hidden" name="param1" value="PRODUCT_ELEPHANT_MASK_PRODUCT">';
110 $texte .=
'<input type="hidden" name="param2" value="PRODUCT_ELEPHANT_MASK_SERVICE">';
111 $texte .=
'<table class="nobordernopadding" width="100%">';
113 $tooltip = $langs->trans(
"GenericMaskCodes", $langs->transnoentities(
"Product"), $langs->transnoentities(
"Product"));
114 $tooltip .= $langs->trans(
"GenericMaskCodes3");
115 $tooltip .= $langs->trans(
"GenericMaskCodes4c");
116 $tooltip .= $langs->trans(
"GenericMaskCodes5");
119 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"ProductCodeModel").
'):</td>';
120 $texte .=
'<td class="right">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value1" value="'.(!empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT) ? $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT :
'').
'"'.$disabled.
'>', $tooltip, 1, 1).
'</td>';
122 $texte .=
'<td class="left" rowspan="2"> <input type="submit" class="button small reposition" name="modify" value="'.$langs->trans(
"Modify").
'"'.$disabled.
'></td>';
127 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
' ('.$langs->trans(
"ServiceCodeModel").
'):</td>';
128 $texte .=
'<td class="right">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value2" value="'.(!empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE) ? $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE :
'').
'"'.$disabled.
'>', $tooltip, 1, 1).
'</td>';
131 $texte .=
'</table>';
146 public function getExample($langs, $objproduct = 0, $type = -1)
148 $exampleproduct = $exampleservice =
'';
150 if ($type == 0 || $type == -1) {
152 if (!$exampleproduct) {
153 $exampleproduct = $langs->trans(
'NotConfigured');
155 if ($exampleproduct ==
"ErrorBadMask") {
156 $langs->load(
"errors");
157 $exampleproduct = $langs->trans($exampleproduct);
160 if ($type == 1 || $type == -1) {
162 if (!$exampleservice) {
163 $exampleservice = $langs->trans(
'NotConfigured');
165 if ($exampleservice ==
"ErrorBadMask") {
166 $langs->load(
"errors");
167 $exampleservice = $langs->trans($exampleservice);
172 return $exampleproduct;
175 return $exampleservice;
177 return $exampleproduct.
'<br>'.$exampleservice;
191 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
195 if ($type == 0 && !empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT)) {
196 $mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
197 } elseif ($type == 1 && !empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE)) {
198 $mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
202 $this->error =
'NotConfigured';
211 } elseif ($type == 1) {
220 if (!empty($conf->global->PRODUCT_ELEPHANT_ADD_WHERE)) {
221 $where =
' AND ('.dol_string_nospecial(
dol_string_unaccent($conf->global->PRODUCT_ELEPHANT_ADD_WHERE),
'_', array(
',',
'@',
'"',
"|",
";",
":")).
')';
224 $numFinal =
get_next_value($db, $mask,
'product', $field, $where,
'', $now);
241 $mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
242 if (preg_match(
'/\{pre\}/i', $mask)) {
246 $mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
247 if (preg_match(
'/\{pre\}/i', $mask)) {
269 public function verif($db, &$code, $product, $type)
273 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
276 $code = strtoupper(trim($code));
278 if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) {
280 } elseif (empty($code) && (!$this->code_null || !empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))) {
286 $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT) ?
'' : $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
289 $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE) ?
'' : $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
292 $this->error =
'NotConfigured';
297 if (is_string($result)) {
298 $this->error = $result;
303 dol_syslog(
"mod_codeclient_elephant::verif type=".$type.
" result=".$result);
320 $sql =
"SELECT ref FROM ".MAIN_DB_PREFIX.
"product";
321 $sql .=
" WHERE ref = '".$db->escape($code).
"'";
322 if ($product->id > 0) {
323 $sql .=
" AND rowid <> ".$product->id;
326 $resql = $db->query($sql);
328 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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.