dolibarr 18.0.6
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 *
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/fichinter/modules_fichinter.php';
27
32{
37 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
38
39 public $prefix = 'FI';
40
44 public $error = '';
45
51 public $nom = 'pacific';
52
56 public $name = 'pacific';
57
58
64 public function info()
65 {
66 global $langs;
67 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
68 }
69
75 public function getExample()
76 {
77 return $this->prefix."0501-0001";
78 }
79
86 public function canBeActivated()
87 {
88 global $langs, $conf, $db;
89
90 $langs->load("bills");
91
92 $fayymm = '';
93 $max = '';
94
95 $posindice = strlen($this->prefix) + 6;
96 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
97 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter";
98 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
99 $sql .= " WHERE entity = ".$conf->entity;
100
101 $resql = $db->query($sql);
102 if ($resql) {
103 $row = $db->fetch_row($resql);
104 if ($row) {
105 $fayymm = substr($row[0], 0, 6);
106 $max = $row[0];
107 }
108 }
109 if (!$fayymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
110 return true;
111 } else {
112 $langs->load("errors");
113 $this->error = $langs->trans('ErrorNumRefModel', $max);
114 return false;
115 }
116 }
117
125 public function getNextValue($objsoc = 0, $object = '')
126 {
127 global $db, $conf;
128
129 // First, we get the max value
130 $posindice = strlen($this->prefix) + 6;
131 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
132 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter";
133 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
134 $sql .= " AND entity = ".$conf->entity;
135
136 $resql = $db->query($sql);
137 if ($resql) {
138 $obj = $db->fetch_object($resql);
139 if ($obj) {
140 $max = intval($obj->max);
141 } else {
142 $max = 0;
143 }
144 }
145
146 //$date=time();
147 $date = $object->datec;
148 $yymm = strftime("%y%m", $date);
149
150 if ($max >= (pow(10, 4) - 1)) {
151 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
152 } else {
153 $num = sprintf("%04s", $max + 1);
154 }
155
156 return $this->prefix.$yymm."-".$num;
157 }
158
166 public function getNumRef($objsoc, $objforref)
167 {
168 return $this->getNextValue($objsoc, $objforref);
169 }
170}
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.
info()
Return description of numbering module.
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
getExample()
Return an example of numbering.
getNextValue($objsoc=0, $object='')
Return next free value.