26require_once DOL_DOCUMENT_ROOT.
'/core/modules/expensereport/modules_expensereport.php';
37 public $version =
'dolibarr';
42 public $prefix =
'ER';
59 public $name =
'Jade';
68 public function info($langs)
71 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
82 return $this->prefix.
"0501-0001";
95 global
$conf, $langs, $db;
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.
"expensereport";
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 $coyymm = substr($row[0], 0, 6);
114 if ($coyymm && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
115 $langs->load(
"errors");
116 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
136 if (
$object->fk_user_author > 0) {
138 $fuser->fetch(
$object->fk_user_author);
144 $sql =
'SELECT MAX(de.ref_number_int) as max';
145 $sql .=
' FROM '.MAIN_DB_PREFIX.
'expensereport de';
147 $result =
$db->query($sql);
149 if (
$db->num_rows($result) > 0) {
150 $objp =
$db->fetch_object($result);
151 $newref = $objp->max;
153 while (strlen($newref) < $num_car) {
154 $newref =
"0".$newref;
158 while (strlen((
string) $newref) < $num_car) {
159 $newref =
"0".$newref;
163 $ref_number_int = (int) $newref;
171 $newref = str_replace(
' ',
'_', $user_author_infos).$expld_car.$prefix.$newref.$expld_car.dol_print_date(
$object->date_debut,
'%y%m%d');
173 $sqlbis =
'UPDATE '.MAIN_DB_PREFIX.
'expensereport SET ref_number_int = '.((int) $ref_number_int).
' WHERE rowid = '.((int)
$object->id);
174 $resqlbis =
$db->query($sqlbis);
180 dol_syslog(
"mod_expensereport_jade::getNextValue return ".$newref);
185 $posindice = strlen($this->prefix) + 6;
186 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
187 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport";
188 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
189 $sql .=
" AND entity = ".$conf->entity;
191 $resql =
$db->query($sql);
193 $obj =
$db->fetch_object($resql);
195 $max = intval($obj->max);
200 dol_syslog(
"mod_expensereport_jade::getNextValue", LOG_DEBUG);
206 $this->error =
'Date valid not defined';
212 if ($max >= (pow(10, 4) - 1)) {
215 $num = sprintf(
"%04d", $max + 1);
218 dol_syslog(
"mod_expensereport_jade::getNextValue return ".$this->prefix.$yymm.
"-".$num);
219 return $this->prefix.$yymm.
"-".$num;
if(! $sortfield) if(! $sortorder) $object
Parent class for numbering masks of expense reports.
Class to manage Dolibarr users.
Class to manage expensereport numbering rules Jade.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
getExample()
Returns an example of numbering.
info($langs)
Return description of numbering model.
getNextValue($object)
Return next free value.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.