dolibarr 21.0.0-beta
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 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
62 public $prefix = 'BL';
63
64
71 public function info($langs)
72 {
73 global $langs;
74 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
75 }
76
82 public function getExample()
83 {
84 return $this->prefix."0501-0001";
85 }
86
94 public function canBeActivated($object)
95 {
96 global $langs, $conf, $db;
97
98 $langs->load("bills");
99
100 // Check invoice num
101 $fayymm = '';
102 $max = '';
103
104 $posindice = strlen($this->prefix) + 6;
105 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
106 $sql .= " FROM ".MAIN_DB_PREFIX."delivery";
107 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
108 $sql .= " AND entity = ".$conf->entity;
109
110 $resql = $db->query($sql);
111 if ($resql) {
112 $row = $db->fetch_row($resql);
113 if ($row) {
114 $fayymm = substr($row[0], 0, 6);
115 $max = $row[0];
116 }
117 }
118 if ($fayymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
119 $langs->load("errors");
120 $this->error = $langs->trans('ErrorNumRefModel', $max);
121 return false;
122 }
123
124 return true;
125 }
126
134 public function getNextValue($objsoc, $object)
135 {
136 global $db, $conf;
137
138 // First, we get the max value
139 $posindice = strlen($this->prefix) + 6;
140 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
141 $sql .= " FROM ".MAIN_DB_PREFIX."delivery";
142 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
143 $sql .= " AND entity = ".$conf->entity;
144
145 $resql = $db->query($sql);
146 dol_syslog("mod_delivery_jade::getNextValue", LOG_DEBUG);
147 if ($resql) {
148 $obj = $db->fetch_object($resql);
149 if ($obj) {
150 $max = intval($obj->max);
151 } else {
152 $max = 0;
153 }
154 } else {
155 return -1;
156 }
157
158 $date = $object->date_delivery;
159 if (empty($date)) {
160 $date = dol_now();
161 }
162 $yymm = dol_print_date($date, "%y%m");
163
164 if ($max >= (pow(10, 4) - 1)) {
165 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
166 } else {
167 $num = sprintf("%04d", $max + 1);
168 }
169
170 dol_syslog("mod_delivery_jade::getNextValue return ".$this->prefix.$yymm."-".$num);
171 return $this->prefix.$yymm."-".$num;
172 }
173}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79