dolibarr 23.0.3
mod_holiday_madonna.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
3 * Copyright (C) 2018-2023 Charlene Benke <charlene@patas-monkey.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
27require_once DOL_DOCUMENT_ROOT.'/core/modules/holiday/modules_holiday.php';
28
33{
34 // variables inherited from ModelNumRefHolidays class
35 public $name = 'Madonna';
36 public $version = 'dolibarr';
37
38 public $position = 10;
39
40
41 // variables not inherited
42
46 public $prefix = 'HL';
47
51 public function __construct()
52 {
53 $this->code_auto = 1;
54 }
55
62 public function info($langs)
63 {
64 global $langs;
65 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
66 }
67
68
74 public function getExample()
75 {
76 return $this->prefix."0501-0001";
77 }
78
79
86 public function canBeActivated($object)
87 {
88 global $conf, $langs, $db;
89
90 $coyymm = '';
91 $max = '';
92
93 $posindice = strlen($this->prefix) + 6;
94 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
95 $sql .= " FROM ".MAIN_DB_PREFIX."holiday";
96 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
97 $sql .= " AND entity = ".$conf->entity;
98
99 $resql = $db->query($sql);
100 if ($resql) {
101 $row = $db->fetch_row($resql);
102 if ($row) {
103 $coyymm = substr($row[0], 0, 6);
104 $max = $row[0];
105 }
106 }
107 if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
108 $langs->load("errors");
109 $this->error = $langs->trans('ErrorNumRefModel', $max);
110 return false;
111 }
112
113 return true;
114 }
115
123 public function getNextValue($objsoc, $holiday)
124 {
125 global $db, $conf;
126
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."holiday";
130 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
131 $sql .= " AND entity = ".$conf->entity;
132
133 $resql = $db->query($sql);
134 if ($resql) {
135 $obj = $db->fetch_object($resql);
136 if ($obj) {
137 $max = intval($obj->max);
138 } else {
139 $max = 0;
140 }
141 } else {
142 dol_syslog("mod_holiday_madonna::getNextValue", LOG_DEBUG);
143 return -1;
144 }
145
146 $date = $holiday->date_debut;
147 $yymm = dol_print_date($date, "%y%m");
148
149 if ($max >= (pow(10, 4) - 1)) {
150 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
151 } else {
152 $num = sprintf("%04d", $max + 1);
153 }
154
155 dol_syslog("mod_holiday_madonna::getNextValue return ".$this->prefix.$yymm."-".$num);
156 return $this->prefix.$yymm."-".$num;
157 }
158}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Parent class for all holidays numbering modules.
Class to manage holiday numbering rules Madonna.
getExample()
Return numbering example.
canBeActivated($object)
Test if existing numbers make problems with numbering.
info($langs)
Return default description of numbering model.
getNextValue($objsoc, $holiday)
Return next value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.