28require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
38 public $name =
'Mars';
43 public $position = 30;
49 public $version =
'dolibarr';
51 public $prefixinvoice =
'FA';
53 public $prefixreplacement =
'FR';
55 public $prefixdeposit =
'AC';
57 public $prefixcreditnote =
'AV';
72 if ((
float)
$conf->global->MAIN_VERSION_LAST_INSTALL >= 16.0 && $mysoc->country_code !=
'FR') {
73 $this->prefixinvoice =
'IN';
74 $this->prefixreplacement =
'IR';
75 $this->prefixdeposit =
'ID';
76 $this->prefixcreditnote =
'IC';
90 public function info($langs)
93 $langs->load(
"bills");
94 return $langs->trans(
'MarsNumRefModelDesc1', $this->prefixinvoice, $this->prefixreplacement, $this->prefixdeposit, $this->prefixcreditnote);
104 return $this->prefixinvoice.
"0501-0001";
116 global $langs,
$conf, $db;
118 $langs->load(
"bills");
124 $posindice = strlen($this->prefixinvoice) + 6;
125 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED) as max";
126 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
127 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixinvoice).
"____-%'";
128 $sql .=
" AND entity = ".$conf->entity;
130 $resql = $db->query($sql);
132 $row = $db->fetch_row($resql);
134 $fayymm = substr($row[0], 0, 6);
138 if ($fayymm && !preg_match(
'/'.$this->prefixinvoice.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
139 $langs->load(
"errors");
140 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
147 $posindice = strlen($this->prefixcreditnote) + 6;
148 $sql =
"SELECT MAX(SUBSTRING(ref FROM ".$posindice.
")) as max";
149 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
150 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixcreditnote).
"____-%'";
151 $sql .=
" AND entity = ".$conf->entity;
153 $resql = $db->query($sql);
155 $row = $db->fetch_row($resql);
157 $fayymm = substr($row[0], 0, 6);
161 if ($fayymm && !preg_match(
'/'.$this->prefixcreditnote.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
162 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
181 $prefix = $this->prefixinvoice;
182 if ($invoice->type == 1) {
183 $prefix = $this->prefixreplacement;
184 } elseif ($invoice->type == 2) {
185 $prefix = $this->prefixcreditnote;
186 } elseif ($invoice->type == 3) {
187 $prefix = $this->prefixdeposit;
191 $posindice = strlen($prefix) + 6;
192 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
193 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
194 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-%'";
195 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
197 $resql = $db->query($sql);
198 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
200 $obj = $db->fetch_object($resql);
202 $max = intval($obj->max);
210 if ($mode ==
'last') {
211 if ($max >= (pow(10, 4) - 1)) {
214 $num = sprintf(
"%04d", $max);
218 $sql =
"SELECT ref as ref";
219 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
220 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-".$num.
"'";
221 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
222 $sql .=
" ORDER BY ref DESC";
224 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
225 $resql = $db->query($sql);
227 $obj = $db->fetch_object($resql);
236 } elseif ($mode ==
'next') {
237 $date = $invoice->date;
240 if ($max >= (pow(10, 4) - 1)) {
243 $num = sprintf(
"%04d", $max + 1);
246 dol_syslog(get_class($this).
"::getNextValue return ".$prefix.$yymm.
"-".$num);
247 return $prefix.$yymm.
"-".$num;
263 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...