27require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
37 public $name =
'Terre';
42 public $position = 40;
48 public $version =
'dolibarr_deprecated';
54 public $prefixinvoice =
'FA';
60 public $prefixreplacement =
'FA';
66 public $prefixcreditnote =
'AV';
72 public $prefixdeposit =
'AC';
87 if (((
float)
getDolGlobalString(
'MAIN_VERSION_LAST_INSTALL')) >= 16.0 && $mysoc->country_code !=
'FR') {
88 $this->prefixinvoice =
'IN';
89 $this->prefixreplacement =
'IR';
90 $this->prefixdeposit =
'ID';
91 $this->prefixcreditnote =
'IC';
108 $langs->load(
"bills");
109 return $langs->trans(
'TerreNumRefModelDesc1', $this->prefixinvoice, $this->prefixcreditnote, $this->prefixdeposit);
119 return $this->prefixinvoice.
"0501-0001";
131 global $langs,
$conf, $db;
133 $langs->load(
"bills");
139 $posindice = strlen($this->prefixinvoice) + 6;
140 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
141 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
142 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixinvoice).
"____-%'";
143 $sql .=
" AND entity = ".$conf->entity;
145 $resql = $db->query($sql);
147 $row = $db->fetch_row($resql);
149 $fayymm = substr($row[0], 0, 6);
153 if ($fayymm && !preg_match(
'/'.$this->prefixinvoice.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
154 $langs->load(
"errors");
155 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
162 $posindice = strlen($this->prefixcreditnote) + 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($this->prefixcreditnote).
"____-%'";
166 $sql .=
" AND entity = ".$conf->entity;
168 $resql = $db->query($sql);
170 $row = $db->fetch_row($resql);
172 $fayymm = substr($row[0], 0, 6);
176 if ($fayymm && !preg_match(
'/'.$this->prefixcreditnote.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
177 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
184 $posindice = strlen($this->prefixdeposit) + 6;
185 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
186 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
187 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixdeposit).
"____-%'";
188 $sql .=
" AND entity = ".$conf->entity;
190 $resql = $db->query($sql);
192 $row = $db->fetch_row($resql);
194 $fayymm = substr($row[0], 0, 6);
198 if ($fayymm && !preg_match(
'/'.$this->prefixdeposit.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
199 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
221 dol_syslog(get_class($this).
"::getNextValue mode=".$mode, LOG_DEBUG);
223 $prefix = $this->prefixinvoice;
224 if ($invoice->type == 2) {
225 $prefix = $this->prefixcreditnote;
226 } elseif ($invoice->type == 3) {
227 $prefix = $this->prefixdeposit;
231 $posindice = strlen($prefix) + 6;
232 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
233 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
234 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-%'";
235 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
237 $resql = $db->query($sql);
239 $obj = $db->fetch_object($resql);
241 $max = intval($obj->max);
249 if ($mode ==
'last') {
250 if ($max >= (pow(10, 4) - 1)) {
253 $num = sprintf(
"%04d", $max);
257 $sql =
"SELECT ref as ref";
258 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
259 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-".$num.
"'";
260 $sql .=
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
261 $sql .=
" ORDER BY ref DESC";
263 $resql = $db->query($sql);
265 $obj = $db->fetch_object($resql);
274 } elseif ($mode ==
'next') {
275 $date = $invoice->date;
278 if ($max >= (pow(10, 4) - 1)) {
281 $num = sprintf(
"%04d", $max + 1);
284 dol_syslog(get_class($this).
"::getNextValue return ".$prefix.$yymm.
"-".$num);
285 return $prefix.$yymm.
"-".$num;
302 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 of numbering module Terre for invoices.
getNextValue($objsoc, $invoice, $mode='next')
Return next value not used or last value used.
info($langs)
Returns the description of the numbering model.
getNumRef($objsoc, $objforref, $mode='next')
Return next free value.
getExample()
Return an example of numbering.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
__construct()
Constructor.
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...