dolibarr  7.0.0-beta
mod_pacific.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  * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
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 
26 require_once DOL_DOCUMENT_ROOT .'/core/modules/fichinter/modules_fichinter.php';
27 
32 {
33  var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
34  var $prefix='FI';
35  var $error='';
36  var $nom = 'pacific';
37 
38 
44  function info()
45  {
46  global $langs;
47  return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
48  }
49 
55  function getExample()
56  {
57  return $this->prefix."0501-0001";
58  }
59 
66  function canBeActivated()
67  {
68  global $langs,$conf,$db;
69 
70  $langs->load("bills");
71 
72  $fayymm=''; $max='';
73 
74  $posindice=8;
75  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
76  $sql.= " FROM ".MAIN_DB_PREFIX."fichinter";
77  $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
78  $sql.= " WHERE entity = ".$conf->entity;
79 
80  $resql=$db->query($sql);
81  if ($resql)
82  {
83  $row = $db->fetch_row($resql);
84  if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; }
85  }
86  if (! $fayymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$fayymm))
87  {
88  return true;
89  }
90  else
91  {
92  $langs->load("errors");
93  $this->error=$langs->trans('ErrorNumRefModel',$max);
94  return false;
95  }
96  }
97 
105  function getNextValue($objsoc=0,$object='')
106  {
107  global $db,$conf;
108 
109  // D'abord on recupere la valeur max
110  $posindice=8;
111  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
112  $sql.= " FROM ".MAIN_DB_PREFIX."fichinter";
113  $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
114  $sql.= " AND entity = ".$conf->entity;
115 
116  $resql=$db->query($sql);
117  if ($resql)
118  {
119  $obj = $db->fetch_object($resql);
120  if ($obj) $max = intval($obj->max);
121  else $max=0;
122  }
123 
124  //$date=time();
125  $date=$object->datec;
126  $yymm = strftime("%y%m",$date);
127 
128  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
129  else $num = sprintf("%04s",$max+1);
130 
131  return $this->prefix.$yymm."-".$num;
132  }
133 
141  function getNumRef($objsoc,$objforref)
142  {
143  return $this->getNextValue($objsoc,$objforref);
144  }
145 
146 }
147 
getExample()
Renvoi un exemple de numerotation.
Definition: mod_pacific.php:55
getNextValue($objsoc=0, $object='')
Return next free value.
getNextValue()
Renvoi prochaine valeur attribuee.
getNumRef($objsoc, $objforref)
Return next free value.
canBeActivated()
Test si les numeros deja en vigueur dans la base ne provoquent pas de de conflits qui empechera cette...
Definition: mod_pacific.php:66
info()
Return description of numbering module.
Definition: mod_pacific.php:44
Classe mere des modeles de numerotation des references de fiches d'intervention.
Class to manage numbering of intervention cards with rule Pacific.
Definition: mod_pacific.php:31
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