dolibarr 22.0.5
html.formfiscalyear.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
23require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
24
28class FormFiscalYear extends Form
29{
33 public $db;
34
38 public $error = '';
39
45 public function __construct($db)
46 {
47 $this->db = $db;
48 }
49
60 public function selectFiscalYear($selected = 0, $htmlname = 'fiscalyear', $useempty = 0, $maxlen = 0, $help = 1)
61 {
62 global $conf, $langs;
63
64 $out = '';
65
66 $sql = "SELECT f.rowid, f.label, f.date_start, f.date_end, f.statut as status";
67 $sql .= " FROM ".$this->db->prefix()."accounting_fiscalyear as f";
68 $sql .= " WHERE f.entity = ".$conf->entity;
69 $sql .= " ORDER BY f.date_start ASC";
70
71 dol_syslog(get_class($this).'::'.__METHOD__, LOG_DEBUG);
72 $resql = $this->db->query($sql);
73 if ($resql) {
74 $num = $this->db->num_rows($resql);
75 if ($num) {
76 $out .= '<select class="flat minwidth200" id="'.$htmlname.'" name="'.$htmlname.'">';
77 $i = 0;
78
79 if ($useempty) {
80 $out .= '<option value="0">&nbsp;</option>';
81 }
82 while ($i < $num) {
83 $obj = $this->db->fetch_object($resql);
84
85 $titletoshowhtml = ($maxlen ? dol_trunc($obj->label, $maxlen) : $obj->label).' <span class="opacitymedium">('.$obj->date_start . " - " . $obj->date_end.')</span>';
86 $titletoshow = ($maxlen ? dol_trunc($obj->label, $maxlen) : $obj->label).' <span class="opacitymedium">('.$langs->transnoentitiesnoconv("FiscalYearFromTo", $obj->date_start, $obj->date_end).')</span>';
87
88 $out .= '<option value="'.$obj->rowid.'"';
89 if ($obj->rowid == $selected) {
90 $out .= ' selected';
91 }
92 //$out .= ' data-html="'.dol_escape_htmltag(dol_string_onlythesehtmltags($titletoshowhtml, 1, 0, 0, 0, array('span'))).'"';
93 $out .= ' data-html="'.dolPrintHTMLForAttribute($titletoshowhtml).'"';
94 $out .= '>';
95 $out .= dol_escape_htmltag($titletoshow);
96 $out .= '</option>';
97 $i++;
98 }
99 $out .= '</select>';
100 //if ($user->admin && $help) $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
101
102 $out .= ajax_combobox($htmlname, array());
103 } else {
104 $out .= '<span class="opacitymedium">'.$langs->trans("ErrorNoFiscalyearDefined", $langs->transnoentitiesnoconv("Accounting"), $langs->transnoentitiesnoconv("Setup"), $langs->transnoentitiesnoconv("Fiscalyear")).'</span>';
105 }
106 } else {
107 dol_print_error($this->db);
108 }
109
110 return $out;
111 }
112}
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:475
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.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79