dolibarr 19.0.3
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
26require_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
64 public function info($langs)
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
87 public function canBeActivated($object)
88 {
89 global $conf, $langs, $db;
90
91 $coyymm = '';
92 $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."ticket";
97 $search = $this->prefix."____-%";
98 $sql .= " WHERE ref LIKE '".$db->escape($search)."'";
99 $sql .= " AND entity = ".$conf->entity;
100 $resql = $db->query($sql);
101 if ($resql) {
102 $row = $db->fetch_row($resql);
103 if ($row) {
104 $coyymm = substr($row[0], 0, 6);
105 $max = $row[0];
106 }
107 }
108 if (!$coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
109 return true;
110 } else {
111 $langs->load("errors");
112 $this->error = $langs->trans('ErrorNumRefModel', $max);
113 return false;
114 }
115 }
116
124 public function getNextValue($objsoc, $ticket)
125 {
126 global $db;
127
128 // First, we get the max value
129 $posindice = strlen($this->prefix) + 6;
130 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
131 $sql .= " FROM ".MAIN_DB_PREFIX."ticket";
132 $search = $this->prefix."____-%";
133 $sql .= " WHERE ref LIKE '".$db->escape($search)."'";
134 $sql .= " AND entity IN (".getEntity('ticketnumber', 1, $ticket).")";
135
136 $resql = $db->query($sql);
137 if ($resql) {
138 $obj = $db->fetch_object($resql);
139 if ($obj) {
140 $max = intval($obj->max);
141 } else {
142 $max = 0;
143 }
144 } else {
145 dol_syslog("mod_ticket_simple::getNextValue", LOG_DEBUG);
146 return -1;
147 }
148
149 $date = empty($ticket->datec) ? dol_now() : $ticket->datec;
150
151 //$yymm = strftime("%y%m",time());
152 $yymm = dol_print_date($date, "%y%m");
153
154 if ($max >= (pow(10, 4) - 1)) {
155 $num = $max + 1;
156 } else {
157 // If counter > 9999, we do not format on 4 chars, we take number as it is
158 $num = sprintf("%04s", $max + 1);
159 }
160
161 dol_syslog("mod_ticket_simple::getNextValue return ".$this->prefix.$yymm."-".$num);
162 return $this->prefix.$yymm."-".$num;
163 }
164}
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($langs)
Return description of numbering module.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
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.