85 global $conf, $langs, $db;
90 $posindice = strlen($this->prefix) + 6;
91 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
92 $sql .=
" FROM ".MAIN_DB_PREFIX.
"asset_asset";
93 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
94 if ($object->ismultientitymanaged == 1) {
95 $sql .=
" AND entity = ".$conf->entity;
96 } elseif ($object->ismultientitymanaged == 2) {
100 $resql = $db->query($sql);
102 $row = $db->fetch_row($resql);
104 $coyymm = substr($row[0], 0, 6); $max = $row[0];
107 if ($coyymm && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
108 $langs->load(
"errors");
109 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
127 $posindice = strlen($this->prefix) + 6;
128 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
129 $sql .=
" FROM ".MAIN_DB_PREFIX.
"asset";
130 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
131 if ($object->ismultientitymanaged == 1) {
132 $sql .=
" AND entity = ".$conf->entity;
133 } elseif ($object->ismultientitymanaged == 2) {
137 $resql = $db->query($sql);
139 $obj = $db->fetch_object($resql);
141 $max = intval($obj->max);
146 dol_syslog(
"mod_asset_standard::getNextValue", LOG_DEBUG);
151 $date = $object->date_creation;
152 $yymm = strftime(
"%y%m", $date);
154 if ($max >= (pow(10, 4) - 1)) {
157 $num = sprintf(
"%04s", $max + 1);
160 dol_syslog(
"mod_asset_standard::getNextValue return ".$this->prefix.$yymm.
"-".$num);
161 return $this->prefix.$yymm.
"-".$num;