28require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
39 public $version =
'dolibarr';
41 public $prefixinvoice =
'FA';
43 public $prefixreplacement =
'FR';
45 public $prefixdeposit =
'AC';
47 public $prefixcreditnote =
'AV';
62 if ((
float) $conf->global->MAIN_VERSION_LAST_INSTALL >= 16.0 && $mysoc->country_code !=
'FR') {
63 $this->prefixinvoice =
'IN';
64 $this->prefixreplacement =
'IR';
65 $this->prefixdeposit =
'ID';
66 $this->prefixcreditnote =
'IC';
80 public function info($langs)
83 $langs->load(
"bills");
84 return $langs->trans(
'MarsNumRefModelDesc1', $this->prefixinvoice, $this->prefixreplacement, $this->prefixdeposit, $this->prefixcreditnote);
94 return $this->prefixinvoice.
"0501-0001";
106 global $langs, $conf, $db;
108 $langs->load(
"bills");
114 $posindice = strlen($this->prefixinvoice) + 6;
115 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED) as max";
116 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
117 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixinvoice).
"____-%'";
118 $sql .=
" AND entity = ".$conf->entity;
120 $resql = $db->query($sql);
122 $row = $db->fetch_row($resql);
124 $fayymm = substr($row[0], 0, 6);
128 if ($fayymm && !preg_match(
'/'.$this->prefixinvoice.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
129 $langs->load(
"errors");
130 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
137 $posindice = strlen($this->prefixcreditnote) + 6;
138 $sql =
"SELECT MAX(SUBSTRING(ref FROM ".$posindice.
")) as max";
139 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
140 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixcreditnote).
"____-%'";
141 $sql .=
" AND entity = ".$conf->entity;
143 $resql = $db->query($sql);
145 $row = $db->fetch_row($resql);
147 $fayymm = substr($row[0], 0, 6);
151 if ($fayymm && !preg_match(
'/'.$this->prefixcreditnote.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
152 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
171 $prefix = $this->prefixinvoice;
172 if ($invoice->type == 1) {
173 $prefix = $this->prefixreplacement;
174 } elseif ($invoice->type == 2) {
175 $prefix = $this->prefixcreditnote;
176 } elseif ($invoice->type == 3) {
177 $prefix = $this->prefixdeposit;
181 $posindice = strlen($prefix) + 6;
182 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
183 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
184 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-%'";
185 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
187 $resql = $db->query($sql);
188 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
190 $obj = $db->fetch_object($resql);
192 $max = intval($obj->max);
200 if ($mode ==
'last') {
201 if ($max >= (pow(10, 4) - 1)) {
204 $num = sprintf(
"%04d", $max);
208 $sql =
"SELECT ref as ref";
209 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
210 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-".$num.
"'";
211 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
212 $sql .=
" ORDER BY ref DESC";
214 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
215 $resql = $db->query($sql);
217 $obj = $db->fetch_object($resql);
226 } elseif ($mode ==
'next') {
227 $date = $invoice->date;
230 if ($max >= (pow(10, 4) - 1)) {
233 $num = sprintf(
"%04d", $max + 1);
236 dol_syslog(get_class($this).
"::getNextValue return ".$prefix.$yymm.
"-".$num);
237 return $prefix.$yymm.
"-".$num;
253 public function getNumRef($objsoc, $objforref, $mode =
'next')
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Parent class of invoice reference numbering templates.
Class to manage invoice numbering rules Mars.
getExample()
Return an example of numbering.
__construct()
Constructor.
getNextValue($objsoc, $invoice, $mode='next')
Return next value not used or last value used.
info($langs)
Returns the description of the numbering model.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
getNumRef($objsoc, $objforref, $mode='next')
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).
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.