dolibarr 19.0.3
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 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 * or see https://www.gnu.org/
18 */
19
25require_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
26
31{
36 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
37
38 public $prefix = 'CO';
39
43 public $error = '';
44
48 public $name = 'Marbre';
49
50
54 public function __construct()
55 {
56 global $conf, $mysoc;
57
58 if ((float) $conf->global->MAIN_VERSION_LAST_INSTALL >= 16.0 && $mysoc->country_code != 'FR') {
59 $this->prefix = 'SO'; // We use correct standard code "SO = Sale Order"
60 }
61 }
62
69 public function info($langs)
70 {
71 global $langs;
72 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
73 }
74
75
81 public function getExample()
82 {
83 return $this->prefix."0501-0001";
84 }
85
86
94 public function canBeActivated($object)
95 {
96 global $conf, $langs, $db;
97
98 $coyymm = '';
99 $max = '';
100
101 $posindice = strlen($this->prefix) + 6;
102 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
103 $sql .= " FROM ".MAIN_DB_PREFIX."commande";
104 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
105 $sql .= " AND entity = ".$conf->entity;
106
107 $resql = $db->query($sql);
108 if ($resql) {
109 $row = $db->fetch_row($resql);
110 if ($row) {
111 $coyymm = substr($row[0], 0, 6);
112 $max = $row[0];
113 }
114 }
115 if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
116 $langs->load("errors");
117 $this->error = $langs->trans('ErrorNumRefModel', $max);
118 return false;
119 }
120
121 return true;
122 }
123
131 public function getNextValue($objsoc, $object)
132 {
133 global $db, $conf;
134
135 // First, we get the max value
136 $posindice = strlen($this->prefix) + 6;
137 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
138 $sql .= " FROM ".MAIN_DB_PREFIX."commande";
139 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
140 $sql .= " AND entity IN (".getEntity('ordernumber', 1, $object).")";
141
142 $resql = $db->query($sql);
143 if ($resql) {
144 $obj = $db->fetch_object($resql);
145 if ($obj) {
146 $max = intval($obj->max);
147 } else {
148 $max = 0;
149 }
150 } else {
151 dol_syslog("mod_commande_marbre::getNextValue", LOG_DEBUG);
152 return -1;
153 }
154
155 //$date=time();
156 $date = $object->date;
157 $yymm = dol_print_date($date, "%y%m");
158
159 if ($max >= (pow(10, 4) - 1)) {
160 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
161 } else {
162 $num = sprintf("%04s", $max + 1);
163 }
164
165 dol_syslog("mod_commande_marbre::getNextValue return ".$this->prefix.$yymm."-".$num);
166 return $this->prefix.$yymm."-".$num;
167 }
168
169
170 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
178 public function commande_get_num($objsoc, $objforref)
179 {
180 // phpcs:enable
181 return $this->getNextValue($objsoc, $objforref);
182 }
183}
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...
commande_get_num($objsoc, $objforref)
Return next free value.
getExample()
Return an example of numbering.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.