dolibarr  19.0.0-dev
mod_ticket_simple.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
3  * Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
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/ticket/modules_ticket.php';
27 
32 {
37  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
38 
39  public $prefix = 'TS';
40 
44  public $error = '';
45 
51  public $nom = 'Simple';
52 
56  public $name = 'Simple';
57 
63  public function info()
64  {
65  global $langs;
66  return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
67  }
68 
74  public function getExample()
75  {
76  return $this->prefix."0501-0001";
77  }
78 
85  public function canBeActivated()
86  {
87  global $conf, $langs, $db;
88 
89  $coyymm = '';
90  $max = '';
91 
92  $posindice = strlen($this->prefix) + 6;
93  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
94  $sql .= " FROM ".MAIN_DB_PREFIX."ticket";
95  $search = $this->prefix."____-%";
96  $sql .= " WHERE ref LIKE '".$db->escape($search)."'";
97  $sql .= " AND entity = ".$conf->entity;
98  $resql = $db->query($sql);
99  if ($resql) {
100  $row = $db->fetch_row($resql);
101  if ($row) {
102  $coyymm = substr($row[0], 0, 6);
103  $max = $row[0];
104  }
105  }
106  if (!$coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
107  return true;
108  } else {
109  $langs->load("errors");
110  $this->error = $langs->trans('ErrorNumRefModel', $max);
111  return false;
112  }
113  }
114 
122  public function getNextValue($objsoc, $ticket)
123  {
124  global $db, $conf;
125 
126  // First, we get the max value
127  $posindice = strlen($this->prefix) + 6;
128  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
129  $sql .= " FROM ".MAIN_DB_PREFIX."ticket";
130  $search = $this->prefix."____-%";
131  $sql .= " WHERE ref LIKE '".$db->escape($search)."'";
132  $sql .= " AND entity IN (".getEntity('ticketnumber', 1, $ticket).")";
133 
134  $resql = $db->query($sql);
135  if ($resql) {
136  $obj = $db->fetch_object($resql);
137  if ($obj) {
138  $max = intval($obj->max);
139  } else {
140  $max = 0;
141  }
142  } else {
143  dol_syslog("mod_ticket_simple::getNextValue", LOG_DEBUG);
144  return -1;
145  }
146 
147  $date = empty($ticket->datec) ? dol_now() : $ticket->datec;
148 
149  //$yymm = strftime("%y%m",time());
150  $yymm = dol_print_date($date, "%y%m");
151 
152  if ($max >= (pow(10, 4) - 1)) {
153  $num = $max + 1;
154  } else {
155  // If counter > 9999, we do not format on 4 chars, we take number as it is
156  $num = sprintf("%04s", $max + 1);
157  }
158 
159  dol_syslog("mod_ticket_simple::getNextValue return ".$this->prefix.$yymm."-".$num);
160  return $this->prefix.$yymm."-".$num;
161  }
162 }
Classe mere des modeles de numerotation des references de projets.
Class to manage the numbering module Simple for ticket references.
getExample()
Return an example of numbering module values.
getNextValue($objsoc, $ticket)
Return next value.
info()
Return description of numbering module.
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.