28 require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_invoice/modules_facturefournisseur.php';
40 public $version =
'dolibarr';
52 public $nom =
'Cactus';
57 public $name =
'Cactus';
59 public $prefixinvoice =
'SI';
61 public $prefixcreditnote =
'SA';
63 public $prefixdeposit =
'SD';
74 $langs->load(
"bills");
75 return $langs->trans(
"CactusNumRefModelDesc1", $this->prefixinvoice, $this->prefixcreditnote, $this->prefixdeposit);
86 return $this->prefixinvoice.
"1301-0001";
97 global $conf, $langs, $db;
99 $langs->load(
"bills");
105 $posindice = strlen($this->prefixinvoice) + 6;
106 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
107 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn";
108 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixinvoice).
"____-%'";
109 $sql .=
" AND entity = ".$conf->entity;
110 $resql = $db->query($sql);
112 $row = $db->fetch_row(
$resql);
114 $siyymm = substr($row[0], 0, 6);
118 if ($siyymm && !preg_match(
'/'.$this->prefixinvoice.
'[0-9][0-9][0-9][0-9]/i', $siyymm)) {
119 $langs->load(
"errors");
120 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
127 $posindice = strlen($this->prefixcreditnote) + 6;
128 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
129 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn";
130 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixcreditnote).
"____-%'";
131 $sql .=
" AND entity = ".$conf->entity;
133 $resql = $db->query($sql);
135 $row = $db->fetch_row(
$resql);
137 $siyymm = substr($row[0], 0, 6);
141 if ($siyymm && !preg_match(
'/'.$this->prefixcreditnote.
'[0-9][0-9][0-9][0-9]/i', $siyymm)) {
142 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
149 $posindice = strlen($this->prefixdeposit) + 6;
150 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
151 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn";
152 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefixdeposit).
"____-%'";
153 $sql .=
" AND entity = ".$conf->entity;
155 $resql = $db->query($sql);
157 $row = $db->fetch_row(
$resql);
159 $siyymm = substr($row[0], 0, 6);
163 if ($siyymm && !preg_match(
'/'.$this->prefixdeposit.
'[0-9][0-9][0-9][0-9]/i', $siyymm)) {
164 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
181 $prefix = $this->prefixinvoice;
182 if ($object->type == 2) {
183 $prefix = $this->prefixcreditnote;
184 } elseif ($object->type == 3) {
185 $prefix = $this->prefixdeposit;
189 $posindice = strlen($prefix) + 6;
190 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
191 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn";
192 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-%'";
193 $sql .=
" AND entity = ".$conf->entity;
195 $resql = $db->query($sql);
196 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
198 $obj = $db->fetch_object(
$resql);
200 $max = intval($obj->max);
208 if ($mode ==
'last') {
209 if ($max >= (pow(10, 4) - 1)) {
212 $num = sprintf(
"%04s", $max);
216 $sql =
"SELECT ref as ref";
217 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn";
218 $sql .=
" WHERE ref LIKE '".$db->escape($prefix).
"____-".$num.
"'";
219 $sql .=
" AND entity = ".$conf->entity;
221 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
222 $resql = $db->query($sql);
224 $obj = $db->fetch_object(
$resql);
233 } elseif ($mode ==
'next') {
234 $date = $object->date;
235 $yymm = strftime(
"%y%m", $date);
237 if ($max >= (pow(10, 4) - 1)) {
240 $num = sprintf(
"%04s", $max + 1);
243 dol_syslog(get_class($this).
"::getNextValue return ".$prefix.$yymm.
"-".$num);
244 return $prefix.$yymm.
"-".$num;
259 public function getNumRef($objsoc, $objforref, $mode =
'next')
getNumRef($objsoc, $objforref, $mode= 'next')
Return next free value.
getExample()
Returns a numbering example.
info()
Return description of numbering model.
Parent Class of numbering models of suppliers invoices references.
getNextValue($objsoc, $object, $mode= 'next')
Return next value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->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->rights->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...
Cactus Class of numbering models of suppliers invoices references.
canBeActivated()
Tests if the numbers already in force in the database do not cause conflicts that would prevent this ...