dolibarr  13.0.2
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 <https://www.gnu.org/licenses/>.
17  * or see https://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  public 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  public function info()
76  {
77  global $langs;
78  return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
79  }
80 
81 
87  public function getExample()
88  {
89  return $this->prefix."0501-0001";
90  }
91 
92 
99  public function canBeActivated()
100  {
101  global $conf, $langs, $db;
102 
103  $coyymm = ''; $max = '';
104 
105  $posindice = strlen($this->prefix) + 6;
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  } else {
120  $langs->load("errors");
121  $this->error = $langs->trans('ErrorNumRefModel', $max);
122  return false;
123  }
124  }
125 
133  public function getNextValue($objsoc = 0, $object = '')
134  {
135  global $db, $conf;
136 
137  // First, we get the max value
138  $posindice = strlen($this->prefix) + 6;
139  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
140  $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
141  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
142  $sql .= " AND entity = ".$conf->entity;
143 
144  $resql = $db->query($sql);
145  if ($resql)
146  {
147  $obj = $db->fetch_object($resql);
148  if ($obj) $max = intval($obj->max);
149  else $max = 0;
150  }
151 
152  //$date=time();
153  $date = $object->date_commande; // Not always defined
154  if (empty($date)) $date = $object->date; // Creation date is order date for suppliers orders
155  $yymm = strftime("%y%m", $date);
156 
157  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
158  else $num = sprintf("%04s", $max + 1);
159 
160  return $this->prefix.$yymm."-".$num;
161  }
162 
163 
164  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
172  public function commande_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 commande fournisseur Muguet.
getNextValue()
Returns next value assigned.
info()
Return description of numbering module.
getNextValue($objsoc=0, $object= '')
Return next value.
Parent Class of numbering models of suppliers orders references.
getExample()
Return an example of numbering.
commande_get_num($objsoc=0, $object= '')
Renvoie la reference de commande suivante non utilisee.
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
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...