dolibarr 19.0.3
mod_supplier_payment_bronan.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/supplier_payment/modules_supplier_payment.php';
26
31{
36 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
37
38 public $prefix = 'SPAY';
39
43 public $error = '';
44
50 public $nom = 'Bronan';
51
55 public $name = 'Bronan';
56
57
64 public function info($langs)
65 {
66 global $langs;
67 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
68 }
69
70
76 public function getExample()
77 {
78 return $this->prefix."0501-0001";
79 }
80
81
89 public function canBeActivated($object)
90 {
91 global $conf, $langs, $db;
92
93 $payyymm = '';
94 $max = '';
95
96 $posindice = strlen($this->prefix) + 6;
97 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
98 $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn";
99 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
100 $sql .= " AND entity = ".$conf->entity;
101
102 $resql = $db->query($sql);
103 if ($resql) {
104 $row = $db->fetch_row($resql);
105 if ($row) {
106 $payyymm = substr($row[0], 0, 6);
107 $max = $row[0];
108 }
109 }
110 if ($payyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $payyymm)) {
111 $langs->load("errors");
112 $this->error = $langs->trans('ErrorNumRefModel', $max);
113 return false;
114 }
115
116 return true;
117 }
118
126 public function getNextValue($objsoc, $object)
127 {
128 global $db, $conf;
129
130 // First, we get the max value
131 $posindice = strlen($this->prefix) + 6;
132 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
133 $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn";
134 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
135 $sql .= " AND entity = ".$conf->entity;
136
137 $resql = $db->query($sql);
138 if ($resql) {
139 $obj = $db->fetch_object($resql);
140 if ($obj) {
141 $max = intval($obj->max);
142 } else {
143 $max = 0;
144 }
145 } else {
146 dol_syslog(__METHOD__, LOG_DEBUG);
147 return -1;
148 }
149
150 //$date=time();
151 $date = $object->datepaye;
152 $yymm = dol_print_date($date, "%y%m");
153
154 if ($max >= (pow(10, 4) - 1)) {
155 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
156 } else {
157 $num = sprintf("%04s", $max + 1);
158 }
159
160 dol_syslog(__METHOD__." return ".$this->prefix.$yymm."-".$num);
161 return $this->prefix.$yymm."-".$num;
162 }
163
164
165 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
173 public function payment_get_num($objsoc, $objforref)
174 {
175 // phpcs:enable
176 return $this->getNextValue($objsoc, $objforref);
177 }
178}
ModeleNumRefSupplierPayments.
Class to manage customer payment numbering rules Cicada.
info($langs)
Return description of numbering module.
payment_get_num($objsoc, $objforref)
Return next free value.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
getExample()
Return an example of numbering.
getNextValue($objsoc, $object)
Return next free value.
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.