dolibarr 20.0.0
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 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 // variables not inherited
39
43 public $prefix = 'HL';
44
48 public function __construct()
49 {
50 $this->code_auto = 1;
51 }
52
59 public function info($langs)
60 {
61 global $langs;
62 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
63 }
64
65
71 public function getExample()
72 {
73 return $this->prefix."0501-0001";
74 }
75
76
83 public function canBeActivated($object)
84 {
85 global $conf, $langs, $db;
86
87 $coyymm = '';
88 $max = '';
89
90 $posindice = strlen($this->prefix) + 6;
91 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
92 $sql .= " FROM ".MAIN_DB_PREFIX."holiday";
93 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
94 $sql .= " AND entity = ".$conf->entity;
95
96 $resql = $db->query($sql);
97 if ($resql) {
98 $row = $db->fetch_row($resql);
99 if ($row) {
100 $coyymm = substr($row[0], 0, 6);
101 $max = $row[0];
102 }
103 }
104 if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
105 $langs->load("errors");
106 $this->error = $langs->trans('ErrorNumRefModel', $max);
107 return false;
108 }
109
110 return true;
111 }
112
120 public function getNextValue($objsoc, $holiday)
121 {
122 global $db, $conf;
123
124 $posindice = strlen($this->prefix) + 6;
125 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
126 $sql .= " FROM ".MAIN_DB_PREFIX."holiday";
127 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
128 $sql .= " AND entity = ".$conf->entity;
129
130 $resql = $db->query($sql);
131 if ($resql) {
132 $obj = $db->fetch_object($resql);
133 if ($obj) {
134 $max = intval($obj->max);
135 } else {
136 $max = 0;
137 }
138 } else {
139 dol_syslog("mod_holiday_madonna::getNextValue", LOG_DEBUG);
140 return -1;
141 }
142
143 $date = $holiday->date_debut;
144 $yymm = dol_print_date($date, "%y%m");
145
146 if ($max >= (pow(10, 4) - 1)) {
147 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
148 } else {
149 $num = sprintf("%04d", $max + 1);
150 }
151
152 dol_syslog("mod_holiday_madonna::getNextValue return ".$this->prefix.$yymm."-".$num);
153 return $this->prefix.$yymm."-".$num;
154 }
155}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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)
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.