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, $objproduct = 
'', $type = -1)
 
  129    $exampleproduct = $exampleservice = 
'';
 
  131    if ($type == 0 || $type == -1) {
 
  133      if (!$exampleproduct) {
 
  134        $exampleproduct = $langs->trans(
'NotConfigured');
 
  136      if ($exampleproduct == 
"ErrorBadMask") {
 
  137        $langs->load(
"errors");
 
  138        $exampleproduct = $langs->trans($exampleproduct);
 
  141    if ($type == 1 || $type == -1) {
 
  143      if (!$exampleservice) {
 
  144        $exampleservice = $langs->trans(
'NotConfigured');
 
  146      if ($exampleservice == 
"ErrorBadMask") {
 
  147        $langs->load(
"errors");
 
  148        $exampleservice = $langs->trans($exampleservice);
 
  153      return $exampleproduct;
 
  156      return $exampleservice;
 
  158    return $exampleproduct.
'<br>'.$exampleservice;
 
 
  172    require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
 
  183      $this->error = 
'NotConfigured';
 
  192    } elseif ($type == 1) {
 
  202      $where = 
' AND ('.dol_string_nospecial(
dol_string_unaccent($conf->global->PRODUCT_ELEPHANT_ADD_WHERE), 
'_', array(
',', 
'@', 
'"', 
"|", 
";", 
":")).
')';
 
  205    $numFinal = 
get_next_value($db, $mask, 
'product', $field, $where, 
'', $now);
 
 
  223    if (preg_match(
'/\{pre\}/i', $mask)) {
 
  228    if (preg_match(
'/\{pre\}/i', $mask)) {
 
 
  250  public function verif($db, &$code, $product, $type)
 
  254    require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
 
  257    $code = strtoupper(trim($code));
 
  259    if (empty($code) && $this->code_null && !
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) {
 
  261    } elseif (empty($code) && (!$this->code_null || 
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED'))) {
 
  267        $mask = !
getDolGlobalString(
'PRODUCT_ELEPHANT_MASK_PRODUCT') ? 
'' : $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
 
  270        $mask = !
getDolGlobalString(
'PRODUCT_ELEPHANT_MASK_SERVICE') ? 
'' : $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
 
  273        $this->error = 
'NotConfigured';
 
  278      if (is_string($result)) {
 
  279        $this->error = $result;
 
  284    dol_syslog(
"mod_codeclient_elephant::verif type=".$type.
" result=".$result);
 
 
  301    $sql = 
"SELECT ref FROM ".MAIN_DB_PREFIX.
"product";
 
  302    $sql .= 
" WHERE ref = '".$db->escape($code).
"'";
 
  303    if ($product->id > 0) {
 
  304      $sql .= 
" AND rowid <> ".$product->id;
 
  307    $resql = $db->query($sql);
 
  309      if ($db->num_rows($resql) == 0) {
 
 
 
Class template for classes of numbering product.
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, $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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.