dolibarr 22.0.5
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-2025 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
44 public $prefix = 'WKSTATION';
45
49 public $error = '';
50
54 public $name = 'standard';
55
56
63 public function info($langs)
64 {
65 global $langs;
66 return $langs->trans("SimpleNumRefNoDateModelDesc", $this->prefix);
67 }
68
69
75 public function getExample()
76 {
77 return $this->prefix."-0001";
78 }
79
80
88 public function canBeActivated($object)
89 {
90 global $conf, $db;
91
92 $max = '';
93
94 $posindice = strlen($this->prefix) + 2;
95 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
96 $sql .= " FROM ".MAIN_DB_PREFIX."workstation_workstation";
97 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."-%'";
98 if ($object->ismultientitymanaged == 1) {
99 $sql .= " AND entity = ".$conf->entity;
100 } elseif (!is_numeric($object->ismultientitymanaged)) {
101 // TODO
102 }
103
104 $resql = $db->query($sql);
105 if ($resql) {
106 $row = $db->fetch_row($resql);
107 if ($row) {
108 $max = $row[0];
109 }
110 }
111 /*if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
112 $langs->load("errors");
113 $this->error = $langs->trans('ErrorNumRefModel', $max);
114 return false;
115 }*/
116
117 return true;
118 }
119
126 public function getNextValue($object)
127 {
128 global $db;
129
130 // First we get the max value
131 $posindice = strlen($this->prefix) + 2;
132 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
133 $sql .= " FROM ".MAIN_DB_PREFIX."workstation_workstation";
134 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."-%'";
135 //$sql .= " AND entity = ".$conf->entity;
136
137 $resql = $db->query($sql);
138 if ($resql) {
139 $obj = $db->fetch_object($resql);
140 if ($obj) {
141 $max = intval($obj->max);
142 } else {
143 $max = 0;
144 }
145 } else {
146 dol_syslog("mod_workstation_standard::getNextValue", LOG_DEBUG);
147 return -1;
148 }
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("%04d", $max + 1);
154 }
155
156 dol_syslog("mod_workstation_standard::getNextValue return ".$this->prefix."-".$num);
157 return $this->prefix."-".$num;
158 }
159}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79