dolibarr  16.0.5
mod_stocktransfer_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 Gauthier VERDOL <gauthier.verdol@atm-consulting.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/stocktransfer/modules_stocktransfer.php';
27 
28 
33 {
38  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
39 
40  public $prefix = 'ST';
41 
45  public $error = '';
46 
50  public $name = 'standard';
51 
52 
58  public function info()
59  {
60  global $langs;
61  return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
62  }
63 
64 
70  public function getExample()
71  {
72  return $this->prefix."0501-0001";
73  }
74 
75 
83  public function canBeActivated($object)
84  {
85  global $conf, $langs, $db;
86 
87  $coyymm = ''; $max = '';
88 
89  $posindice = strlen($this->prefix) + 6;
90  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
91  $sql .= " FROM ".MAIN_DB_PREFIX."stocktransfer_stocktransfer";
92  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
93  if ($object->ismultientitymanaged == 1) {
94  $sql .= " AND entity = ".$conf->entity;
95  } elseif ($object->ismultientitymanaged == 2) {
96  // TODO
97  }
98 
99  $resql = $db->query($sql);
100  if ($resql) {
101  $row = $db->fetch_row($resql);
102  if ($row) { $coyymm = substr($row[0], 0, 6); $max = $row[0]; }
103  }
104  if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
105  $langs->load("errors");
106  $this->error = $langs->trans('ErrorNumRefModel', $max);
107  return false;
108  }
109 
110  return true;
111  }
112 
119  public function getNextValue($object)
120  {
121  global $db, $conf;
122 
123  // first we get the max value
124  $posindice = strlen($this->prefix) + 6;
125  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
126  $sql .= " FROM ".MAIN_DB_PREFIX."stocktransfer_stocktransfer";
127  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
128  if ($object->ismultientitymanaged == 1) {
129  $sql .= " AND entity = ".$conf->entity;
130  } elseif ($object->ismultientitymanaged == 2) {
131  // TODO
132  }
133 
134  $resql = $db->query($sql);
135  if ($resql) {
136  $obj = $db->fetch_object($resql);
137  if ($obj) $max = intval($obj->max);
138  else $max = 0;
139  } else {
140  dol_syslog("mod_stocktransfer_standard::getNextValue", LOG_DEBUG);
141  return -1;
142  }
143 
144  //$date=time();
145  $date = $object->date_creation;
146  $yymm = strftime("%y%m", $date);
147 
148  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
149  else $num = sprintf("%04s", $max + 1);
150 
151  dol_syslog("mod_stocktransfer_standard::getNextValue return ".$this->prefix.$yymm."-".$num);
152  return $this->prefix.$yymm."-".$num;
153  }
154 }
mod_stocktransfer_standard
Class to manage customer order numbering rules standard.
Definition: mod_stocktransfer_standard.php:32
mod_stocktransfer_standard\canBeActivated
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
Definition: mod_stocktransfer_standard.php:83
ModeleNumRefStockTransfer
Parent class to manage numbering of StockTransfer.
Definition: modules_stocktransfer.php:70
mod_stocktransfer_standard\info
info()
Return description of numbering module.
Definition: mod_stocktransfer_standard.php:58
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
mod_stocktransfer_standard\getNextValue
getNextValue($object)
Return next free value.
Definition: mod_stocktransfer_standard.php:119
mod_stocktransfer_standard\getExample
getExample()
Return an example of numbering.
Definition: mod_stocktransfer_standard.php:70