dolibarr 23.0.3
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-2025 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 $name = 'pacific';
62
63
70 public function info($langs)
71 {
72 global $langs;
73 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
74 }
75
81 public function getExample()
82 {
83 return $this->prefix."0501-0001";
84 }
85
93 public function canBeActivated($object)
94 {
95 global $langs, $conf, $db;
96
97 $langs->load("bills");
98
99 $fayymm = '';
100 $max = '';
101
102 $posindice = strlen($this->prefix) + 6;
103 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
104 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter";
105 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
106 $sql .= " WHERE 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 return true;
118 } else {
119 $langs->load("errors");
120 $this->error = $langs->trans('ErrorNumRefModel', $max);
121 return false;
122 }
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";
139 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter";
140 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
141 $sql .= " AND entity = ".$conf->entity;
142
143 $max = 0;
144 $resql = $db->query($sql);
145 if ($resql) {
146 $obj = $db->fetch_object($resql);
147 if ($obj) {
148 $max = intval($obj->max);
149 }
150 }
151
152 //$date=time();
153 $date = '';
154 if (!empty($object->datec)) {
155 $date = $object->datec;
156 }
157 $yymm = dol_print_date($date, "%y%m");
158
159 if ($max >= (pow(10, 4) - 1)) {
160 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
161 } else {
162 $num = sprintf("%04d", $max + 1);
163 }
164
165 return $this->prefix.$yymm."-".$num;
166 }
167
176 public function getNumRef($objsoc, $objforref)
177 {
178 return $this->getNextValue($objsoc, $objforref);
179 }
180}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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).