24 require_once DOL_DOCUMENT_ROOT.
'/core/modules/expensereport/modules_expensereport.php';
35 public $version =
'dolibarr';
37 public $prefix =
'ER';
54 public $name =
'Jade';
65 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
76 return $this->prefix.
"0501-0001";
88 global $conf, $langs, $db;
90 $coyymm =
''; $max =
'';
92 $posindice = strlen($this->prefix) + 6;
93 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
94 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport";
95 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
96 $sql .=
" AND entity = ".$conf->entity;
101 $row = $db->fetch_row(
$resql);
102 if ($row) { $coyymm = substr($row[0], 0, 6); $max = $row[0]; }
104 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 if (!empty($conf->global->EXPENSEREPORT_USE_OLD_NUMBERING_RULE))
128 if ($object->fk_user_author > 0)
130 $fuser =
new User($db);
131 $fuser->fetch($object->fk_user_author);
134 $expld_car = (empty($conf->global->NDF_EXPLODE_CHAR)) ?
"-" : $conf->global->NDF_EXPLODE_CHAR;
135 $num_car = (empty($conf->global->NDF_NUM_CAR_REF)) ?
"5" : $conf->global->NDF_NUM_CAR_REF;
137 $sql =
'SELECT MAX(de.ref_number_int) as max';
138 $sql .=
' FROM '.MAIN_DB_PREFIX.
'expensereport de';
140 $result = $db->query($sql);
142 if ($db->num_rows($result) > 0) {
143 $objp = $db->fetch_object($result);
144 $newref = $objp->max;
146 while (strlen($newref) < $num_car) {
147 $newref =
"0".$newref;
151 while (strlen($newref) < $num_car) {
152 $newref =
"0".$newref;
156 $ref_number_int = ($newref + 1) - 1;
161 if (!empty($conf->global->EXPENSE_REPORT_PREFIX)) $prefix = $conf->global->EXPENSE_REPORT_PREFIX;
162 $newref = str_replace(
' ',
'_', $user_author_infos).$expld_car.$prefix.$newref.$expld_car.dol_print_date($object->date_debut,
'%y%m%d');
164 $sqlbis =
'UPDATE '.MAIN_DB_PREFIX.
'expensereport SET ref_number_int = '.$ref_number_int.
' WHERE rowid = '.$object->id;
165 $resqlbis = $db->query($sqlbis);
172 dol_syslog(
"mod_expensereport_jade::getNextValue return ".$newref);
177 $posindice = strlen($this->prefix) + 6;
178 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
179 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport";
180 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
181 $sql .=
" AND entity = ".$conf->entity;
183 $resql = $db->query($sql);
186 $obj = $db->fetch_object(
$resql);
187 if ($obj) $max = intval($obj->max);
190 dol_syslog(
"mod_expensereport_jade::getNextValue", LOG_DEBUG);
194 $date = $object->date_valid;
197 $this->error =
'Date valid not defined';
201 $yymm = strftime(
"%y%m", $date);
203 if ($max >= (pow(10, 4) - 1)) $num = $max + 1;
204 else $num = sprintf(
"%04s", $max + 1);
206 dol_syslog(
"mod_expensereport_jade::getNextValue return ".$this->prefix.$yymm.
"-".$num);
207 return $this->prefix.$yymm.
"-".$num;
Class to manage expensereport numbering rules Jade.
Class to manage Dolibarr users.
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Parent class for numbering masks of expense reports.
getNextValue($object)
Return next free value.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
info()
Return description of numbering model.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
getExample()
Returns an example of numbering.