28require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
38 public $name =
'Mars';
43 public $position = 30;
49 public $version =
'dolibarr';
54 public $prefixinvoice =
'FA';
59 public $prefixreplacement =
'FR';
64 public $prefixdeposit =
'AC';
69 public $prefixcreditnote =
'AV';
84 if ((
float)
$conf->global->MAIN_VERSION_LAST_INSTALL >= 16.0 &&
$mysoc->country_code !=
'FR') {
85 $this->prefixinvoice =
'IN';
86 $this->prefixreplacement =
'IR';
87 $this->prefixdeposit =
'ID';
88 $this->prefixcreditnote =
'IC';
105 $langs->load(
"bills");
106 return $langs->trans(
'MarsNumRefModelDesc1', $this->prefixinvoice, $this->prefixreplacement, $this->prefixdeposit, $this->prefixcreditnote);
116 return $this->prefixinvoice.
"0501-0001";
128 global $langs,
$conf, $db;
130 $langs->load(
"bills");
136 $posindice = strlen($this->prefixinvoice) + 6;
137 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED) as max";
138 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
139 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixinvoice).
"____-%'";
140 $sql .=
" AND entity = ".$conf->entity;
142 $resql =
$db->query($sql);
144 $row =
$db->fetch_row($resql);
146 $fayymm = substr($row[0], 0, 6);
150 if ($fayymm && !preg_match(
'/'.$this->prefixinvoice.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
151 $langs->load(
"errors");
152 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
159 $posindice = strlen($this->prefixcreditnote) + 6;
160 $sql =
"SELECT MAX(SUBSTRING(ref FROM ".$posindice.
")) as max";
161 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
162 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixcreditnote).
"____-%'";
163 $sql .=
" AND entity = ".$conf->entity;
165 $resql =
$db->query($sql);
167 $row =
$db->fetch_row($resql);
169 $fayymm = substr($row[0], 0, 6);
173 if ($fayymm && !preg_match(
'/'.$this->prefixcreditnote.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
174 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
193 $prefix = $this->prefixinvoice;
194 if ($invoice->type == 1) {
195 $prefix = $this->prefixreplacement;
196 } elseif ($invoice->type == 2) {
197 $prefix = $this->prefixcreditnote;
198 } elseif ($invoice->type == 3) {
199 $prefix = $this->prefixdeposit;
203 $posindice = strlen($prefix) + 6;
204 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
205 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
206 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-%'";
207 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
209 $resql =
$db->query($sql);
210 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
212 $obj =
$db->fetch_object($resql);
214 $max = intval($obj->max);
222 if ($mode ==
'last') {
223 if ($max >= (pow(10, 4) - 1)) {
226 $num = sprintf(
"%04d", $max);
230 $sql =
"SELECT ref as ref";
231 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
232 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-".$num.
"'";
233 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
234 $sql .=
" ORDER BY ref DESC";
236 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
237 $resql =
$db->query($sql);
239 $obj =
$db->fetch_object($resql);
248 } elseif ($mode ==
'next') {
249 $date = $invoice->date;
252 if ($max >= (pow(10, 4) - 1)) {
255 $num = sprintf(
"%04d", $max + 1);
258 dol_syslog(get_class($this).
"::getNextValue return ".$prefix.$yymm.
"-".$num);
259 return $prefix.$yymm.
"-".$num;
275 public function getNumRef($objsoc, $objforref, $mode =
'next')
if(! $sortfield) if(! $sortorder) $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, $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.