26require_once DOL_DOCUMENT_ROOT.
'/core/modules/member/modules_member.class.php';
38 public $version =
'dolibarr';
45 public $prefix =
'MEM';
55 public $name =
'Advanced';
60 public $code_auto = 1;
68 public function info($langs)
71 return $langs->trans(
"AdvancedNumRefModelDesc", $this->prefix);
82 return $this->prefix.
"2301-0001";
95 global $conf, $langs, $db;
100 $posindice = strlen($this->prefix) + 6;
101 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
102 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent";
103 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
104 $sql .=
" AND entity = ".$conf->entity;
105 $resql = $db->query($sql);
107 $row = $db->fetch_row($resql);
109 $coyymm = substr($row[0], 0, 6);
113 if (!$coyymm || preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
116 $langs->load(
"errors");
117 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
135 $posindice = strlen($this->prefix) + 6;
136 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
137 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent";
138 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
139 $sql .=
" AND entity = ".$conf->entity;
141 $resql = $db->query($sql);
143 $obj = $db->fetch_object($resql);
145 $max = intval($obj->max);
150 dol_syslog(
"mod_member_advanced::getNextValue", LOG_DEBUG);
154 $date = empty($object->datec) ?
dol_now() : $object->datec;
158 if ($max >= (pow(10, 4) - 1)) {
161 $num = sprintf(
"%04s", $max + 1);
164 dol_syslog(
"mod_member_advanced::getNextValue return ".$this->prefix.$yymm.
"-".$num, LOG_INFO);
165 return $this->prefix.$yymm.
"-".$num;
Classe mere des modeles de numerotation des references de members.
Class to manage the numbering module Advanced for member references.
info($langs)
Return description of numbering module.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
getExample()
Return an example of numbering module values.
getNextValue($objsoc, $object)
Return next value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.