dolibarr  13.0.2
mod_delivery_jade.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
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 
27 require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/modules_delivery.php';
28 
29 
36 {
41  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
42 
46  public $error = '';
47 
53  public $nom = 'Jade';
54 
58  public $name = 'Jade';
59 
60  public $prefix = 'BL';
61 
62 
68  public function info()
69  {
70  global $langs;
71  return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
72  }
73 
79  public function getExample()
80  {
81  return $this->prefix."0501-0001";
82  }
83 
90  public function canBeActivated()
91  {
92  global $langs, $conf, $db;
93 
94  $langs->load("bills");
95 
96  // Check invoice num
97  $fayymm = ''; $max = '';
98 
99  $posindice = strlen($this->prefix) + 6;
100  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
101  $sql .= " FROM ".MAIN_DB_PREFIX."delivery";
102  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
103  $sql .= " AND entity = ".$conf->entity;
104 
105  $resql = $db->query($sql);
106  if ($resql)
107  {
108  $row = $db->fetch_row($resql);
109  if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; }
110  }
111  if ($fayymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $fayymm))
112  {
113  $langs->load("errors");
114  $this->error = $langs->trans('ErrorNumRefModel', $max);
115  return false;
116  }
117 
118  return true;
119  }
120 
128  public function getNextValue($objsoc, $object)
129  {
130  global $db, $conf;
131 
132  // First, we get the max value
133  $posindice = strlen($this->prefix) + 6;
134  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
135  $sql .= " FROM ".MAIN_DB_PREFIX."delivery";
136  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
137  $sql .= " AND entity = ".$conf->entity;
138 
139  $resql = $db->query($sql);
140  dol_syslog("mod_delivery_jade::getNextValue", LOG_DEBUG);
141  if ($resql) {
142  $obj = $db->fetch_object($resql);
143  if ($obj) $max = intval($obj->max);
144  else $max = 0;
145  } else {
146  return -1;
147  }
148 
149  $date = $object->date_delivery;
150  if (empty($date)) $date = dol_now();
151  $yymm = strftime("%y%m", $date);
152 
153  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
154  else $num = sprintf("%04s", $max + 1);
155 
156  dol_syslog("mod_delivery_jade::getNextValue return ".$this->prefix.$yymm."-".$num);
157  return $this->prefix.$yymm."-".$num;
158  }
159 
160 
161  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
169  public function delivery_get_num($objsoc = 0, $object = '')
170  {
171  // phpcs:enable
172  return $this->getNextValue($objsoc, $object);
173  }
174 }
Classe du modele de numerotation de reference de bon de livraison Jade.
dol_now($mode= 'auto')
Return date for now.
info()
Returns the description of the numbering model.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getExample()
Return an example of numbering.
getNextValue($objsoc, $object)
Return next free value.
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
Classe mere des modeles de numerotation des references de bon de livraison.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
delivery_get_num($objsoc=0, $object= '')
Return next free ref.