dolibarr 24.0.0-beta
mod_commande_marbre.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) 2024-2025 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
27require_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
28
33{
38 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
39
43 public $prefix = 'CO';
44
48 public $error = '';
49
53 public $position = 10;
54
58 public $name = 'Marbre';
59
60
64 public function __construct()
65 {
66 global $mysoc;
67
68 if ((float) getDolGlobalString('MAIN_VERSION_LAST_INSTALL') >= 16.0 && $mysoc->country_code != 'FR') {
69 $this->prefix = 'SO'; // We use correct standard code "SO = Sale Order"
70 }
71 }
72
79 public function info($langs)
80 {
81 global $langs;
82 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
83 }
84
85
91 public function getExample()
92 {
93 return $this->prefix."0501-0001";
94 }
95
96
104 public function canBeActivated($object)
105 {
106 global $conf, $langs, $db;
107
108 $coyymm = '';
109 $max = '';
110
111 $posindice = strlen($this->prefix) + 6;
112 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
113 $sql .= " FROM ".MAIN_DB_PREFIX."commande";
114 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
115 $sql .= " AND entity = ".$conf->entity;
116
117 $resql = $db->query($sql);
118 if ($resql) {
119 $row = $db->fetch_row($resql);
120 if ($row) {
121 $coyymm = substr($row[0], 0, 6);
122 $max = $row[0];
123 }
124 }
125 if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
126 $langs->load("errors");
127 $this->error = $langs->trans('ErrorNumRefModel', $max);
128 return false;
129 }
130
131 return true;
132 }
133
141 public function getNextValue($objsoc, $object)
142 {
143 global $db, $conf;
144
145 // First, we get the max value
146 $posindice = strlen($this->prefix) + 6;
147 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
148 $sql .= " FROM ".MAIN_DB_PREFIX."commande";
149 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
150 $sql .= " AND entity IN (".getEntity('ordernumber', 1, $object).")";
151
152 $resql = $db->query($sql);
153 if ($resql) {
154 $obj = $db->fetch_object($resql);
155 if ($obj) {
156 $max = intval($obj->max);
157 } else {
158 $max = 0;
159 }
160 } else {
161 dol_syslog("mod_commande_marbre::getNextValue", LOG_DEBUG);
162 return -1;
163 }
164
165 //$date=time();
166 $date = $object->date;
167 $yymm = dol_print_date($date, "%y%m");
168
169 if ($max >= (pow(10, 4) - 1)) {
170 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
171 } else {
172 $num = sprintf("%04d", $max + 1);
173 }
174
175 dol_syslog("mod_commande_marbre::getNextValue return ".$this->prefix.$yymm."-".$num);
176 return $this->prefix.$yymm."-".$num;
177 }
178}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Parent class to manage numbering of Sale Orders.
Class to manage Sales Order numbering rules Marbre.
info($langs)
Return description of numbering module.
getNextValue($objsoc, $object)
Return next free value.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
getExample()
Return an example of numbering.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.