dolibarr  7.0.0-beta
mod_supplier_payment_bronan.php
1 <?php
2 /* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  * or see http://www.gnu.org/
17  */
18 
25 require_once DOL_DOCUMENT_ROOT .'/core/modules/supplier_payment/modules_supplier_payment.php';
26 
31 {
32  var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
33  var $prefix='SPAY';
34  var $error='';
35  var $nom='Bronan';
36 
37 
43  function info()
44  {
45  global $langs;
46  return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
47  }
48 
49 
55  function getExample()
56  {
57  return $this->prefix."0501-0001";
58  }
59 
60 
67  function canBeActivated()
68  {
69  global $conf,$langs,$db;
70 
71  $payyymm=''; $max='';
72 
73  $posindice=9;
74  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
75  $sql.= " FROM ".MAIN_DB_PREFIX."paiementfourn";
76  $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
77  $sql.= " AND entity = ".$conf->entity;
78 
79  $resql=$db->query($sql);
80  if ($resql)
81  {
82  $row = $db->fetch_row($resql);
83  if ($row) { $payyymm = substr($row[0],0,6); $max=$row[0]; }
84  }
85  if ($payyymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$payyymm))
86  {
87  $langs->load("errors");
88  $this->error=$langs->trans('ErrorNumRefModel', $max);
89  return false;
90  }
91 
92  return true;
93  }
94 
102  function getNextValue($objsoc,$object)
103  {
104  global $db,$conf;
105 
106  // D'abord on recupere la valeur max
107  $posindice=10;
108  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
109  $sql.= " FROM ".MAIN_DB_PREFIX."paiementfourn";
110  $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
111  $sql.= " AND entity = ".$conf->entity;
112 
113  $resql=$db->query($sql);
114  if ($resql)
115  {
116  $obj = $db->fetch_object($resql);
117  if ($obj) $max = intval($obj->max);
118  else $max=0;
119  }
120  else
121  {
122  dol_syslog(__METHOD__, LOG_DEBUG);
123  return -1;
124  }
125 
126  //$date=time();
127  $date=$object->datepaye;
128  $yymm = strftime("%y%m",$date);
129 
130  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
131  else $num = sprintf("%04s",$max+1);
132 
133  dol_syslog(__METHOD__." return ".$this->prefix.$yymm."-".$num);
134  return $this->prefix.$yymm."-".$num;
135  }
136 
137 
145  function payment_get_num($objsoc,$objforref)
146  {
147  return $this->getNextValue($objsoc,$objforref);
148  }
149 
150 }
Class to manage customer payment numbering rules Cicada.
payment_get_num($objsoc, $objforref)
Return next free value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
getNextValue($objsoc, $object)
Return next free value.
canBeActivated()
Test si les numeros deje en vigueur dans la base ne provoquent pas de de conflits qui empechera cette...
getExample()
Renvoi un exemple de numerotation.
info()
Return description of numbering module.
Payment numbering references mother class.
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