dolibarr 21.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 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
28require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
29
34{
39 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
40
41 public $prefix = 'FI';
42
46 public $error = '';
47
53 public $nom = 'pacific';
54
58 public $name = 'pacific';
59
60
67 public function info($langs)
68 {
69 global $langs;
70 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
71 }
72
78 public function getExample()
79 {
80 return $this->prefix."0501-0001";
81 }
82
90 public function canBeActivated($object)
91 {
92 global $langs, $conf, $db;
93
94 $langs->load("bills");
95
96 $fayymm = '';
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."fichinter";
102 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
103 $sql .= " WHERE entity = ".$conf->entity;
104
105 $resql = $db->query($sql);
106 if ($resql) {
107 $row = $db->fetch_row($resql);
108 if ($row) {
109 $fayymm = substr($row[0], 0, 6);
110 $max = $row[0];
111 }
112 }
113 if (!$fayymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
114 return true;
115 } else {
116 $langs->load("errors");
117 $this->error = $langs->trans('ErrorNumRefModel', $max);
118 return false;
119 }
120 }
121
129 public function getNextValue($objsoc = '', $object = '')
130 {
131 global $db, $conf;
132
133 // First, we get the max value
134 $posindice = strlen($this->prefix) + 6;
135 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
136 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter";
137 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
138 $sql .= " AND entity = ".$conf->entity;
139
140 $resql = $db->query($sql);
141 if ($resql) {
142 $obj = $db->fetch_object($resql);
143 if ($obj) {
144 $max = intval($obj->max);
145 } else {
146 $max = 0;
147 }
148 }
149
150 //$date=time();
151 $date = '';
152 if (!empty($object->datec)) {
153 $date = $object->datec;
154 }
155 $yymm = dol_print_date($date, "%y%m");
156
157 if ($max >= (pow(10, 4) - 1)) {
158 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
159 } else {
160 $num = sprintf("%04d", $max + 1);
161 }
162
163 return $this->prefix.$yymm."-".$num;
164 }
165
174 public function getNumRef($objsoc, $objforref)
175 {
176 return $this->getNextValue($objsoc, $objforref);
177 }
178}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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)
Output date in a string format according to outputlangs (or langs if not defined).