dolibarr 25.0.0-alpha
fiscalyear_card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014-2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
3 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/fiscalyear.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/fiscalyear.class.php';
38
39// Load translation files required by the page
40$langs->loadLangs(array("admin", "compta"));
41
42// Get parameters
43$id = GETPOSTINT('id');
44$ref = GETPOST('ref', 'alpha') ? GETPOST('ref', 'alpha') : GETPOST('label', 'alpha');
45
46$action = GETPOST('action', 'aZ09');
47$confirm = GETPOST('confirm', 'alpha');
48$cancel = GETPOST('cancel', 'alpha');
49$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
50$backtopage = GETPOST('backtopage', 'alpha'); // if not set, a default page will be used
51$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); // if not set, $backtopage will be used
52$dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
53
54$error = 0;
55
56// Initialize a technical objects
57$object = new Fiscalyear($db);
58
59// Load object
60include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
61
62// List of status
63/*
64static $tmpstatus2label = array(
65 '0' => 'OpenFiscalYear',
66 '1' => 'CloseFiscalYear'
67);
68$status2label = array('' => '');
69foreach ($tmpstatus2label as $key => $val) {
70 $status2label[$key] = $langs->trans($val);
71}
72*/
73$date_start = dol_mktime(0, 0, 0, GETPOSTINT('fiscalyearmonth'), GETPOSTINT('fiscalyearday'), GETPOSTINT('fiscalyearyear'));
74$date_end = dol_mktime(0, 0, 0, GETPOSTINT('fiscalyearendmonth'), GETPOSTINT('fiscalyearendday'), GETPOSTINT('fiscalyearendyear'));
75
76$permissiontoadd = $user->hasRight('accounting', 'fiscalyear', 'write');
77
78// Security check
79if ($user->socid > 0) {
81}
82if (!$permissiontoadd) { // after this test $permissiontoadd is always true
84}
85
86
87/*
88 * Actions
89 */
90
91$parameters = array();
92$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
93if ($reshook < 0) {
94 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
95}
96
97if ($action == 'confirm_delete' && $confirm == "yes" /* && $permissiontoadd // always true */) {
98 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
99 $result = $object->delete($user);
100 if ($result >= 0) {
101 header("Location: fiscalyear.php");
102 exit();
103 } else {
104 setEventMessages($object->error, $object->errors, 'errors');
105 }
106} elseif ($action == 'add' /* && $permissiontoadd // always true */) {
107 if (!GETPOST('cancel', 'alpha')) {
108 $error = 0;
109
110 $object->date_start = $date_start;
111 $object->date_end = $date_end;
112 $object->label = GETPOST('label', 'alpha');
113 $object->status = GETPOSTINT('status');
114 $object->datec = dol_now();
115
116 if (empty($object->date_start) && empty($object->date_end)) {
117 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
118 $error++;
119 }
120 if (empty($object->label)) {
121 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
122 $error++;
123 }
124
125 if (!$error) {
126 $db->begin();
127
128 $id = $object->create($user);
129 if ($id > 0) {
130 $db->commit();
131 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
132 exit;
133 } else {
134 $db->rollback();
135
136 // Handle overlap error
137 if ($id == -5 && !empty($object->errors[0])) {
138 setEventMessages($langs->trans($object->error, $object->errors[0]), null, 'errors');
139 } else {
140 setEventMessages($object->error, $object->errors, 'errors');
141 }
142 $action = 'create';
143 }
144 } else {
145 $action = 'create';
146 }
147 } else {
148 header("Location: ./fiscalyear.php");
149 exit;
150 }
151} elseif ($action == 'update' /* && $permissiontoadd // always true */) {
152 // Update record
153 if (!GETPOST('cancel', 'alpha')) {
154 $result = $object->fetch($id);
155
156 $object->date_start = GETPOST("fiscalyear") ? $date_start : '';
157 $object->date_end = GETPOST("fiscalyearend") ? $date_end : '';
158 $object->label = GETPOST('label', 'alpha');
159 $object->status = GETPOSTINT('status');
160
161 $result = $object->update($user);
162 if ($result > 0) {
163 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
164 exit;
165 } else {
166 // Handle overlap error
167 if ($result == -5 && !empty($object->errors[0])) {
168 setEventMessages($langs->trans($object->error, $object->errors[0]), null, 'errors');
169 } else {
170 setEventMessages($object->error, $object->errors, 'errors');
171 }
172 }
173 } else {
174 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
175 exit;
176 }
177} elseif ($action == 'reopen' /* && $permissiontoadd // always true */ && getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD')) {
178 $result = $object->fetch($id);
179
180 $object->status = GETPOSTINT('status');
181 $result = $object->update($user);
182
183 if ($result > 0) {
184 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
185 exit();
186 } else {
187 setEventMessages($object->error, $object->errors, 'errors');
188 }
189}
190
191
192/*
193 * View
194 */
195
196$form = new Form($db);
197
198$title = $langs->trans("Fiscalyear")." - ".$langs->trans("Card");
199if ($action == 'create') {
200 $title = $langs->trans("NewFiscalYear");
201}
202
203$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
204
205llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-fiscalyear');
206
207if ($action == 'create') {
208 print load_fiche_titre($title, '', 'object_'.$object->picto);
209
210 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
211 print '<input type="hidden" name="token" value="'.newToken().'">';
212 print '<input type="hidden" name="action" value="add">';
213
214 print dol_get_fiche_head(array(), '');
215
216 print '<table class="border centpercent tableforfieldcreate">'."\n";
217
218 // Label
219 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td>';
220 print '<input name="label" size="32" value="'.GETPOST('label', 'alpha').'">';
221 print '</td></tr>';
222
223 // Date start
224 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
225 print $form->selectDate(($date_start ? $date_start : ''), 'fiscalyear');
226 print '</td></tr>';
227
228 // Date end
229 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
230 print $form->selectDate(($date_end ? $date_end : - 1), 'fiscalyearend');
231 print '</td></tr>';
232
233 /*
234 // Status
235 print '<tr>';
236 print '<td class="fieldrequired">' . $langs->trans("Status") . '</td>';
237 print '<td class="valeur">';
238 print $form->selectarray('status', $status2label, GETPOST('status', 'int'));
239 print '</td></tr>';
240 */
241
242 // Common attributes
243 //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
244
245 // Other attributes
246 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
247
248 print '</table>'."\n";
249
250 print dol_get_fiche_end();
251
252 print $form->buttonsSaveCancel("Create");
253
254 print '</form>';
255
256 dol_set_focus('input[name="label"]');
257}
258
259
260// Part to edit record
261if (($id || $ref) && $action == 'edit') {
262 print load_fiche_titre($langs->trans("Fiscalyear"), '', 'object_'.$object->picto);
263
264 print '<form method="POST" name="update" action="'.$_SERVER["PHP_SELF"].'">'."\n";
265 print '<input type="hidden" name="token" value="'.newToken().'">';
266 print '<input type="hidden" name="action" value="update">';
267 print '<input type="hidden" name="status" value="' . $object->status . '">';
268 print '<input type="hidden" name="id" value="'.$object->id.'">';
269 if ($backtopage) {
270 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
271 }
272 if ($backtopageforcancel) {
273 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
274 }
275
276 print dol_get_fiche_head();
277
278 print '<table class="border centpercent tableforfieldedit">'."\n";
279
280 // Ref
281 print "<tr>";
282 print '<td class="titlefieldcreate titlefield">'.$langs->trans("Ref").'</td><td>';
283 print $object->ref;
284 print '</td></tr>';
285
286 // Label
287 print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
288 print '<input name="label" class="flat" size="32" value="'.$object->label.'">';
289 print '</td></tr>';
290
291 // Date start
292 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
293 print $form->selectDate($object->date_start ? $object->date_start : - 1, 'fiscalyear');
294 print '</td></tr>';
295
296 // Date end
297 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
298 print $form->selectDate($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
299 print '</td></tr>';
300
301 // Status
302 print '<tr><td>'.$langs->trans("Status").'</td><td>';
303 print $object->getLibStatut(4);
304 print '</td></tr>';
305
306 // Common attributes
307 //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
308
309 // Other attributes
310 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
311
312 print '</table>';
313
314 print dol_get_fiche_end();
315
316 print $form->buttonsSaveCancel();
317
318 print '</form>';
319}
320
321// Part to show record
322if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
323 $head = fiscalyear_prepare_head($object);
324
325 print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), -1, $object->picto);
326
327 $morehtmlref = '';
328 //$morehtmlref .= '<div class="refidno">';
329 //$morehtmlref .= '</div>';
330
331 $formconfirm = '';
332
333 // Confirmation to delete
334 if ($action == 'delete') {
335 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete", '', 0, 1);
336 }
337
338 // Print form confirm
339 print $formconfirm;
340
341 // Object card
342 // ------------------------------------------------------------
343 $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/fiscalyear.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
344
345 dol_banner_tab($object, 'label', $linkback, 1, 'label', 'label', $morehtmlref);
346
347
348 print '<div class="fichecenter">';
349 print '<div class="fichehalfleft">';
350 print '<div class="underbanner clearboth"></div>';
351
352 print '<table class="border centpercent tableforfield">'."\n";
353
354 // Id
355 print "<tr>";
356 print '<td class="titlefield">'.$langs->trans("Id").'</td><td>';
357 print $object->id;
358 print '</td></tr>';
359
360 // Label
361 print '<tr><td class="tdtop">';
362 print $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'alpha:32');
363 print '</td><td>';
364 print $form->editfieldval("Label", 'label', $object->label, $object, 0, 'alpha:32');
365 print "</td></tr>";
366
367 // Date start
368 print '<tr><td>';
369 print $form->editfieldkey("DateStart", 'date_start', (string) $object->date_start, $object, 0, 'datepicker');
370 print '</td><td>';
371 print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, 0, 'datepicker');
372 print '</td></tr>';
373
374 // Date end
375 print '<tr><td>';
376 print $form->editfieldkey("DateEnd", 'date_end', (string) $object->date_end, $object, 0, 'datepicker');
377 print '</td><td>';
378 print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, 0, 'datepicker');
379 print '</td></tr>';
380
381 print '</table>';
382
383 print '</div>';
384 print '</div>';
385
386 print '<div class="clearboth"></div>';
387
388 print dol_get_fiche_end();
389
390
391 /*
392 * Action bar
393 */
394 if ($user->hasRight('accounting', 'fiscalyear', 'write')) {
395 print '<div class="tabsAction">';
396
397 if (getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD') && $object->status == $object::STATUS_CLOSED) {
398 print dolGetButtonAction($langs->trans("ReOpen"), '', 'reopen', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken(), 'reopen', (int) $permissiontoadd);
399 }
400
401 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
402
403 //print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
404
405 print '</div>';
406 }
407}
408
409// End of page
410llxFooter();
411$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
fiscalyear_prepare_head(Fiscalyear $object)
Prepare array with list of tabs.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.