dolibarr 19.0.3
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 *
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
26require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
27
28
33{
38 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
39
43 public $error = '';
44
50 public $nom = 'Muguet';
51
55 public $name = 'Muguet';
56
57 public $prefix = 'PO'; // PO for "Purchase Order"
58
59
63 public function __construct()
64 {
65 if (getDolGlobalInt('MAIN_VERSION_LAST_INSTALL') < 5) {
66 $this->prefix = 'CF'; // We use old prefix
67 }
68 }
69
76 public function info($langs)
77 {
78 global $langs;
79 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
80 }
81
82
88 public function getExample()
89 {
90 return $this->prefix."0501-0001";
91 }
92
93
101 public function canBeActivated($object)
102 {
103 global $conf, $langs, $db;
104
105 $coyymm = '';
106 $max = '';
107
108 $posindice = strlen($this->prefix) + 6;
109 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
110 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
111 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
112 $sql .= " AND entity = ".$conf->entity;
113 $resql = $db->query($sql);
114 if ($resql) {
115 $row = $db->fetch_row($resql);
116 if ($row) {
117 $coyymm = substr($row[0], 0, 6);
118 $max = $row[0];
119 }
120 }
121 if (!$coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
122 return true;
123 } else {
124 $langs->load("errors");
125 $this->error = $langs->trans('ErrorNumRefModel', $max);
126 return false;
127 }
128 }
129
137 public function getNextValue($objsoc = 0, $object = '')
138 {
139 global $db, $conf;
140
141 // First, we get the max value
142 $posindice = strlen($this->prefix) + 6;
143 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
144 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
145 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
146 $sql .= " AND entity = ".$conf->entity;
147
148 $resql = $db->query($sql);
149 if ($resql) {
150 $obj = $db->fetch_object($resql);
151 if ($obj) {
152 $max = intval($obj->max);
153 } else {
154 $max = 0;
155 }
156 }
157
158 //$date=time();
159 $date = $object->date_commande; // Not always defined
160 if (empty($date)) {
161 $date = $object->date; // Creation date is order date for suppliers orders
162 }
163 $yymm = dol_print_date($date, "%y%m");
164
165 if ($max >= (pow(10, 4) - 1)) {
166 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
167 } else {
168 $num = sprintf("%04s", $max + 1);
169 }
170
171 return $this->prefix.$yymm."-".$num;
172 }
173
174
175 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
183 public function commande_get_num($objsoc = 0, $object = '')
184 {
185 // phpcs:enable
186 return $this->getNextValue($objsoc, $object);
187 }
188}
Parent Class of numbering models of suppliers orders references.
Classe 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=0, $object='')
Return next value.
commande_get_num($objsoc=0, $object='')
Renvoie la reference de commande suivante non utilisee.
info($langs)
Return description of numbering module.
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).
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.