dolibarr 18.0.6
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
57 public function info()
58 {
59 global $langs;
60 return $langs->trans("SimpleNumRefNoDateModelDesc", $this->prefix);
61 }
62
63
69 public function getExample()
70 {
71 return $this->prefix."-0001";
72 }
73
74
82 public function canBeActivated($object)
83 {
84 global $conf, $langs, $db;
85
86 $max = '';
87
88 $posindice = strlen($this->prefix) + 2;
89 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
90 $sql .= " FROM ".MAIN_DB_PREFIX."workstation_workstation";
91 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."-%'";
92 if ($object->ismultientitymanaged == 1) {
93 $sql .= " AND entity = ".$conf->entity;
94 } elseif ($object->ismultientitymanaged == 2) {
95 // TODO
96 }
97
98 $resql = $db->query($sql);
99 if ($resql) {
100 $row = $db->fetch_row($resql);
101 if ($row) {
102 $max = $row[0];
103 }
104 }
105 /*if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
106 $langs->load("errors");
107 $this->error = $langs->trans('ErrorNumRefModel', $max);
108 return false;
109 }*/
110
111 return true;
112 }
113
120 public function getNextValue($object)
121 {
122 global $db, $conf;
123
124 // First we get the max value
125 $posindice = strlen($this->prefix) + 2;
126 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
127 $sql .= " FROM ".MAIN_DB_PREFIX."workstation_workstation";
128 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."-%'";
129 //$sql .= " AND entity = ".$conf->entity;
130
131 $resql = $db->query($sql);
132 if ($resql) {
133 $obj = $db->fetch_object($resql);
134 if ($obj) {
135 $max = intval($obj->max);
136 } else {
137 $max = 0;
138 }
139 } else {
140 dol_syslog("mod_workstation_standard::getNextValue", LOG_DEBUG);
141 return -1;
142 }
143
144 if ($max >= (pow(10, 4) - 1)) {
145 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
146 } else {
147 $num = sprintf("%04s", $max + 1);
148 }
149
150 dol_syslog("mod_workstation_standard::getNextValue return ".$this->prefix."-".$num);
151 return $this->prefix."-".$num;
152 }
153}
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()
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.