27 require_once DOL_DOCUMENT_ROOT.
'/core/modules/delivery/modules_delivery.php';
41 public $version =
'dolibarr';
58 public $name =
'Jade';
60 public $prefix =
'BL';
71 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
81 return $this->prefix.
"0501-0001";
92 global $langs, $conf, $db;
94 $langs->load(
"bills");
100 $posindice = strlen($this->prefix) + 6;
101 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
102 $sql .=
" FROM ".MAIN_DB_PREFIX.
"delivery";
103 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
104 $sql .=
" AND entity = ".$conf->entity;
106 $resql = $db->query(
$sql);
108 $row = $db->fetch_row($resql);
110 $fayymm = substr($row[0], 0, 6);
114 if ($fayymm && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
115 $langs->load(
"errors");
116 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
135 $posindice = strlen($this->prefix) + 6;
136 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
137 $sql .=
" FROM ".MAIN_DB_PREFIX.
"delivery";
138 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
139 $sql .=
" AND entity = ".$conf->entity;
141 $resql = $db->query(
$sql);
142 dol_syslog(
"mod_delivery_jade::getNextValue", LOG_DEBUG);
144 $obj = $db->fetch_object($resql);
146 $max = intval($obj->max);
154 $date = $object->date_delivery;
158 $yymm = strftime(
"%y%m", $date);
160 if ($max >= (pow(10, 4) - 1)) {
163 $num = sprintf(
"%04s", $max + 1);
166 dol_syslog(
"mod_delivery_jade::getNextValue return ".$this->prefix.$yymm.
"-".$num);
167 return $this->prefix.$yymm.
"-".$num;