dolibarr  17.0.4
mod_lot_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) 2021 Christophe Battarel <christophe@altairis.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  * or see https://www.gnu.org/
19  */
20 
26 require_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php';
27 
32 {
37  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
38 
39  public $prefix = 'LOT';
40 
44  public $error = '';
45 
49  public $name = 'lot_standard';
50 
51 
57  public function info()
58  {
59  global $langs;
60  return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
61  }
62 
63 
69  public function getExample()
70  {
71  return $this->prefix."0501-0001";
72  }
73 
74 
81  public function canBeActivated()
82  {
83  global $conf, $langs, $db;
84 
85  $coyymm = ''; $max = '';
86 
87  $posindice = strlen($this->prefix) + 6;
88  $sql = "SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.") AS SIGNED)) as max";
89  $sql .= " FROM ".MAIN_DB_PREFIX."product_lot";
90  $sql .= " WHERE batch LIKE '".$db->escape($this->prefix)."____-%'";
91  $sql .= " AND entity = ".$conf->entity;
92 
93  $resql = $db->query($sql);
94  if ($resql) {
95  $obj = $db->fetch_object($resql);
96  if ($obj) {
97  $max = intval($obj->max);
98  } else {
99  $max = 0;
100  }
101  }
102  if ($max && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $max)) {
103  $langs->load("errors");
104  $this->error = $langs->trans('ErrorNumRefModel', $max);
105  return false;
106  }
107 
108  return true;
109  }
110 
118  public function getNextValue($objsoc, $object)
119  {
120  global $db, $conf;
121 
122  // First, we get the max value
123  $posindice = strlen($this->prefix) + 6;
124  $sql = "SELECT MAX(CAST(SUBSTRING(batch FROM ".$posindice.") AS SIGNED)) as max";
125  $sql .= " FROM ".MAIN_DB_PREFIX."product_lot";
126  $sql .= " WHERE batch LIKE '".$db->escape($this->prefix)."____-%'";
127  $sql .= " AND entity = ".$conf->entity;
128 
129  $resql = $db->query($sql);
130  if ($resql) {
131  $obj = $db->fetch_object($resql);
132  if ($obj) {
133  $max = intval($obj->max);
134  } else {
135  $max = 0;
136  }
137  } else {
138  dol_syslog("mod_lot_standard::getNextValue", LOG_DEBUG);
139  return -1;
140  }
141 
142  //$date=time();
143  $date = dol_now();
144  $yymm = strftime("%y%m", $date);
145 
146  if ($max >= (pow(10, 4) - 1)) $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
147  else $num = sprintf("%04s", $max + 1);
148 
149  dol_syslog("mod_lot_standard::getNextValue return ".$this->prefix.$yymm."-".$num);
150  return $this->prefix.$yymm."-".$num;
151  }
152 }
Parent class to manage numbering of batch products.
Class to manage MO numbering rules standard.
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
getNextValue($objsoc, $object)
Return next free value.
getExample()
Return an example of numbering.
info()
Return description of numbering module.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.