25 require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
37 public $version =
'dolibarr';
43 public $prefixinvoice =
'FA';
49 public $prefixreplacement =
'FA';
55 public $prefixcreditnote =
'AV';
61 public $prefixdeposit =
'AC';
76 if ((
float) $conf->global->MAIN_VERSION_LAST_INSTALL >= 16.0 && $mysoc->country_code !=
'FR') {
77 $this->prefixinvoice =
'IN';
78 $this->prefixreplacement =
'IR';
79 $this->prefixdeposit =
'ID';
80 $this->prefixcreditnote =
'IC';
83 if (!empty($conf->global->INVOICE_NUMBERING_TERRE_FORCE_PREFIX)) {
84 $this->prefixinvoice = $conf->global->INVOICE_NUMBERING_TERRE_FORCE_PREFIX;
96 $langs->load(
"bills");
97 return $langs->trans(
'TerreNumRefModelDesc1', $this->prefixinvoice, $this->prefixcreditnote, $this->prefixdeposit);
107 return $this->prefixinvoice.
"0501-0001";
118 global $langs, $conf, $db;
120 $langs->load(
"bills");
126 $posindice = strlen($this->prefixinvoice) + 6;
127 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
128 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
129 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixinvoice).
"____-%'";
130 $sql .=
" AND entity = ".$conf->entity;
132 $resql = $db->query($sql);
134 $row = $db->fetch_row(
$resql);
136 $fayymm = substr($row[0], 0, 6);
140 if ($fayymm && !preg_match(
'/'.$this->prefixinvoice.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
141 $langs->load(
"errors");
142 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
149 $posindice = strlen($this->prefixcreditnote) + 6;
150 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
151 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
152 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixcreditnote).
"____-%'";
153 $sql .=
" AND entity = ".$conf->entity;
155 $resql = $db->query($sql);
157 $row = $db->fetch_row(
$resql);
159 $fayymm = substr($row[0], 0, 6);
163 if ($fayymm && !preg_match(
'/'.$this->prefixcreditnote.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
164 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
171 $posindice = strlen($this->prefixdeposit) + 6;
172 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
173 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
174 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixdeposit).
"____-%'";
175 $sql .=
" AND entity = ".$conf->entity;
177 $resql = $db->query($sql);
179 $row = $db->fetch_row(
$resql);
181 $fayymm = substr($row[0], 0, 6);
185 if ($fayymm && !preg_match(
'/'.$this->prefixdeposit.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
186 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
208 dol_syslog(get_class($this).
"::getNextValue mode=".$mode, LOG_DEBUG);
210 $prefix = $this->prefixinvoice;
211 if ($invoice->type == 2) {
212 $prefix = $this->prefixcreditnote;
213 } elseif ($invoice->type == 3) {
214 $prefix = $this->prefixdeposit;
218 $posindice = strlen($prefix) + 6;
219 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
220 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
221 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-%'";
222 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
224 $resql = $db->query($sql);
226 $obj = $db->fetch_object(
$resql);
228 $max = intval($obj->max);
236 if ($mode ==
'last') {
237 if ($max >= (pow(10, 4) - 1)) {
240 $num = sprintf(
"%04s", $max);
244 $sql =
"SELECT ref as ref";
245 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
246 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-".$num.
"'";
247 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
248 $sql .=
" ORDER BY ref DESC";
250 $resql = $db->query($sql);
252 $obj = $db->fetch_object(
$resql);
261 } elseif ($mode ==
'next') {
262 $date = $invoice->date;
263 $yymm = strftime(
"%y%m", $date);
265 if ($max >= (pow(10, 4) - 1)) {
268 $num = sprintf(
"%04s", $max + 1);
271 dol_syslog(get_class($this).
"::getNextValue return ".$prefix.$yymm.
"-".$num);
272 return $prefix.$yymm.
"-".$num;
288 public function getNumRef($objsoc, $objforref, $mode =
'next')
Parent class of invoice reference numbering templates.
Class of numbering module Terre for invoices.
getNextValue($objsoc, $invoice, $mode='next')
Return next value not used or last value used.
info()
Returns the description of the numbering model.
getNumRef($objsoc, $objforref, $mode='next')
Return next free value.
getExample()
Return an example of numbering.
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
__construct()
Constructor.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $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...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.