25 require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
37 public $version =
'dolibarr';
43 public $prefixinvoice =
'FA';
49 public $prefixcreditnote =
'AV';
55 public $prefixdeposit =
'AC';
68 if (!empty($conf->global->INVOICE_NUMBERING_TERRE_FORCE_PREFIX))
70 $this->prefixinvoice = $conf->global->INVOICE_NUMBERING_TERRE_FORCE_PREFIX;
82 $langs->load(
"bills");
83 return $langs->trans(
'TerreNumRefModelDesc1', $this->prefixinvoice, $this->prefixcreditnote, $this->prefixdeposit);
93 return $this->prefixinvoice.
"0501-0001";
104 global $langs, $conf, $db;
106 $langs->load(
"bills");
109 $fayymm =
''; $max =
'';
111 $posindice = strlen($this->prefixinvoice) + 6;
112 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
113 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
114 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixinvoice).
"____-%'";
115 $sql .=
" AND entity = ".$conf->entity;
117 $resql = $db->query($sql);
120 $row = $db->fetch_row(
$resql);
121 if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; }
123 if ($fayymm && !preg_match(
'/'.$this->prefixinvoice.
'[0-9][0-9][0-9][0-9]/i', $fayymm))
125 $langs->load(
"errors");
126 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
133 $posindice = strlen($this->prefixcreditnote) + 6;
134 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
135 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
136 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixcreditnote).
"____-%'";
137 $sql .=
" AND entity = ".$conf->entity;
139 $resql = $db->query($sql);
142 $row = $db->fetch_row(
$resql);
143 if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; }
145 if ($fayymm && !preg_match(
'/'.$this->prefixcreditnote.
'[0-9][0-9][0-9][0-9]/i', $fayymm))
147 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
154 $posindice = strlen($this->prefixdeposit) + 6;
155 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
156 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
157 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixdeposit).
"____-%'";
158 $sql .=
" AND entity = ".$conf->entity;
160 $resql = $db->query($sql);
163 $row = $db->fetch_row(
$resql);
164 if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; }
166 if ($fayymm && !preg_match(
'/'.$this->prefixdeposit.
'[0-9][0-9][0-9][0-9]/i', $fayymm))
168 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
187 dol_syslog(get_class($this).
"::getNextValue mode=".$mode, LOG_DEBUG);
189 $prefix = $this->prefixinvoice;
190 if ($invoice->type == 2) $prefix = $this->prefixcreditnote;
191 elseif ($invoice->type == 3) $prefix = $this->prefixdeposit;
194 $posindice = strlen($prefix) + 6;
195 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
196 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
197 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-%'";
198 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
200 $resql = $db->query($sql);
203 $obj = $db->fetch_object(
$resql);
204 if ($obj) $max = intval($obj->max);
212 if ($max >= (pow(10, 4) - 1)) $num = $max;
213 else $num = sprintf(
"%04s", $max);
216 $sql =
"SELECT ref as ref";
217 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
218 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-".$num.
"'";
219 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
220 $sql .=
" ORDER BY ref DESC";
222 $resql = $db->query($sql);
225 $obj = $db->fetch_object(
$resql);
226 if ($obj) $ref = $obj->ref;
230 } elseif ($mode ==
'next')
232 $date = $invoice->date;
233 $yymm = strftime(
"%y%m", $date);
235 if ($max >= (pow(10, 4) - 1)) $num = $max + 1;
236 else $num = sprintf(
"%04s", $max + 1);
238 dol_syslog(get_class($this).
"::getNextValue return ".$prefix.$yymm.
"-".$num);
239 return $prefix.$yymm.
"-".$num;
251 public function getNumRef($objsoc, $objforref, $mode =
'next')
info()
Returns the description of the numbering model.
Class of numbering module Terre for invoices.
canBeActivated()
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.
Parent class of invoice reference numbering templates.
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...
__construct()
Constructor.
getNextValue($objsoc, $invoice, $mode= 'next')
Return next value not used or last value used.