85 global $conf, $langs, $db;
87 $coyymm =
''; $max =
'';
89 $posindice = strlen($this->prefix) + 6;
90 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
91 $sql .=
" FROM ".MAIN_DB_PREFIX.
"stocktransfer_stocktransfer";
92 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
93 if ($object->ismultientitymanaged == 1) {
94 $sql .=
" AND entity = ".$conf->entity;
95 } elseif ($object->ismultientitymanaged == 2) {
99 $resql = $db->query($sql);
101 $row = $db->fetch_row($resql);
102 if ($row) { $coyymm = substr($row[0], 0, 6); $max = $row[0]; }
104 if ($coyymm && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
105 $langs->load(
"errors");
106 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
124 $posindice = strlen($this->prefix) + 6;
125 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
126 $sql .=
" FROM ".MAIN_DB_PREFIX.
"stocktransfer_stocktransfer";
127 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
128 if ($object->ismultientitymanaged == 1) {
129 $sql .=
" AND entity = ".$conf->entity;
130 } elseif ($object->ismultientitymanaged == 2) {
134 $resql = $db->query($sql);
136 $obj = $db->fetch_object($resql);
137 if ($obj) $max = intval($obj->max);
140 dol_syslog(
"mod_stocktransfer_standard::getNextValue", LOG_DEBUG);
145 $date = $object->date_creation;
146 $yymm = strftime(
"%y%m", $date);
148 if ($max >= (pow(10, 4) - 1)) $num = $max + 1;
149 else $num = sprintf(
"%04s", $max + 1);
151 dol_syslog(
"mod_stocktransfer_standard::getNextValue return ".$this->prefix.$yymm.
"-".$num);
152 return $this->prefix.$yymm.
"-".$num;