dolibarr 22.0.5
fiscalyear.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
3 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
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
25// Load Dolibarr environment
26require '../../main.inc.php';
27
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/fiscalyear.class.php';
31
40$action = GETPOST('action', 'aZ09');
41
42// Load variable for pagination
43$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
44$sortfield = GETPOST('sortfield', 'aZ09comma');
45$sortorder = GETPOST('sortorder', 'aZ09comma');
46$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
47if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
48 // If $page is not defined, or '' or -1 or if we click on clear filters
49 $page = 0;
50}
51$offset = $limit * $page;
52$pageprev = $page - 1;
53$pagenext = $page + 1;
54if (!$sortfield) {
55 $sortfield = "f.rowid"; // Set here default search field
56}
57if (!$sortorder) {
58 $sortorder = "ASC";
59}
60
61// Load translation files required by the page
62$langs->loadLangs(array("admin", "compta"));
63
64$error = 0;
65$errors = array();
66
67// List of status
68static $tmpstatut2label = array(
69 '0' => 'OpenFiscalYear',
70 '1' => 'CloseFiscalYear'
71);
72
73// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
74$object = new Fiscalyear($db);
75$hookmanager->initHooks(array('fiscalyearlist'));
76
77// Security check
78if ($user->socid > 0) {
80}
81if (!$user->hasRight('accounting', 'fiscalyear', 'write')) { // If we can read accounting records, we should be able to see fiscal year.
83}
84
85/*
86 * Actions
87 */
88if ($action == 'setdefault') {
89 // Set a fiscal year as default
90 $error = 0;
91
92 $defaultFiscalYear = GETPOSTINT('value');
93 $defaultFiscalYearLabel = GETPOST('label', 'alpha');
94
95 if (!empty($defaultFiscalYear)) {
96 dolibarr_set_const($db, 'ACCOUNTANCY_FISCALYEAR_DEFAULT', $defaultFiscalYear, 'chaine', 0, '', $conf->entity);
97 } else {
98 $error++;
99 }
100
101 if (!$error) {
102 setEventMessages($langs->trans("FiscalYearSetAsDefault", $defaultFiscalYearLabel), null, 'mesgs');
103 } else {
104 setEventMessages($langs->trans("Error"), null, 'errors');
105 }
106}
107
108
109/*
110 * View
111 */
112
113$max = 100;
114
115$form = new Form($db);
116$fiscalyearstatic = new Fiscalyear($db);
117
118$title = $langs->trans('AccountingPeriods');
119
120$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
121
122llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_fiscalyear');
123
124$sql = "SELECT f.rowid, f.label, f.date_start, f.date_end, f.statut as status, f.entity";
125$sql .= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear as f";
126$sql .= " WHERE f.entity = ".$conf->entity;
127$sql .= $db->order($sortfield, $sortorder);
128
129// Count total nb of records
130$nbtotalofrecords = '';
131if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
132 $result = $db->query($sql);
133 $nbtotalofrecords = $db->num_rows($result);
134 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
135 $page = 0;
136 $offset = 0;
137 }
138}
139
140$sql .= $db->plimit($limit + 1, $offset);
141
142$result = $db->query($sql);
143if ($result) {
144 $num = $db->num_rows($result);
145 $param = '';
146
147 $parameters = array('param' => $param);
148 $reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
149 if ($reshook < 0) {
150 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
151 }
152
153 $newcardbutton = empty($hookmanager->resPrint) ? '' : $hookmanager->resPrint;
154
155 if (empty($reshook)) {
156 $newcardbutton .= dolGetButtonTitle($langs->trans('NewFiscalYear'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/accountancy/admin/fiscalyear_card.php?action=create', '', $user->hasRight('accounting', 'fiscalyear', 'write'));
157 }
158
159 $title = $langs->trans('AccountingPeriods');
160 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'calendar', 0, $newcardbutton, '', $limit, 1);
161
162 print '<div class="div-table-responsive">';
163 print '<table class="tagtable liste centpercent noborder">';
164 print '<tr class="liste_titre">';
165 print '<td>'.$langs->trans("Ref").'</td>';
166 print '<td>'.$langs->trans("Label").'</td>';
167 print '<td>'.$langs->trans("DateStart").'</td>';
168 print '<td>'.$langs->trans("DateEnd").'</td>';
169 print '<td class="center">'.$langs->trans("NumberOfAccountancyEntries").'</td>';
170 print '<td class="center">'.$langs->trans("NumberOfAccountancyMovements").'</td>';
171 print '<td class="center">'.$langs->trans("Default").'</td>';
172 print '<td class="right">'.$langs->trans("Status").'</td>';
173 print '</tr>';
174
175 // Loop on record
176 // --------------------------------------------------------------------
177 $i = 0;
178 if ($num) {
179 while ($i < $num && $i < $max) {
180 $obj = $db->fetch_object($result);
181
182 $fiscalyearstatic->ref = $obj->rowid;
183 $fiscalyearstatic->id = $obj->rowid;
184 $fiscalyearstatic->label = $obj->label;
185 $fiscalyearstatic->date_start = $obj->date_start;
186 $fiscalyearstatic->date_end = $obj->date_end;
187 $fiscalyearstatic->statut = $obj->status; // deprecated
188 $fiscalyearstatic->status = $obj->status;
189
190 print '<tr class="oddeven">';
191 print '<td>';
192 print $fiscalyearstatic->getNomUrl(1);
193 print '</td>';
194 print '<td class="left">'.$obj->label.'</td>';
195 print '<td class="left">'.dol_print_date($db->jdate($obj->date_start), 'day').'</td>';
196 print '<td class="left">'.dol_print_date($db->jdate($obj->date_end), 'day').'</td>';
197 print '<td class="center">'.$object->getAccountancyEntriesByFiscalYear($obj->date_start, $obj->date_end).'</td>';
198 print '<td class="center">'.$object->getAccountancyMovementsByFiscalYear($obj->date_start, $obj->date_end).'</td>';
199
200 // Default
201 print '<td class="center">';
202 if (getDolGlobalString('ACCOUNTANCY_FISCALYEAR_DEFAULT') == (int) $fiscalyearstatic->ref) {
203 print img_picto($langs->trans("Default"), 'on');
204 } else {
205 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdefault&token='.newToken().'&value='.urlencode($fiscalyearstatic->ref).'&label='.urlencode($fiscalyearstatic->label).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("SetAsDefault"), 'off').'</a>';
206 }
207 print '</td>';
208
209 print '<td class="right">'.$fiscalyearstatic->LibStatut($obj->status, 5).'</td>';
210 print '</tr>';
211 $i++;
212 }
213 } else {
214 print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
215 }
216 print '</table>';
217 print '</div>';
218} else {
219 dol_print_error($db);
220}
221
222// End of page
223llxFooter();
224$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage fiscal year.
Class to manage generation of HTML components Only common components must be here.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.