dolibarr  19.0.0-dev
mod_reception_beryl.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  * or see https://www.gnu.org/
17  */
18 
24 require_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
25 
30 {
31  public $version = 'dolibarr';
32  public $prefix = 'RCP';
33  public $error = '';
34  public $nom = 'Beryl';
35 
36 
42  public function info()
43  {
44  global $langs;
45  return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
46  }
47 
48 
54  public function getExample()
55  {
56  return $this->prefix."0501-0001";
57  }
58 
59 
65  public function canBeActivated()
66  {
67  global $conf, $langs, $db;
68 
69  $coyymm = '';
70  $max = '';
71 
72  $posindice = strlen($this->prefix) + 6;
73  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
74  $sql .= " FROM ".MAIN_DB_PREFIX."reception";
75  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
76  $sql .= " AND entity = ".$conf->entity;
77 
78  $resql = $db->query($sql);
79  if ($resql) {
80  $row = $db->fetch_row($resql);
81  if ($row) {
82  $coyymm = substr($row[0], 0, 6);
83  $max = $row[0];
84  }
85  }
86  if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
87  $langs->load("errors");
88  $this->error = $langs->trans('ErrorNumRefModel', $max);
89  return false;
90  }
91 
92  return true;
93  }
94 
102  public function getNextValue($objsoc, $reception)
103  {
104  global $db, $conf;
105 
106  $posindice = strlen($this->prefix) + 6;
107  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
108  $sql .= " FROM ".MAIN_DB_PREFIX."reception";
109  $sql .= " WHERE ref like '".$db->escape($this->prefix)."____-%'";
110  $sql .= " AND entity = ".$conf->entity;
111 
112  $resql = $db->query($sql);
113  if ($resql) {
114  $obj = $db->fetch_object($resql);
115  if ($obj) {
116  $max = intval($obj->max);
117  } else {
118  $max = 0;
119  }
120  } else {
121  dol_syslog("mod_reception_beryl::getNextValue", LOG_DEBUG);
122  return -1;
123  }
124 
125  $date = time();
126  $yymm = strftime("%y%m", $date);
127 
128  if ($max >= (pow(10, 4) - 1)) {
129  $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
130  } else {
131  $num = sprintf("%04s", $max + 1);
132  }
133 
134  dol_syslog("mod_reception_beryl::getNextValue return ".$this->prefix.$yymm."-".$num);
135  return $this->prefix.$yymm."-".$num;
136  }
137 
138  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
146  public function reception_get_num($objsoc, $objforref)
147  {
148  // phpcs:enable
149  return $this->getNextValue($objsoc, $objforref);
150  }
151 }
Parent Class of numbering models of sending receipts references.
Class to manage reception numbering rules Beryl.
getExample()
Return numbering example.
getNextValue($objsoc, $reception)
Return next value.
canBeActivated()
Test if existing numbers make problems with numbering.
info()
Return default description of numbering model.
reception_get_num($objsoc, $objforref)
Return next free value.
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.