dolibarr 21.0.0-beta
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 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
44
51 public function info($langs)
52 {
53 global $langs;
54 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
55 }
56
57
63 public function getExample()
64 {
65 return $this->prefix."0501-0001";
66 }
67
68
75 public function canBeActivated($object)
76 {
77 global $conf, $langs, $db;
78
79 $coyymm = '';
80 $max = '';
81
82 $posindice = strlen($this->prefix) + 6;
83 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
84 $sql .= " FROM ".MAIN_DB_PREFIX."reception";
85 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
86 $sql .= " AND entity = ".$conf->entity;
87
88 $resql = $db->query($sql);
89 if ($resql) {
90 $row = $db->fetch_row($resql);
91 if ($row) {
92 $coyymm = substr($row[0], 0, 6);
93 $max = $row[0];
94 }
95 }
96 if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
97 $langs->load("errors");
98 $this->error = $langs->trans('ErrorNumRefModel', $max);
99 return false;
100 }
101
102 return true;
103 }
104
112 public function getNextValue($objsoc, $reception)
113 {
114 global $db, $conf;
115
116 $posindice = strlen($this->prefix) + 6;
117 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
118 $sql .= " FROM ".MAIN_DB_PREFIX."reception";
119 $sql .= " WHERE ref like '".$db->escape($this->prefix)."____-%'";
120 $sql .= " AND entity = ".$conf->entity;
121
122 $resql = $db->query($sql);
123 if ($resql) {
124 $obj = $db->fetch_object($resql);
125 if ($obj) {
126 $max = intval($obj->max);
127 } else {
128 $max = 0;
129 }
130 } else {
131 dol_syslog("mod_reception_beryl::getNextValue", LOG_DEBUG);
132 return -1;
133 }
134
135 $date = time();
136 $yymm = dol_print_date($date, "%y%m");
137
138 if ($max >= (pow(10, 4) - 1)) {
139 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
140 } else {
141 $num = sprintf("%04d", $max + 1);
142 }
143
144 dol_syslog("mod_reception_beryl::getNextValue return ".$this->prefix.$yymm."-".$num);
145 return $this->prefix.$yymm."-".$num;
146 }
147}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.
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_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...
Definition member.php:79