dolibarr 21.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 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';
34 public $prefix = 'RCP';
35 public $error = '';
36 public $nom = 'Beryl';
37
38
45 public function info($langs)
46 {
47 global $langs;
48 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
49 }
50
51
57 public function getExample()
58 {
59 return $this->prefix."0501-0001";
60 }
61
62
69 public function canBeActivated($object)
70 {
71 global $conf, $langs, $db;
72
73 $coyymm = '';
74 $max = '';
75
76 $posindice = strlen($this->prefix) + 6;
77 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
78 $sql .= " FROM ".MAIN_DB_PREFIX."reception";
79 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
80 $sql .= " AND entity = ".$conf->entity;
81
82 $resql = $db->query($sql);
83 if ($resql) {
84 $row = $db->fetch_row($resql);
85 if ($row) {
86 $coyymm = substr($row[0], 0, 6);
87 $max = $row[0];
88 }
89 }
90 if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
91 $langs->load("errors");
92 $this->error = $langs->trans('ErrorNumRefModel', $max);
93 return false;
94 }
95
96 return true;
97 }
98
106 public function getNextValue($objsoc, $reception)
107 {
108 global $db, $conf;
109
110 $posindice = strlen($this->prefix) + 6;
111 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
112 $sql .= " FROM ".MAIN_DB_PREFIX."reception";
113 $sql .= " WHERE ref like '".$db->escape($this->prefix)."____-%'";
114 $sql .= " AND entity = ".$conf->entity;
115
116 $resql = $db->query($sql);
117 if ($resql) {
118 $obj = $db->fetch_object($resql);
119 if ($obj) {
120 $max = intval($obj->max);
121 } else {
122 $max = 0;
123 }
124 } else {
125 dol_syslog("mod_reception_beryl::getNextValue", LOG_DEBUG);
126 return -1;
127 }
128
129 $date = time();
130 $yymm = dol_print_date($date, "%y%m");
131
132 if ($max >= (pow(10, 4) - 1)) {
133 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
134 } else {
135 $num = sprintf("%04d", $max + 1);
136 }
137
138 dol_syslog("mod_reception_beryl::getNextValue return ".$this->prefix.$yymm."-".$num);
139 return $this->prefix.$yymm."-".$num;
140 }
141}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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.