dolibarr  9.0.0
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@inodbox.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 {
38  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
39 
43  public $error = '';
44 
50  public $nom='Muguet';
51 
55  public $name='Muguet';
56 
57  public $prefix='CF';
58 
59 
63  function __construct()
64  {
65  global $conf;
66 
67  if ((float) $conf->global->MAIN_VERSION_LAST_INSTALL >= 5.0) $this->prefix = 'PO'; // We use correct standard code "PO = Purchase Order"
68  }
69 
75  function info()
76  {
77  global $langs;
78  return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
79  }
80 
81 
87  function getExample()
88  {
89  return $this->prefix."0501-0001";
90  }
91 
92 
99  function canBeActivated()
100  {
101  global $conf,$langs,$db;
102 
103  $coyymm=''; $max='';
104 
105  $posindice=8;
106  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
107  $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
108  $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
109  $sql.= " AND entity = ".$conf->entity;
110  $resql=$db->query($sql);
111  if ($resql)
112  {
113  $row = $db->fetch_row($resql);
114  if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; }
115  }
116  if (! $coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm))
117  {
118  return true;
119  }
120  else
121  {
122  $langs->load("errors");
123  $this->error=$langs->trans('ErrorNumRefModel',$max);
124  return false;
125  }
126  }
127 
135  function getNextValue($objsoc=0,$object='')
136  {
137  global $db,$conf;
138 
139  // D'abord on recupere la valeur max
140  $posindice=8;
141  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
142  $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
143  $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
144  $sql.= " AND entity = ".$conf->entity;
145 
146  $resql=$db->query($sql);
147  if ($resql)
148  {
149  $obj = $db->fetch_object($resql);
150  if ($obj) $max = intval($obj->max);
151  else $max=0;
152  }
153 
154  //$date=time();
155  $date=$object->date_commande; // Not always defined
156  if (empty($date)) $date=$object->date; // Creation date is order date for suppliers orders
157  $yymm = strftime("%y%m",$date);
158 
159  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
160  else $num = sprintf("%04s",$max+1);
161 
162  return $this->prefix.$yymm."-".$num;
163  }
164 
165 
166  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
174  function commande_get_num($objsoc=0,$object='')
175  {
176  // phpcs:enable
177  return $this->getNextValue($objsoc,$object);
178  }
179 }
Classe du modele de numerotation de reference de commande fournisseur Muguet.
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
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.
$version
Dolibarr version of the loaded document string.
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.