dolibarr 20.0.0
mod_mo_standard.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 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/mrp/modules_mo.php';
28
33{
38 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
39
40 public $prefix = 'MO';
41
45 public $error = '';
46
50 public $name = 'standard';
51
52
59 public function info($langs)
60 {
61 global $langs;
62 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
63 }
64
65
71 public function getExample()
72 {
73 return $this->prefix."0501-0001";
74 }
75
76
84 public function canBeActivated($object)
85 {
86 global $conf, $langs, $db;
87
88 $coyymm = '';
89 $max = '';
90
91 $posindice = strlen($this->prefix) + 6;
92 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
93 $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo";
94 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
95 $sql .= " AND entity = ".$conf->entity;
96
97 $resql = $db->query($sql);
98 if ($resql) {
99 $row = $db->fetch_row($resql);
100 if ($row) {
101 $coyymm = substr($row[0], 0, 6);
102 $max = $row[0];
103 }
104 }
105 if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
106 $langs->load("errors");
107 $this->error = $langs->trans('ErrorNumRefModel', $max);
108 return false;
109 }
110
111 return true;
112 }
113
121 public function getNextValue($objprod, $object)
122 {
123 global $db, $conf;
124
125 // First, we get the max value
126 $posindice = strlen($this->prefix) + 6;
127 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
128 $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo";
129 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
130 $sql .= " AND entity = ".$conf->entity;
131
132 $resql = $db->query($sql);
133 if ($resql) {
134 $obj = $db->fetch_object($resql);
135 if ($obj) {
136 $max = intval($obj->max);
137 } else {
138 $max = 0;
139 }
140 } else {
141 dol_syslog("mod_mo_standard::getNextValue", LOG_DEBUG);
142 return -1;
143 }
144
145 //$date=time();
146 $date = $object->date_creation;
147 $yymm = dol_print_date($date, "%y%m");
148
149 if ($max >= (pow(10, 4) - 1)) {
150 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
151 } else {
152 $num = sprintf("%04d", $max + 1);
153 }
154
155 dol_syslog("mod_mo_standard::getNextValue return ".$this->prefix.$yymm."-".$num);
156 return $this->prefix.$yymm."-".$num;
157 }
158}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Parent class to manage numbering of MOs.
Class to manage MO numbering rules standard.
getExample()
Return an example of numbering.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
getNextValue($objprod, $object)
Return next free value.
info($langs)
Return description of numbering module.
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).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.