dolibarr 24.0.0-beta
mod_expedition_safor.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
3 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.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
26require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
27
32{
37 public $version = 'dolibarr';
38
42 public $prefix = 'SH';
43
47 public $error = '';
48
54 public $nom = 'Safor';
55
59 public $name = 'Safor';
60
61
68 public function info($langs)
69 {
70 global $langs;
71 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
72 }
73
74
80 public function getExample()
81 {
82 return $this->prefix."0501-0001";
83 }
84
85
92 public function canBeActivated($object)
93 {
94 global $conf, $langs, $db;
95
96 $coyymm = '';
97 $max = '';
98
99 $posindice = strlen($this->prefix) + 6;
100 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
101 $sql .= " FROM ".MAIN_DB_PREFIX."expedition";
102 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
103 $sql .= " AND entity = ".$conf->entity;
104
105 $resql = $db->query($sql);
106 if ($resql) {
107 $row = $db->fetch_row($resql);
108 if ($row) {
109 $coyymm = substr($row[0], 0, 6);
110 $max = $row[0];
111 }
112 }
113 if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
114 $langs->load("errors");
115 $this->error = $langs->trans('ErrorNumRefModel', $max);
116 return false;
117 }
118
119 return true;
120 }
121
129 public function getNextValue($objsoc, $shipment)
130 {
131 global $db, $conf;
132
133 $posindice = strlen($this->prefix) + 6;
134 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
135 $sql .= " FROM ".MAIN_DB_PREFIX."expedition";
136 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
137 $sql .= " AND entity = ".$conf->entity;
138
139 $resql = $db->query($sql);
140 if ($resql) {
141 $obj = $db->fetch_object($resql);
142 if ($obj) {
143 $max = intval($obj->max);
144 } else {
145 $max = 0;
146 }
147 } else {
148 dol_syslog("mod_expedition_safor::getNextValue", LOG_DEBUG);
149 return -1;
150 }
151
152 $date = $shipment->date_creation;
153 $yymm = dol_print_date($date, "%y%m");
154
155 if ($max >= (pow(10, 4) - 1)) {
156 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
157 } else {
158 $num = sprintf("%04d", $max + 1);
159 }
160
161 dol_syslog("mod_expedition_safor::getNextValue return ".$this->prefix.$yymm."-".$num);
162 return $this->prefix.$yymm."-".$num;
163 }
164}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Parent Class of numbering models of sending receipts references.
Class to manage expedition numbering rules Safor.
canBeActivated($object)
Test if existing numbers make problems with numbering.
info($langs)
Return default description of numbering model.
getExample()
Return numbering example.
getNextValue($objsoc, $shipment)
Return next value.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.