dolibarr 24.0.0-beta
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-2026 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
41 public $position = 10;
42
43
44 // variables not inherited
45
49 public $prefix = 'HL';
50
54 public function __construct()
55 {
56 $this->code_auto = 1;
57 }
58
65 public function info($langs)
66 {
67 global $langs;
68 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
69 }
70
71
77 public function getExample()
78 {
79 return $this->prefix."0501-0001";
80 }
81
82
89 public function canBeActivated($object)
90 {
91 global $conf, $langs, $db;
92
93 $coyymm = '';
94 $max = '';
95
96 $posindice = strlen($this->prefix) + 6;
97 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
98 $sql .= " FROM ".MAIN_DB_PREFIX."holiday";
99 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
100 $sql .= " AND entity = ".$conf->entity;
101
102 $resql = $db->query($sql);
103 if ($resql) {
104 $row = $db->fetch_row($resql);
105 if ($row) {
106 $coyymm = substr($row[0], 0, 6);
107 $max = $row[0];
108 }
109 }
110 if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
111 $langs->load("errors");
112 $this->error = $langs->trans('ErrorNumRefModel', $max);
113 return false;
114 }
115
116 return true;
117 }
118
126 public function getNextValue($objsoc, $holiday)
127 {
128 global $db, $conf;
129
130 $posindice = strlen($this->prefix) + 6;
131 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
132 $sql .= " FROM ".MAIN_DB_PREFIX."holiday";
133 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
134 $sql .= " AND entity = ".$conf->entity;
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_holiday_madonna::getNextValue", LOG_DEBUG);
146 return -1;
147 }
148
149 $date = $holiday->date_debut;
150 $yymm = dol_print_date($date, "%y%m");
151
152 if ($max >= (pow(10, 4) - 1)) {
153 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
154 } else {
155 $num = sprintf("%04d", $max + 1);
156 }
157
158 dol_syslog("mod_holiday_madonna::getNextValue return ".$this->prefix.$yymm."-".$num);
159 return $this->prefix.$yymm."-".$num;
160 }
161}
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.