dolibarr  7.0.0-beta
mod_commande_fournisseur_muguet.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * or see http://www.gnu.org/
18  */
19 
26 require_once DOL_DOCUMENT_ROOT .'/core/modules/supplier_order/modules_commandefournisseur.php';
27 
28 
33 {
34  var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
35  var $error = '';
36  var $nom = 'Muguet';
37  var $prefix='CF';
38 
39 
43  function __construct()
44  {
45  global $conf;
46 
47  if ((float) $conf->global->MAIN_VERSION_LAST_INSTALL >= 5.0) $this->prefix = 'PO'; // We use correct standard code "PO = Purchase Order"
48  }
49 
55  function info()
56  {
57  global $langs;
58  return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
59  }
60 
61 
67  function getExample()
68  {
69  return $this->prefix."0501-0001";
70  }
71 
72 
79  function canBeActivated()
80  {
81  global $conf,$langs,$db;
82 
83  $coyymm=''; $max='';
84 
85  $posindice=8;
86  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
87  $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
88  $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
89  $sql.= " AND entity = ".$conf->entity;
90  $resql=$db->query($sql);
91  if ($resql)
92  {
93  $row = $db->fetch_row($resql);
94  if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; }
95  }
96  if (! $coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm))
97  {
98  return true;
99  }
100  else
101  {
102  $langs->load("errors");
103  $this->error=$langs->trans('ErrorNumRefModel',$max);
104  return false;
105  }
106  }
107 
115  function getNextValue($objsoc=0,$object='')
116  {
117  global $db,$conf;
118 
119  // D'abord on recupere la valeur max
120  $posindice=8;
121  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
122  $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
123  $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
124  $sql.= " AND entity = ".$conf->entity;
125 
126  $resql=$db->query($sql);
127  if ($resql)
128  {
129  $obj = $db->fetch_object($resql);
130  if ($obj) $max = intval($obj->max);
131  else $max=0;
132  }
133 
134  //$date=time();
135  $date=$object->date_commande; // Not always defined
136  if (empty($date)) $date=$object->date; // Creation date is order date for suppliers orders
137  $yymm = strftime("%y%m",$date);
138 
139  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
140  else $num = sprintf("%04s",$max+1);
141 
142  return $this->prefix.$yymm."-".$num;
143  }
144 
145 
153  function commande_get_num($objsoc=0,$object='')
154  {
155  return $this->getNextValue($objsoc,$object);
156  }
157 }
158 
Classe du modele de numerotation de reference de commande fournisseur Muguet.
getNextValue($objsoc=0, $object='')
Return next value.
getNextValue()
Returns next value assigned.
info()
Return description of numbering module.
Parent Class of numbering models of suppliers orders references.
getExample()
Renvoi un exemple de numerotation.
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...
commande_get_num($objsoc=0, $object='')
Renvoie la reference de commande suivante non utilisee.