dolibarr  17.0.4
mod_contract_serpis.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011 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 <https://www.gnu.org/licenses/>.
16  * or see https://www.gnu.org/
17  */
18 
24 require_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
25 
30 {
35  public $version = 'dolibarr';
36 
37  public $prefix = 'CT';
38 
42  public $error = '';
43 
49  public $nom = 'Serpis';
50 
54  public $name = 'Serpis';
55 
59  public $code_auto = 1;
60 
61 
67  public function info()
68  {
69  global $langs;
70  return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
71  }
72 
73 
79  public function getExample()
80  {
81  return $this->prefix."0501-0001";
82  }
83 
84 
90  public function canBeActivated()
91  {
92  global $conf, $langs, $db;
93 
94  $coyymm = '';
95  $max = '';
96 
97  $posindice = strlen($this->prefix) + 6;
98  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
99  $sql .= " FROM ".MAIN_DB_PREFIX."contrat";
100  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
101  $sql .= " AND entity = ".$conf->entity;
102 
103  $resql = $db->query($sql);
104  if ($resql) {
105  $row = $db->fetch_row($resql);
106  if ($row) {
107  $coyymm = substr($row[0], 0, 6);
108  $max = $row[0];
109  }
110  }
111  if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
112  $langs->load("errors");
113  $this->error = $langs->trans('ErrorNumRefModel', $max);
114  return false;
115  }
116 
117  return true;
118  }
119 
127  public function getNextValue($objsoc, $contract)
128  {
129  global $db, $conf;
130 
131  $posindice = strlen($this->prefix) + 6;
132  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
133  $sql .= " FROM ".MAIN_DB_PREFIX."contrat";
134  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
135  $sql .= " AND entity = ".$conf->entity;
136 
137  $resql = $db->query($sql);
138  if ($resql) {
139  $obj = $db->fetch_object($resql);
140  if ($obj) {
141  $max = intval($obj->max);
142  } else {
143  $max = 0;
144  }
145  } else {
146  dol_syslog("mod_contract_serpis::getNextValue", LOG_DEBUG);
147  return -1;
148  }
149 
150  $date = $contract->date_contrat;
151  $yymm = strftime("%y%m", $date);
152 
153  if ($max >= (pow(10, 4) - 1)) {
154  $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
155  } else {
156  $num = sprintf("%04s", $max + 1);
157  }
158 
159  dol_syslog("mod_contract_serpis::getNextValue return ".$this->prefix.$yymm."-".$num);
160  return $this->prefix.$yymm."-".$num;
161  }
162 
163 
164  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
172  public function contract_get_num($objsoc, $objforref)
173  {
174  // phpcs:enable
175  return $this->getNextValue($objsoc, $objforref);
176  }
177 }
Parent class for all contract numbering modules.
Class to manage contract numbering rules Serpis.
canBeActivated()
Test if existing numbers make problems with numbering.
contract_get_num($objsoc, $objforref)
Return next value.
info()
Return default description of numbering model.
getExample()
Return numbering example.
getNextValue($objsoc, $contract)
Return next value.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.