26require_once DOL_DOCUMENT_ROOT.
'/core/modules/expensereport/modules_expensereport.php';
37 public $version =
'dolibarr';
39 public $prefix =
'ER';
56 public $name =
'Jade';
65 public function info($langs)
68 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
79 return $this->prefix.
"0501-0001";
92 global $conf, $langs, $db;
97 $posindice = strlen($this->prefix) + 6;
98 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
99 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport";
100 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
101 $sql .=
" AND entity = ".$conf->entity;
103 $resql = $db->query($sql);
105 $row = $db->fetch_row($resql);
107 $coyymm = substr($row[0], 0, 6);
111 if ($coyymm && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
112 $langs->load(
"errors");
113 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
133 if (
$object->fk_user_author > 0) {
134 $fuser =
new User($db);
135 $fuser->fetch(
$object->fk_user_author);
138 $expld_car = (!
getDolGlobalString(
'NDF_EXPLODE_CHAR')) ?
"-" : $conf->global->NDF_EXPLODE_CHAR;
139 $num_car = (!
getDolGlobalString(
'NDF_NUM_CAR_REF')) ?
"5" : $conf->global->NDF_NUM_CAR_REF;
141 $sql =
'SELECT MAX(de.ref_number_int) as max';
142 $sql .=
' FROM '.MAIN_DB_PREFIX.
'expensereport de';
144 $result = $db->query($sql);
146 if ($db->num_rows($result) > 0) {
147 $objp = $db->fetch_object($result);
148 $newref = $objp->max;
150 while (strlen($newref) < $num_car) {
151 $newref =
"0".$newref;
155 while (strlen((
string) $newref) < $num_car) {
156 $newref =
"0".$newref;
160 $ref_number_int = (int) $newref;
168 $newref = str_replace(
' ',
'_', $user_author_infos).$expld_car.$prefix.$newref.$expld_car.dol_print_date(
$object->date_debut,
'%y%m%d');
170 $sqlbis =
'UPDATE '.MAIN_DB_PREFIX.
'expensereport SET ref_number_int = '.((int) $ref_number_int).
' WHERE rowid = '.((int)
$object->id);
171 $resqlbis = $db->query($sqlbis);
177 dol_syslog(
"mod_expensereport_jade::getNextValue return ".$newref);
182 $posindice = strlen($this->prefix) + 6;
183 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
184 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport";
185 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
186 $sql .=
" AND entity = ".$conf->entity;
188 $resql = $db->query($sql);
190 $obj = $db->fetch_object($resql);
192 $max = intval($obj->max);
197 dol_syslog(
"mod_expensereport_jade::getNextValue", LOG_DEBUG);
203 $this->error =
'Date valid not defined';
209 if ($max >= (pow(10, 4) - 1)) {
212 $num = sprintf(
"%04d", $max + 1);
215 dol_syslog(
"mod_expensereport_jade::getNextValue return ".$this->prefix.$yymm.
"-".$num);
216 return $this->prefix.$yymm.
"-".$num;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
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.