dolibarr 25.0.0-alpha
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
26require_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
27
32{
33 public $version = 'dolibarr';
37 public $prefix = 'RCP';
38 public $error = '';
42 public $nom = 'Beryl';
43
47 public $position = 10;
48
49
56 public function info($langs)
57 {
58 global $langs;
59 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
60 }
61
62
68 public function getExample()
69 {
70 return $this->prefix."0501-0001";
71 }
72
73
80 public function canBeActivated($object)
81 {
82 global $conf, $langs, $db;
83
84 $coyymm = '';
85 $max = '';
86
87 $posindice = strlen($this->prefix) + 6;
88 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".((int) $posindice).") AS SIGNED)) as max";
89 $sql .= " FROM ".MAIN_DB_PREFIX."reception";
90 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
91 $sql .= " AND entity = ".((int) $conf->entity);
92
93 $resql = $db->query($sql);
94 if ($resql) {
95 $row = $db->fetch_row($resql);
96 if ($row) {
97 $coyymm = substr($row[0], 0, 6);
98 $max = $row[0];
99 }
100 }
101 if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
102 $langs->load("errors");
103 $this->error = $langs->trans('ErrorNumRefModel', $max);
104 return false;
105 }
106
107 return true;
108 }
109
117 public function getNextValue($objsoc, $reception)
118 {
119 global $db, $conf;
120
121 $posindice = strlen($this->prefix) + 6;
122 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".((int) $posindice).") AS SIGNED)) as max";
123 $sql .= " FROM ".MAIN_DB_PREFIX."reception";
124 $sql .= " WHERE ref like '".$db->escape($this->prefix)."____-%'";
125 $sql .= " AND entity = ".((int) $conf->entity);
126
127 $resql = $db->query($sql);
128 if ($resql) {
129 $obj = $db->fetch_object($resql);
130 if ($obj) {
131 $max = intval($obj->max);
132 } else {
133 $max = 0;
134 }
135 } else {
136 dol_syslog("mod_reception_beryl::getNextValue", LOG_DEBUG);
137 return -1;
138 }
139
140 $date = dol_now();
141 $yymm = dol_print_date($date, "%y%m");
142
143 if ($max >= (pow(10, 4) - 1)) {
144 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
145 } else {
146 $num = sprintf("%04d", $max + 1);
147 }
148
149 dol_syslog("mod_reception_beryl::getNextValue return ".$this->prefix.$yymm."-".$num);
150 return $this->prefix.$yymm."-".$num;
151 }
152}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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($object)
Test if existing numbers make problems with numbering.
info($langs)
Return default description of numbering model.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.