84 global $conf, $langs, $db;
86 $coyymm =
''; $max =
'';
88 $posindice = strlen($this->prefix) + 6;
89 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
90 $sql .=
" FROM ".MAIN_DB_PREFIX.
"hrm_evaluation";
91 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
92 if ($object->ismultientitymanaged == 1) {
93 $sql .=
" AND entity = ".$conf->entity;
94 } elseif ($object->ismultientitymanaged == 2) {
98 $resql = $db->query($sql);
100 $row = $db->fetch_row($resql);
102 $coyymm = substr($row[0], 0, 6); $max = $row[0];
105 if ($coyymm && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
106 $langs->load(
"errors");
107 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
125 $posindice = strlen($this->prefix) + 6;
126 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
127 $sql .=
" FROM ".MAIN_DB_PREFIX.
"hrm_evaluation";
128 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
129 if ($object->ismultientitymanaged == 1) {
130 $sql .=
" AND entity = ".$conf->entity;
131 } elseif ($object->ismultientitymanaged == 2) {
135 $resql = $db->query($sql);
137 $obj = $db->fetch_object($resql);
139 $max = intval($obj->max);
144 dol_syslog(
"mod_evaluation_standard::getNextValue", LOG_DEBUG);
149 $date = $object->date_creation;
150 $yymm = strftime(
"%y%m", $date);
152 if ($max >= (pow(10, 4) - 1)) {
155 $num = sprintf(
"%04s", $max + 1);
158 dol_syslog(
"mod_evaluation_standard::getNextValue return ".$this->prefix.$yymm.
"-".$num);
159 return $this->prefix.$yymm.
"-".$num;