88 global $langs, $conf, $db;
90 $langs->load(
"bills");
95 $posindice = strlen($this->prefix) + 6;
96 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
97 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter";
98 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
99 $sql .=
" WHERE entity = ".$conf->entity;
101 $resql = $db->query($sql);
103 $row = $db->fetch_row($resql);
105 $fayymm = substr($row[0], 0, 6);
109 if (!$fayymm || preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
112 $langs->load(
"errors");
113 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
130 $posindice = strlen($this->prefix) + 6;
131 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
132 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter";
133 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
134 $sql .=
" AND entity = ".$conf->entity;
136 $resql = $db->query($sql);
138 $obj = $db->fetch_object($resql);
140 $max = intval($obj->max);
147 $date = $object->datec;
148 $yymm = strftime(
"%y%m", $date);
150 if ($max >= (pow(10, 4) - 1)) {
153 $num = sprintf(
"%04s", $max + 1);
156 return $this->prefix.$yymm.
"-".$num;