dolibarr 19.0.4
mod_chequereceipt_mint.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
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
25require_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
26
31{
36 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
37
38 public $prefix = 'CHK';
39
43 public $error = '';
44
45 public $name = 'Mint';
46
47
54 public function info($langs)
55 {
56 global $langs;
57 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
58 }
59
60
66 public function getExample()
67 {
68 return $this->prefix."0501-0001";
69 }
70
71
79 public function canBeActivated($object)
80 {
81 global $conf, $langs, $db;
82
83 $payyymm = '';
84 $max = '';
85
86 $posindice = strlen($this->prefix) + 6;
87 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
88 $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
89 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
90 $sql .= " AND entity = ".$conf->entity;
91
92 $resql = $db->query($sql);
93 if ($resql) {
94 $row = $db->fetch_row($resql);
95 if ($row) {
96 $payyymm = substr($row[0], 0, 6);
97 $max = $row[0];
98 }
99 }
100 if ($payyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $payyymm)) {
101 $langs->load("errors");
102 $this->error = $langs->trans('ErrorNumRefModel', $max);
103 return false;
104 }
105
106 return true;
107 }
108
116 public function getNextValue($objsoc, $object)
117 {
118 global $db, $conf;
119
120 // First, we get the max value
121 $posindice = strlen($this->prefix) + 6;
122 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
123 $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
124 $sql .= " WHERE ref like '".$db->escape($this->prefix)."____-%'";
125 $sql .= " AND entity = ".$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(__METHOD__, LOG_DEBUG);
137 return -1;
138 }
139
140 //$date=time();
141 $date = $object->date_bordereau;
142 $yymm = dol_print_date($date, "%y%m");
143
144 if ($max >= (pow(10, 4) - 1)) {
145 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
146 } else {
147 $num = sprintf("%04s", $max + 1);
148 }
149
150 dol_syslog(__METHOD__." return ".$this->prefix.$yymm."-".$num);
151 return $this->prefix.$yymm."-".$num;
152 }
153
154
155 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
163 public function chequereceipt_get_num($objsoc, $objforref)
164 {
165 // phpcs:enable
166 return $this->getNextValue($objsoc, $objforref);
167 }
168}
Class parent for cheque Receipts numbering references mother class.
Class to manage cheque receipts numbering rules Mint.
getExample()
Return an example of numbering.
getNextValue($objsoc, $object)
Return next free value.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
chequereceipt_get_num($objsoc, $objforref)
Return next free value.
info($langs)
Return description of numbering module.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $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.