30require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_invoice/modules_facturefournisseur.php';
42 public $version =
'dolibarr';
54 public $nom =
'Cactus';
59 public $name =
'Cactus';
64 public $prefixinvoice =
'SI';
69 public $prefixcreditnote =
'SA';
74 public $prefixdeposit =
'SD';
83 public function info($langs)
86 $langs->load(
"bills");
87 return $langs->trans(
"CactusNumRefModelDesc1", $this->prefixinvoice, $this->prefixcreditnote, $this->prefixdeposit);
98 return $this->prefixinvoice.
"1301-0001";
110 global
$conf, $langs, $db;
112 $langs->load(
"bills");
118 $posindice = strlen($this->prefixinvoice) + 6;
119 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
120 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn";
121 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixinvoice).
"____-%'";
122 $sql .=
" AND entity = ".$conf->entity;
123 $resql = $db->query($sql);
125 $row = $db->fetch_row($resql);
127 $siyymm = substr($row[0], 0, 6);
131 if ($siyymm && !preg_match(
'/'.$this->prefixinvoice.
'[0-9][0-9][0-9][0-9]/i', $siyymm)) {
132 $langs->load(
"errors");
133 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
140 $posindice = strlen($this->prefixcreditnote) + 6;
141 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
142 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn";
143 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixcreditnote).
"____-%'";
144 $sql .=
" AND entity = ".$conf->entity;
146 $resql = $db->query($sql);
148 $row = $db->fetch_row($resql);
150 $siyymm = substr($row[0], 0, 6);
154 if ($siyymm && !preg_match(
'/'.$this->prefixcreditnote.
'[0-9][0-9][0-9][0-9]/i', $siyymm)) {
155 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
162 $posindice = strlen($this->prefixdeposit) + 6;
163 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
164 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn";
165 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixdeposit).
"____-%'";
166 $sql .=
" AND entity = ".$conf->entity;
168 $resql = $db->query($sql);
170 $row = $db->fetch_row($resql);
172 $siyymm = substr($row[0], 0, 6);
176 if ($siyymm && !preg_match(
'/'.$this->prefixdeposit.
'[0-9][0-9][0-9][0-9]/i', $siyymm)) {
177 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
196 $prefix = $this->prefixinvoice;
198 $prefix = $this->prefixcreditnote;
199 } elseif (
$object->type == 3) {
200 $prefix = $this->prefixdeposit;
204 $posindice = strlen($prefix) + 6;
205 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
206 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn";
207 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-%'";
208 $sql .=
" AND entity = ".$conf->entity;
210 $resql = $db->query($sql);
211 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
213 $obj = $db->fetch_object($resql);
215 $max = intval($obj->max);
223 if ($mode ==
'last') {
224 if ($max >= (pow(10, 4) - 1)) {
227 $num = sprintf(
"%04d", $max);
231 $sql =
"SELECT ref as ref";
232 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn";
233 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-".$num.
"'";
234 $sql .=
" AND entity = ".$conf->entity;
236 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
237 $resql = $db->query($sql);
239 $obj = $db->fetch_object($resql);
248 } elseif ($mode ==
'next') {
252 if ($max >= (pow(10, 4) - 1)) {
255 $num = sprintf(
"%04d", $max + 1);
258 dol_syslog(get_class($this).
"::getNextValue return ".$prefix.$yymm.
"-".$num);
259 return $prefix.$yymm.
"-".$num;
276 public function getNumRef($objsoc, $objforref, $mode =
'next')
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Parent Class of numbering models of suppliers invoices references.
Cactus Class of numbering models of suppliers invoices references.
getNextValue($objsoc, $object, $mode='next')
Return next value.
canBeActivated($object)
Tests if the numbers already in the database do not cause conflicts that would prevent this numbering...
getExample()
Returns a numbering example.
info($langs)
Return description of numbering model.
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...
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...