103 global $conf, $langs, $db;
108 $posindice = strlen($this->prefix) + 6;
109 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
110 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur";
111 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
112 $sql .=
" AND entity = ".$conf->entity;
113 $resql = $db->query($sql);
115 $row = $db->fetch_row($resql);
117 $coyymm = substr($row[0], 0, 6);
121 if (!$coyymm || preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
124 $langs->load(
"errors");
125 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
142 $posindice = strlen($this->prefix) + 6;
143 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
144 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur";
145 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
146 $sql .=
" AND entity = ".$conf->entity;
148 $resql = $db->query($sql);
150 $obj = $db->fetch_object($resql);
152 $max = intval($obj->max);
159 $date = $object->date_commande;
161 $date = $object->date;
163 $yymm = strftime(
"%y%m", $date);
165 if ($max >= (pow(10, 4) - 1)) {
168 $num = sprintf(
"%04s", $max + 1);
171 return $this->prefix.$yymm.
"-".$num;