dolibarr 25.0.0-alpha
mod_pacific.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2026 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
28require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
29
34{
39 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
40
44 public $prefix = 'FI';
45
49 public $error = '';
50
56 public $nom = 'pacific';
57
61 public $position = 50;
62
66 public $name = 'pacific';
67
68
75 public function info($langs)
76 {
77 global $langs;
78 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
79 }
80
86 public function getExample()
87 {
88 return $this->prefix."0501-0001";
89 }
90
98 public function canBeActivated($object)
99 {
100 global $langs, $conf, $db;
101
102 $langs->load("bills");
103
104 $fayymm = '';
105 $max = '';
106
107 $posindice = strlen($this->prefix) + 6;
108 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".((int) $posindice).") AS SIGNED)) as max";
109 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter";
110 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
111 $sql .= " WHERE entity = ".((int) $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 return true;
123 } else {
124 $langs->load("errors");
125 $this->error = $langs->trans('ErrorNumRefModel', $max);
126 return false;
127 }
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 ".((int) $posindice).") AS SIGNED)) as max";
144 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter";
145 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
146 $sql .= " AND entity = ".((int) $conf->entity);
147
148 $max = 0;
149 $resql = $db->query($sql);
150 if ($resql) {
151 $obj = $db->fetch_object($resql);
152 if ($obj) {
153 $max = intval($obj->max);
154 }
155 }
156
157 //$date=time();
158 $date = '';
159 if (!empty($object->datec)) {
160 $date = $object->datec;
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 return $this->prefix.$yymm."-".$num;
171 }
172
181 public function getNumRef($objsoc, $objforref)
182 {
183 return $this->getNextValue($objsoc, $objforref);
184 }
185}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Parent class numbering models of intervention sheet references.
Class to manage numbering of intervention cards with rule Pacific.
getNumRef($objsoc, $objforref)
Return next free value.
getNextValue($objsoc='', $object='')
Return next free value.
info($langs)
Return description of numbering module.
getExample()
Return an example of numbering.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
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).