dolibarr 19.0.4
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
69 public function info($langs)
70 {
71 global $langs;
72 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
73 }
74
80 public function getExample()
81 {
82 return $this->prefix."0501-0001";
83 }
84
92 public function canBeActivated($object)
93 {
94 global $langs, $conf, $db;
95
96 $langs->load("bills");
97
98 // Check invoice num
99 $fayymm = '';
100 $max = '';
101
102 $posindice = strlen($this->prefix) + 6;
103 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
104 $sql .= " FROM ".MAIN_DB_PREFIX."delivery";
105 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
106 $sql .= " AND entity = ".$conf->entity;
107
108 $resql = $db->query($sql);
109 if ($resql) {
110 $row = $db->fetch_row($resql);
111 if ($row) {
112 $fayymm = substr($row[0], 0, 6);
113 $max = $row[0];
114 }
115 }
116 if ($fayymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
117 $langs->load("errors");
118 $this->error = $langs->trans('ErrorNumRefModel', $max);
119 return false;
120 }
121
122 return true;
123 }
124
132 public function getNextValue($objsoc, $object)
133 {
134 global $db, $conf;
135
136 // First, we get the max value
137 $posindice = strlen($this->prefix) + 6;
138 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
139 $sql .= " FROM ".MAIN_DB_PREFIX."delivery";
140 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
141 $sql .= " AND entity = ".$conf->entity;
142
143 $resql = $db->query($sql);
144 dol_syslog("mod_delivery_jade::getNextValue", LOG_DEBUG);
145 if ($resql) {
146 $obj = $db->fetch_object($resql);
147 if ($obj) {
148 $max = intval($obj->max);
149 } else {
150 $max = 0;
151 }
152 } else {
153 return -1;
154 }
155
156 $date = $object->date_delivery;
157 if (empty($date)) {
158 $date = dol_now();
159 }
160 $yymm = dol_print_date($date, "%y%m");
161
162 if ($max >= (pow(10, 4) - 1)) {
163 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
164 } else {
165 $num = sprintf("%04s", $max + 1);
166 }
167
168 dol_syslog("mod_delivery_jade::getNextValue return ".$this->prefix.$yymm."-".$num);
169 return $this->prefix.$yymm."-".$num;
170 }
171
172
173 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
181 public function delivery_get_num($objsoc = 0, $object = '')
182 {
183 // phpcs:enable
184 return $this->getNextValue($objsoc, $object);
185 }
186}
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($langs)
Returns the description of the numbering model.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
getNextValue($objsoc, $object)
Return next free value.
getExample()
Return an example of numbering.
delivery_get_num($objsoc=0, $object='')
Return next free ref.
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_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.