dolibarr 23.0.3
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 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 * or see https://www.gnu.org/
21 */
22
29require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/modules_delivery.php';
30
31
38{
43 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
44
48 public $error = '';
49
55 public $nom = 'Jade';
56
60 public $name = 'Jade';
61
65 public $prefix = 'BL';
66
67
74 public function info($langs)
75 {
76 global $langs;
77 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
78 }
79
85 public function getExample()
86 {
87 return $this->prefix."0501-0001";
88 }
89
97 public function canBeActivated($object)
98 {
99 global $langs, $conf, $db;
100
101 $langs->load("bills");
102
103 // Check invoice num
104 $fayymm = '';
105 $max = '';
106
107 $posindice = strlen($this->prefix) + 6;
108 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
109 $sql .= " FROM ".MAIN_DB_PREFIX."delivery";
110 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
111 $sql .= " AND entity = ".$conf->entity;
112
113 $resql = $db->query($sql);
114 if ($resql) {
115 $row = $db->fetch_row($resql);
116 if ($row) {
117 $fayymm = substr($row[0], 0, 6);
118 $max = $row[0];
119 }
120 }
121 if ($fayymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
122 $langs->load("errors");
123 $this->error = $langs->trans('ErrorNumRefModel', $max);
124 return false;
125 }
126
127 return true;
128 }
129
137 public function getNextValue($objsoc, $object)
138 {
139 global $db, $conf;
140
141 // First, we get the max value
142 $posindice = strlen($this->prefix) + 6;
143 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
144 $sql .= " FROM ".MAIN_DB_PREFIX."delivery";
145 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
146 $sql .= " AND entity = ".$conf->entity;
147
148 $resql = $db->query($sql);
149 dol_syslog("mod_delivery_jade::getNextValue", LOG_DEBUG);
150 if ($resql) {
151 $obj = $db->fetch_object($resql);
152 if ($obj) {
153 $max = intval($obj->max);
154 } else {
155 $max = 0;
156 }
157 } else {
158 return -1;
159 }
160
161 $date = $object->date_delivery;
162 if (empty($date)) {
163 $date = dol_now();
164 }
165 $yymm = dol_print_date($date, "%y%m");
166
167 if ($max >= (pow(10, 4) - 1)) {
168 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
169 } else {
170 $num = sprintf("%04d", $max + 1);
171 }
172
173 dol_syslog("mod_delivery_jade::getNextValue return ".$this->prefix.$yymm."-".$num);
174 return $this->prefix.$yymm."-".$num;
175 }
176}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class mere des modeles de numerotation des references de bon de livraison.
Class 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.
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
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.