dolibarr 19.0.3
mod_workstation_standard.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2020 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
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/workstation/modules_workstation.php';
27
32{
37 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
38
39 public $prefix = 'WKSTATION';
40
44 public $error = '';
45
49 public $name = 'standard';
50
51
58 public function info($langs)
59 {
60 global $langs;
61 return $langs->trans("SimpleNumRefNoDateModelDesc", $this->prefix);
62 }
63
64
70 public function getExample()
71 {
72 return $this->prefix."-0001";
73 }
74
75
83 public function canBeActivated($object)
84 {
85 global $conf, $langs, $db;
86
87 $max = '';
88
89 $posindice = strlen($this->prefix) + 2;
90 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
91 $sql .= " FROM ".MAIN_DB_PREFIX."workstation_workstation";
92 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."-%'";
93 if ($object->ismultientitymanaged == 1) {
94 $sql .= " AND entity = ".$conf->entity;
95 } elseif ($object->ismultientitymanaged == 2) {
96 // TODO
97 }
98
99 $resql = $db->query($sql);
100 if ($resql) {
101 $row = $db->fetch_row($resql);
102 if ($row) {
103 $max = $row[0];
104 }
105 }
106 /*if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
107 $langs->load("errors");
108 $this->error = $langs->trans('ErrorNumRefModel', $max);
109 return false;
110 }*/
111
112 return true;
113 }
114
121 public function getNextValue($object)
122 {
123 global $db, $conf;
124
125 // First we get the max value
126 $posindice = strlen($this->prefix) + 2;
127 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
128 $sql .= " FROM ".MAIN_DB_PREFIX."workstation_workstation";
129 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."-%'";
130 //$sql .= " AND entity = ".$conf->entity;
131
132 $resql = $db->query($sql);
133 if ($resql) {
134 $obj = $db->fetch_object($resql);
135 if ($obj) {
136 $max = intval($obj->max);
137 } else {
138 $max = 0;
139 }
140 } else {
141 dol_syslog("mod_workstation_standard::getNextValue", LOG_DEBUG);
142 return -1;
143 }
144
145 if ($max >= (pow(10, 4) - 1)) {
146 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
147 } else {
148 $num = sprintf("%04s", $max + 1);
149 }
150
151 dol_syslog("mod_workstation_standard::getNextValue return ".$this->prefix."-".$num);
152 return $this->prefix."-".$num;
153 }
154}
Parent class to manage numbering of Workstation.
Class to manage the Standard numbering rule for Workstation.
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...
info($langs)
Return description of numbering module.
getNextValue($object)
Return next free value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.