dolibarr 19.0.4
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
65 public function info($langs)
66 {
67 global $langs;
68 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
69 }
70
76 public function getExample()
77 {
78 return $this->prefix."0501-0001";
79 }
80
88 public function canBeActivated($object)
89 {
90 global $langs, $conf, $db;
91
92 $langs->load("bills");
93
94 $fayymm = '';
95 $max = '';
96
97 $posindice = strlen($this->prefix) + 6;
98 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
99 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter";
100 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
101 $sql .= " WHERE entity = ".$conf->entity;
102
103 $resql = $db->query($sql);
104 if ($resql) {
105 $row = $db->fetch_row($resql);
106 if ($row) {
107 $fayymm = substr($row[0], 0, 6);
108 $max = $row[0];
109 }
110 }
111 if (!$fayymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
112 return true;
113 } else {
114 $langs->load("errors");
115 $this->error = $langs->trans('ErrorNumRefModel', $max);
116 return false;
117 }
118 }
119
127 public function getNextValue($objsoc = 0, $object = '')
128 {
129 global $db, $conf;
130
131 // First, we get the max value
132 $posindice = strlen($this->prefix) + 6;
133 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
134 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter";
135 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
136 $sql .= " AND entity = ".$conf->entity;
137
138 $resql = $db->query($sql);
139 if ($resql) {
140 $obj = $db->fetch_object($resql);
141 if ($obj) {
142 $max = intval($obj->max);
143 } else {
144 $max = 0;
145 }
146 }
147
148 //$date=time();
149 $date = $object->datec;
150 $yymm = dol_print_date($date, "%y%m");
151
152 if ($max >= (pow(10, 4) - 1)) {
153 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
154 } else {
155 $num = sprintf("%04s", $max + 1);
156 }
157
158 return $this->prefix.$yymm."-".$num;
159 }
160
168 public function getNumRef($objsoc, $objforref)
169 {
170 return $this->getNextValue($objsoc, $objforref);
171 }
172}
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($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...
getNextValue($objsoc=0, $object='')
Return next free value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).