dolibarr 20.0.0
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 * 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/workstation/modules_workstation.php';
29
34{
39 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
40
41 public $prefix = 'WKSTATION';
42
46 public $error = '';
47
51 public $name = 'standard';
52
53
60 public function info($langs)
61 {
62 global $langs;
63 return $langs->trans("SimpleNumRefNoDateModelDesc", $this->prefix);
64 }
65
66
72 public function getExample()
73 {
74 return $this->prefix."-0001";
75 }
76
77
85 public function canBeActivated($object)
86 {
87 global $conf, $langs, $db;
88
89 $max = '';
90
91 $posindice = strlen($this->prefix) + 2;
92 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
93 $sql .= " FROM ".MAIN_DB_PREFIX."workstation_workstation";
94 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."-%'";
95 if ($object->ismultientitymanaged == 1) {
96 $sql .= " AND entity = ".$conf->entity;
97 } elseif ($object->ismultientitymanaged == 2) {
98 // TODO
99 }
100
101 $resql = $db->query($sql);
102 if ($resql) {
103 $row = $db->fetch_row($resql);
104 if ($row) {
105 $max = $row[0];
106 }
107 }
108 /*if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
109 $langs->load("errors");
110 $this->error = $langs->trans('ErrorNumRefModel', $max);
111 return false;
112 }*/
113
114 return true;
115 }
116
123 public function getNextValue($object)
124 {
125 global $db, $conf;
126
127 // First we get the max value
128 $posindice = strlen($this->prefix) + 2;
129 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
130 $sql .= " FROM ".MAIN_DB_PREFIX."workstation_workstation";
131 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."-%'";
132 //$sql .= " AND entity = ".$conf->entity;
133
134 $resql = $db->query($sql);
135 if ($resql) {
136 $obj = $db->fetch_object($resql);
137 if ($obj) {
138 $max = intval($obj->max);
139 } else {
140 $max = 0;
141 }
142 } else {
143 dol_syslog("mod_workstation_standard::getNextValue", LOG_DEBUG);
144 return -1;
145 }
146
147 if ($max >= (pow(10, 4) - 1)) {
148 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
149 } else {
150 $num = sprintf("%04d", $max + 1);
151 }
152
153 dol_syslog("mod_workstation_standard::getNextValue return ".$this->prefix."-".$num);
154 return $this->prefix."-".$num;
155 }
156}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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.