dolibarr  9.0.0
mod_livraison_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 <http://www.gnu.org/licenses/>.
18  * or see http://www.gnu.org/
19  */
20 
27 require_once DOL_DOCUMENT_ROOT .'/core/modules/livraison/modules_livraison.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  function info()
69  {
70  global $langs;
71  return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
72  }
73 
79  function getExample()
80  {
81  return $this->prefix."0501-0001";
82  }
83 
90  function canBeActivated()
91  {
92  global $langs,$conf,$db;
93 
94  $langs->load("bills");
95 
96  // Check invoice num
97  $fayymm=''; $max='';
98 
99  $posindice=8;
100  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
101  $sql.= " FROM ".MAIN_DB_PREFIX."livraison";
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  function getNextValue($objsoc,$object)
129  {
130  global $db,$conf;
131 
132  // D'abord on recupere la valeur max
133  $posindice=8;
134  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
135  $sql.= " FROM ".MAIN_DB_PREFIX."livraison";
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_livraison_jade::getNextValue", LOG_DEBUG);
141  if ($resql)
142  {
143  $obj = $db->fetch_object($resql);
144  if ($obj) $max = intval($obj->max);
145  else $max=0;
146  }
147  else
148  {
149  return -1;
150  }
151 
152  $date=$object->date_delivery;
153  if (empty($date)) $date=dol_now();
154  $yymm = strftime("%y%m",$date);
155 
156  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
157  else $num = sprintf("%04s",$max+1);
158 
159  dol_syslog("mod_livraison_jade::getNextValue return ".$this->prefix.$yymm."-".$num);
160  return $this->prefix.$yymm."-".$num;
161  }
162 
163 
164  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
172  function livraison_get_num($objsoc=0,$object='')
173  {
174  // phpcs:enable
175  return $this->getNextValue($objsoc,$object);
176  }
177 }
Classe du modele de numerotation de reference de bon de livraison Jade.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
livraison_get_num($objsoc=0, $object='')
Return next free ref.
info()
Renvoi la description du modele de numerotation.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
getExample()
Renvoi un exemple de numerotation.
dol_now($mode='gmt')
Return date for now.
getNextValue($objsoc, $object)
Return next free value.
Classe mere des modeles de numerotation des references de bon de livraison.
canBeActivated()
Test si les numeros deja en vigueur dans la base ne provoquent pas de de conflits qui empechera cette...
$version
Dolibarr version of the loaded document string.