dolibarr 25.0.0-alpha
html.formfiscalyear.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
3 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
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 */
18
24require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
25
29class FormFiscalYear extends Form
30{
34 public $db;
35
39 public $error = '';
40
46 public function __construct($db)
47 {
48 $this->db = $db;
49 }
50
61 public function selectFiscalYear($selected = 0, $htmlname = 'fiscalyear', $useempty = 0, $maxlen = 0, $help = 1)
62 {
63 global $conf, $langs;
64
65 $out = '';
66
67 $sql = "SELECT f.rowid, f.label, f.date_start, f.date_end, f.statut as status";
68 $sql .= " FROM ".$this->db->prefix()."accounting_fiscalyear as f";
69 $sql .= " WHERE f.entity = ".((int) $conf->entity);
70 $sql .= " ORDER BY f.date_start ASC";
71
72 dol_syslog(get_class($this).'::'.__METHOD__, LOG_DEBUG);
73 $resql = $this->db->query($sql);
74 if ($resql) {
75 $num = $this->db->num_rows($resql);
76 if ($num) {
77 $out .= '<select class="flat minwidth200" id="'.$htmlname.'" name="'.$htmlname.'">';
78 $i = 0;
79
80 if ($useempty) {
81 $out .= '<option value="0">&nbsp;</option>';
82 }
83 while ($i < $num) {
84 $obj = $this->db->fetch_object($resql);
85
86 $titletoshowhtml = ($maxlen ? dol_trunc($obj->label, $maxlen) : $obj->label).' <span class="opacitymedium">('.$obj->date_start . " - " . $obj->date_end.')</span>';
87 $titletoshow = ($maxlen ? dol_trunc($obj->label, $maxlen) : $obj->label).' <span class="opacitymedium">('.$langs->transnoentitiesnoconv("FiscalYearFromTo", $obj->date_start, $obj->date_end).')</span>';
88
89 $out .= '<option value="'.$obj->rowid.'"';
90 if ($obj->rowid == $selected) {
91 $out .= ' selected';
92 }
93 //$out .= ' data-html="'.dol_escape_htmltag(dol_string_onlythesehtmltags($titletoshowhtml, 1, 0, 0, 0, array('span'))).'"';
94 $out .= ' data-html="'.dolPrintHTMLForAttribute($titletoshowhtml).'"';
95 $out .= '>';
96 $out .= dol_escape_htmltag($titletoshow);
97 $out .= '</option>';
98 $i++;
99 }
100 $out .= '</select>';
101 //if ($user->admin && $help) $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
102
103 $out .= ajax_combobox($htmlname, array());
104 } else {
105 $out .= '<span class="opacitymedium">'.$langs->trans("ErrorNoFiscalyearDefined", $langs->transnoentitiesnoconv("Accounting"), $langs->transnoentitiesnoconv("Setup"), $langs->transnoentitiesnoconv("Fiscalyear")).'</span>';
106 }
107 } else {
108 dol_print_error($this->db);
109 }
110
111 return $out;
112 }
113}
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:476
Class to manage generation of HTML components for accounting management.
selectFiscalYear($selected=0, $htmlname='fiscalyear', $useempty=0, $maxlen=0, $help=1)
Return list of fiscal year.
__construct($db)
Constructor.
Class to manage generation of HTML components Only common components must be here.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...