dolibarr 18.0.6
mod_delivery_jade.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.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
27require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/modules_delivery.php';
28
29
36{
41 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
42
46 public $error = '';
47
53 public $nom = 'Jade';
54
58 public $name = 'Jade';
59
60 public $prefix = 'BL';
61
62
68 public function info()
69 {
70 global $langs;
71 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
72 }
73
79 public function getExample()
80 {
81 return $this->prefix."0501-0001";
82 }
83
90 public function canBeActivated()
91 {
92 global $langs, $conf, $db;
93
94 $langs->load("bills");
95
96 // Check invoice num
97 $fayymm = '';
98 $max = '';
99
100 $posindice = strlen($this->prefix) + 6;
101 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
102 $sql .= " FROM ".MAIN_DB_PREFIX."delivery";
103 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
104 $sql .= " AND entity = ".$conf->entity;
105
106 $resql = $db->query($sql);
107 if ($resql) {
108 $row = $db->fetch_row($resql);
109 if ($row) {
110 $fayymm = substr($row[0], 0, 6);
111 $max = $row[0];
112 }
113 }
114 if ($fayymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
115 $langs->load("errors");
116 $this->error = $langs->trans('ErrorNumRefModel', $max);
117 return false;
118 }
119
120 return true;
121 }
122
130 public function getNextValue($objsoc, $object)
131 {
132 global $db, $conf;
133
134 // First, we get the max value
135 $posindice = strlen($this->prefix) + 6;
136 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
137 $sql .= " FROM ".MAIN_DB_PREFIX."delivery";
138 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
139 $sql .= " AND entity = ".$conf->entity;
140
141 $resql = $db->query($sql);
142 dol_syslog("mod_delivery_jade::getNextValue", LOG_DEBUG);
143 if ($resql) {
144 $obj = $db->fetch_object($resql);
145 if ($obj) {
146 $max = intval($obj->max);
147 } else {
148 $max = 0;
149 }
150 } else {
151 return -1;
152 }
153
154 $date = $object->date_delivery;
155 if (empty($date)) {
156 $date = dol_now();
157 }
158 $yymm = strftime("%y%m", $date);
159
160 if ($max >= (pow(10, 4) - 1)) {
161 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
162 } else {
163 $num = sprintf("%04s", $max + 1);
164 }
165
166 dol_syslog("mod_delivery_jade::getNextValue return ".$this->prefix.$yymm."-".$num);
167 return $this->prefix.$yymm."-".$num;
168 }
169
170
171 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
179 public function delivery_get_num($objsoc = 0, $object = '')
180 {
181 // phpcs:enable
182 return $this->getNextValue($objsoc, $object);
183 }
184}
Classe mere des modeles de numerotation des references de bon de livraison.
Classe du modele de numerotation de reference de bon de livraison Jade.
info()
Returns the description of the numbering model.
getNextValue($objsoc, $object)
Return next free value.
getExample()
Return an example of numbering.
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
delivery_get_num($objsoc=0, $object='')
Return next free ref.
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.