dolibarr 20.0.2
mod_commande_fournisseur_muguet.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024 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
28require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
29
30
35{
40 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
41
45 public $error = '';
46
52 public $nom = 'Muguet';
53
57 public $name = 'Muguet';
58
59 public $prefix = 'PO'; // PO for "Purchase Order"
60
61
65 public function __construct()
66 {
67 if (getDolGlobalInt('MAIN_VERSION_LAST_INSTALL') < 5) {
68 $this->prefix = 'CF'; // We use old prefix
69 }
70 }
71
78 public function info($langs)
79 {
80 global $langs;
81 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
82 }
83
84
90 public function getExample()
91 {
92 return $this->prefix."0501-0001";
93 }
94
95
103 public function canBeActivated($object)
104 {
105 global $conf, $langs, $db;
106
107 $coyymm = '';
108 $max = '';
109
110 $posindice = strlen($this->prefix) + 6;
111 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
112 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
113 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
114 $sql .= " AND entity = ".$conf->entity;
115 $resql = $db->query($sql);
116 if ($resql) {
117 $row = $db->fetch_row($resql);
118 if ($row) {
119 $coyymm = substr($row[0], 0, 6);
120 $max = $row[0];
121 }
122 }
123 if (!$coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
124 return true;
125 } else {
126 $langs->load("errors");
127 $this->error = $langs->trans('ErrorNumRefModel', $max);
128 return false;
129 }
130 }
131
139 public function getNextValue($objsoc, $object)
140 {
141 global $db, $conf;
142
143 // First, we get the max value
144 $posindice = strlen($this->prefix) + 6;
145 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
146 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
147 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
148 $sql .= " AND entity = ".$conf->entity;
149
150 $resql = $db->query($sql);
151 if ($resql) {
152 $obj = $db->fetch_object($resql);
153 if ($obj) {
154 $max = intval($obj->max);
155 } else {
156 $max = 0;
157 }
158 }
159
160 //$date=time();
161 $date = $object->date_commande; // Not always defined
162 if (empty($date)) {
163 $date = $object->date; // Creation date is order date for suppliers orders
164 }
165 $yymm = dol_print_date($date, "%y%m");
166
167 if ($max >= (pow(10, 4) - 1)) {
168 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
169 } else {
170 $num = sprintf("%04d", $max + 1);
171 }
172
173 return $this->prefix.$yymm."-".$num;
174 }
175}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Parent Class of numbering models of suppliers orders 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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).