dolibarr 24.0.0-beta
mod_commande_fournisseur_muguet.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 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
29require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
30
31
36{
41 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
42
46 public $error = '';
47
53 public $nom = 'Muguet';
54
58 public $name = 'Muguet';
59
63 public $prefix = 'PO'; // PO for "Purchase Order"
64
65
69 public function __construct()
70 {
71 if (getDolGlobalInt('MAIN_VERSION_LAST_INSTALL') < 5) {
72 $this->prefix = 'CF'; // We use old prefix
73 }
74 }
75
82 public function info($langs)
83 {
84 global $langs;
85 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
86 }
87
88
94 public function getExample()
95 {
96 return $this->prefix."0501-0001";
97 }
98
99
107 public function canBeActivated($object)
108 {
109 global $conf, $langs, $db;
110
111 $coyymm = '';
112 $max = '';
113
114 $posindice = strlen($this->prefix) + 6;
115 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
116 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
117 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
118 $sql .= " AND entity = ".$conf->entity;
119 $resql = $db->query($sql);
120 if ($resql) {
121 $row = $db->fetch_row($resql);
122 if ($row) {
123 $coyymm = substr($row[0], 0, 6);
124 $max = $row[0];
125 }
126 }
127 if (!$coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
128 return true;
129 } else {
130 $langs->load("errors");
131 $this->error = $langs->trans('ErrorNumRefModel', $max);
132 return false;
133 }
134 }
135
143 public function getNextValue($objsoc, $object)
144 {
145 global $db, $conf;
146
147 // First, we get the max value
148 $posindice = strlen($this->prefix) + 6;
149 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
150 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
151 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
152 $sql .= " AND entity = ".$conf->entity;
153
154 $max = 0;
155 $resql = $db->query($sql);
156 if ($resql) {
157 $obj = $db->fetch_object($resql);
158 if ($obj) {
159 $max = intval($obj->max);
160 } else {
161 $max = 0;
162 }
163 }
164
165 //$date=time();
166 $date = $object->date_commande; // Not always defined
167 if (empty($date)) {
168 $date = $object->date; // Creation date is order date for suppliers orders
169 }
170 $yymm = dol_print_date($date, "%y%m");
171
172 if ($max >= (pow(10, 4) - 1)) {
173 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
174 } else {
175 $num = sprintf("%04d", $max + 1);
176 }
177
178 return $this->prefix.$yymm."-".$num;
179 }
180}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Parent Class of numbering models of supplier order references.
Class du modele de numerotation de reference de commande fournisseur Muguet.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
getNextValue($objsoc, $object)
Return next value.
info($langs)
Return description of numbering module.
getExample()
Return an example of numbering.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).