dolibarr  13.0.2
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@inodbox.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 <https://www.gnu.org/licenses/>.
18  * or see https://www.gnu.org/
19  */
20 
26 require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
27 
32 {
37  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
38 
39  public $prefix = 'FI';
40 
44  public $error = '';
45 
51  public $nom = 'pacific';
52 
56  public $name = 'pacific';
57 
58 
64  public function info()
65  {
66  global $langs;
67  return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
68  }
69 
75  public function getExample()
76  {
77  return $this->prefix."0501-0001";
78  }
79 
86  public function canBeActivated()
87  {
88  global $langs, $conf, $db;
89 
90  $langs->load("bills");
91 
92  $fayymm = ''; $max = '';
93 
94  $posindice = strlen($this->prefix) + 6;
95  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
96  $sql .= " FROM ".MAIN_DB_PREFIX."fichinter";
97  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
98  $sql .= " WHERE entity = ".$conf->entity;
99 
100  $resql = $db->query($sql);
101  if ($resql)
102  {
103  $row = $db->fetch_row($resql);
104  if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; }
105  }
106  if (!$fayymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $fayymm))
107  {
108  return true;
109  } else {
110  $langs->load("errors");
111  $this->error = $langs->trans('ErrorNumRefModel', $max);
112  return false;
113  }
114  }
115 
123  public function getNextValue($objsoc = 0, $object = '')
124  {
125  global $db, $conf;
126 
127  // First, we get the max value
128  $posindice = strlen($this->prefix) + 6;
129  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
130  $sql .= " FROM ".MAIN_DB_PREFIX."fichinter";
131  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
132  $sql .= " AND entity = ".$conf->entity;
133 
134  $resql = $db->query($sql);
135  if ($resql)
136  {
137  $obj = $db->fetch_object($resql);
138  if ($obj) $max = intval($obj->max);
139  else $max = 0;
140  }
141 
142  //$date=time();
143  $date = $object->datec;
144  $yymm = strftime("%y%m", $date);
145 
146  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
147  else $num = sprintf("%04s", $max + 1);
148 
149  return $this->prefix.$yymm."-".$num;
150  }
151 
159  public function getNumRef($objsoc, $objforref)
160  {
161  return $this->getNextValue($objsoc, $objforref);
162  }
163 }
getExample()
Return an example of numbering.
Definition: mod_pacific.php:75
getNextValue()
Return the next assigned value.
getNumRef($objsoc, $objforref)
Return next free value.
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
Definition: mod_pacific.php:86
info()
Return description of numbering module.
Definition: mod_pacific.php:64
Parent class numbering models of intervention sheet references.
getNextValue($objsoc=0, $object= '')
Return next free value.
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)&&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