dolibarr  7.0.0-beta
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@capnetworks.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 {
37  var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
38  var $error = '';
39  var $nom = "Jade";
40 
41  var $prefix='BL';
42 
43 
49  function info()
50  {
51  global $langs;
52  return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
53  }
54 
60  function getExample()
61  {
62  return $this->prefix."0501-0001";
63  }
64 
71  function canBeActivated()
72  {
73  global $langs,$conf,$db;
74 
75  $langs->load("bills");
76 
77  // Check invoice num
78  $fayymm=''; $max='';
79 
80  $posindice=8;
81  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
82  $sql.= " FROM ".MAIN_DB_PREFIX."livraison";
83  $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
84  $sql.= " AND entity = ".$conf->entity;
85 
86  $resql=$db->query($sql);
87  if ($resql)
88  {
89  $row = $db->fetch_row($resql);
90  if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; }
91  }
92  if ($fayymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$fayymm))
93  {
94  $langs->load("errors");
95  $this->error=$langs->trans('ErrorNumRefModel',$max);
96  return false;
97  }
98 
99  return true;
100  }
101 
109  function getNextValue($objsoc,$object)
110  {
111  global $db,$conf;
112 
113  // D'abord on recupere la valeur max
114  $posindice=8;
115  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
116  $sql.= " FROM ".MAIN_DB_PREFIX."livraison";
117  $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
118  $sql.= " AND entity = ".$conf->entity;
119 
120  $resql=$db->query($sql);
121  dol_syslog("mod_livraison_jade::getNextValue", LOG_DEBUG);
122  if ($resql)
123  {
124  $obj = $db->fetch_object($resql);
125  if ($obj) $max = intval($obj->max);
126  else $max=0;
127  }
128  else
129  {
130  return -1;
131  }
132 
133  $date=$object->date_delivery;
134  if (empty($date)) $date=dol_now();
135  $yymm = strftime("%y%m",$date);
136 
137  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
138  else $num = sprintf("%04s",$max+1);
139 
140  dol_syslog("mod_livraison_jade::getNextValue return ".$this->prefix.$yymm."-".$num);
141  return $this->prefix.$yymm."-".$num;
142  }
143 
144 
152  function livraison_get_num($objsoc=0,$object='')
153  {
154  return $this->getNextValue($objsoc,$object);
155  }
156 
157 }
Classe du modele de numerotation de reference de bon de livraison Jade.
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.
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:1013
canBeActivated()
Test si les numeros deja en vigueur dans la base ne provoquent pas de de conflits qui empechera cette...