26 require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
37 public $version =
'dolibarr';
39 public $prefixinvoice =
'FA';
41 public $prefixreplacement =
'FR';
43 public $prefixdeposit =
'AC';
45 public $prefixcreditnote =
'AV';
58 if (!empty($conf->global->INVOICE_NUMBERING_MARS_FORCE_PREFIX))
60 $this->prefixinvoice = $conf->global->INVOICE_NUMBERING_MARS_FORCE_PREFIX;
72 $langs->load(
"bills");
73 return $langs->trans(
'MarsNumRefModelDesc1', $this->prefixinvoice, $this->prefixreplacement, $this->prefixdeposit, $this->prefixcreditnote);
83 return $this->prefixinvoice.
"0501-0001";
94 global $langs, $conf, $db;
96 $langs->load(
"bills");
99 $fayymm =
''; $max =
'';
101 $posindice = strlen($this->prefixinvoice) + 6;
102 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED) as max";
103 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
104 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixinvoice).
"____-%'";
105 $sql .=
" AND entity = ".$conf->entity;
107 $resql = $db->query($sql);
110 $row = $db->fetch_row(
$resql);
111 if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; }
113 if ($fayymm && !preg_match(
'/'.$this->prefixinvoice.
'[0-9][0-9][0-9][0-9]/i', $fayymm))
115 $langs->load(
"errors");
116 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
123 $posindice = strlen($this->prefixcreditnote) + 6;
124 $sql =
"SELECT MAX(SUBSTRING(ref FROM ".$posindice.
")) as max";
125 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
126 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixcreditnote).
"____-%'";
127 $sql .=
" AND entity = ".$conf->entity;
129 $resql = $db->query($sql);
132 $row = $db->fetch_row(
$resql);
133 if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; }
135 if ($fayymm && !preg_match(
'/'.$this->prefixcreditnote.
'[0-9][0-9][0-9][0-9]/i', $fayymm))
137 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
156 $prefix = $this->prefixinvoice;
157 if ($invoice->type == 1) $prefix = $this->prefixreplacement;
158 elseif ($invoice->type == 2) $prefix = $this->prefixcreditnote;
159 elseif ($invoice->type == 3) $prefix = $this->prefixdeposit;
162 $posindice = strlen($prefix) + 6;
163 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
164 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
165 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-%'";
166 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
168 $resql = $db->query($sql);
169 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
172 $obj = $db->fetch_object(
$resql);
173 if ($obj) $max = intval($obj->max);
181 if ($max >= (pow(10, 4) - 1)) $num = $max;
182 else $num = sprintf(
"%04s", $max);
185 $sql =
"SELECT ref as ref";
186 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
187 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-".$num.
"'";
188 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
189 $sql .=
" ORDER BY ref DESC";
191 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
192 $resql = $db->query($sql);
195 $obj = $db->fetch_object(
$resql);
196 if ($obj) $ref = $obj->ref;
200 } elseif ($mode ==
'next')
202 $date = $invoice->date;
203 $yymm = strftime(
"%y%m", $date);
205 if ($max >= (pow(10, 4) - 1)) $num = $max + 1;
206 else $num = sprintf(
"%04s", $max + 1);
208 dol_syslog(get_class($this).
"::getNextValue return ".$prefix.$yymm.
"-".$num);
209 return $prefix.$yymm.
"-".$num;
221 public function getNumRef($objsoc, $objforref, $mode =
'next')
getNumRef($objsoc, $objforref, $mode= 'next')
Return next free value.
Class to manage invoice numbering rules Mars.
getNextValue($objsoc, $invoice, $mode= 'next')
Return next value not used or last value used.
__construct()
Constructor.
Parent class of invoice reference numbering templates.
info()
Returns the description of the numbering model.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getExample()
Return an example of numbering.
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...
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...