dolibarr 23.0.3
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-2025 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';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/fiscalyear.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/fiscalyear.class.php';
37
38// Load translation files required by the page
39$langs->loadLangs(array("admin", "compta"));
40
41// Get parameters
42$id = GETPOSTINT('id');
43$ref = GETPOST('ref', 'alpha') ? GETPOST('ref', 'alpha') : GETPOST('label', 'alpha');
44
45$action = GETPOST('action', 'aZ09');
46$confirm = GETPOST('confirm', 'alpha');
47$cancel = GETPOST('cancel', 'alpha');
48$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
49$backtopage = GETPOST('backtopage', 'alpha'); // if not set, a default page will be used
50$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); // if not set, $backtopage will be used
51$dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
52
53$error = 0;
54
55// Initialize a technical objects
56$object = new Fiscalyear($db);
57$extrafields = new ExtraFields($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 $result = $object->delete($user);
99 if ($result >= 0) {
100 header("Location: fiscalyear.php");
101 exit();
102 } else {
103 setEventMessages($object->error, $object->errors, 'errors');
104 }
105} elseif ($action == 'add' /* && $permissiontoadd // always true */) {
106 if (!GETPOST('cancel', 'alpha')) {
107 $error = 0;
108
109 $object->date_start = $date_start;
110 $object->date_end = $date_end;
111 $object->label = GETPOST('label', 'alpha');
112 $object->status = GETPOSTINT('status');
113 $object->datec = dol_now();
114
115 if (empty($object->date_start) && empty($object->date_end)) {
116 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
117 $error++;
118 }
119 if (empty($object->label)) {
120 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
121 $error++;
122 }
123
124 if (!$error) {
125 $db->begin();
126
127 $id = $object->create($user);
128 if ($id > 0) {
129 $db->commit();
130 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
131 exit;
132 } else {
133 $db->rollback();
134
135 // Handle overlap error
136 if ($id == -5 && !empty($object->errors[0])) {
137 setEventMessages($langs->trans($object->error, $object->errors[0]), null, 'errors');
138 } else {
139 setEventMessages($object->error, $object->errors, 'errors');
140 }
141 $action = 'create';
142 }
143 } else {
144 $action = 'create';
145 }
146 } else {
147 header("Location: ./fiscalyear.php");
148 exit;
149 }
150} elseif ($action == 'update' /* && $permissiontoadd // always true */) {
151 // Update record
152 if (!GETPOST('cancel', 'alpha')) {
153 $result = $object->fetch($id);
154
155 $object->date_start = GETPOST("fiscalyear") ? $date_start : '';
156 $object->date_end = GETPOST("fiscalyearend") ? $date_end : '';
157 $object->label = GETPOST('label', 'alpha');
158 $object->status = GETPOSTINT('status');
159
160 $result = $object->update($user);
161 if ($result > 0) {
162 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
163 exit;
164 } else {
165 // Handle overlap error
166 if ($result == -5 && !empty($object->errors[0])) {
167 setEventMessages($langs->trans($object->error, $object->errors[0]), null, 'errors');
168 } else {
169 setEventMessages($object->error, $object->errors, 'errors');
170 }
171 }
172 } else {
173 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
174 exit;
175 }
176} elseif ($action == 'reopen' /* && $permissiontoadd // always true */ && getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD')) {
177 $result = $object->fetch($id);
178
179 $object->status = GETPOSTINT('status');
180 $result = $object->update($user);
181
182 if ($result > 0) {
183 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
184 exit();
185 } else {
186 setEventMessages($object->error, $object->errors, 'errors');
187 }
188}
189
190
191/*
192 * View
193 */
194
195$form = new Form($db);
196
197$title = $langs->trans("Fiscalyear")." - ".$langs->trans("Card");
198if ($action == 'create') {
199 $title = $langs->trans("NewFiscalYear");
200}
201
202$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
203
204llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-fiscalyear');
205
206if ($action == 'create') {
207 print load_fiche_titre($title, '', 'object_'.$object->picto);
208
209 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
210 print '<input type="hidden" name="token" value="'.newToken().'">';
211 print '<input type="hidden" name="action" value="add">';
212
213 print dol_get_fiche_head(array(), '');
214
215 print '<table class="border centpercent tableforfieldcreate">'."\n";
216
217 // Label
218 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td>';
219 print '<input name="label" size="32" value="'.GETPOST('label', 'alpha').'">';
220 print '</td></tr>';
221
222 // Date start
223 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
224 print $form->selectDate(($date_start ? $date_start : ''), 'fiscalyear');
225 print '</td></tr>';
226
227 // Date end
228 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
229 print $form->selectDate(($date_end ? $date_end : - 1), 'fiscalyearend');
230 print '</td></tr>';
231
232 /*
233 // Status
234 print '<tr>';
235 print '<td class="fieldrequired">' . $langs->trans("Status") . '</td>';
236 print '<td class="valeur">';
237 print $form->selectarray('status', $status2label, GETPOST('status', 'int'));
238 print '</td></tr>';
239 */
240
241 // Common attributes
242 //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
243
244 // Other attributes
245 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
246
247 print '</table>'."\n";
248
249 print dol_get_fiche_end();
250
251 print $form->buttonsSaveCancel("Create");
252
253 print '</form>';
254
255 dol_set_focus('input[name="label"]');
256}
257
258
259// Part to edit record
260if (($id || $ref) && $action == 'edit') {
261 print load_fiche_titre($langs->trans("Fiscalyear"), '', 'object_'.$object->picto);
262
263 print '<form method="POST" name="update" action="'.$_SERVER["PHP_SELF"].'">'."\n";
264 print '<input type="hidden" name="token" value="'.newToken().'">';
265 print '<input type="hidden" name="action" value="update">';
266 print '<input type="hidden" name="status" value="' . $object->status . '">';
267 print '<input type="hidden" name="id" value="'.$object->id.'">';
268 if ($backtopage) {
269 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
270 }
271 if ($backtopageforcancel) {
272 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
273 }
274
275 print dol_get_fiche_head();
276
277 print '<table class="border centpercent tableforfieldedit">'."\n";
278
279 // Ref
280 print "<tr>";
281 print '<td class="titlefieldcreate titlefield">'.$langs->trans("Ref").'</td><td>';
282 print $object->ref;
283 print '</td></tr>';
284
285 // Label
286 print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
287 print '<input name="label" class="flat" size="32" value="'.$object->label.'">';
288 print '</td></tr>';
289
290 // Date start
291 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
292 print $form->selectDate($object->date_start ? $object->date_start : - 1, 'fiscalyear');
293 print '</td></tr>';
294
295 // Date end
296 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
297 print $form->selectDate($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
298 print '</td></tr>';
299
300 // Status
301 print '<tr><td>'.$langs->trans("Status").'</td><td>';
302 print $object->getLibStatut(4);
303 print '</td></tr>';
304
305 // Common attributes
306 //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
307
308 // Other attributes
309 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
310
311 print '</table>';
312
313 print dol_get_fiche_end();
314
315 print $form->buttonsSaveCancel();
316
317 print '</form>';
318}
319
320// Part to show record
321if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
322 $head = fiscalyear_prepare_head($object);
323
324 print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), -1, $object->picto, 0, '', '', 0, '', 1);
325
326 $morehtmlref = '';
327 //$morehtmlref .= '<div class="refidno">';
328 //$morehtmlref .= '</div>';
329
330 $formconfirm = '';
331
332 // Confirmation to delete
333 if ($action == 'delete') {
334 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete", '', 0, 1);
335 }
336
337 // Print form confirm
338 print $formconfirm;
339
340 // Object card
341 // ------------------------------------------------------------
342 $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/fiscalyear.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
343
344 dol_banner_tab($object, 'label', $linkback, 1, 'label', 'label', $morehtmlref);
345
346
347 print '<div class="fichecenter">';
348 print '<div class="fichehalfleft">';
349 print '<div class="underbanner clearboth"></div>';
350
351 print '<table class="border centpercent tableforfield">'."\n";
352
353 // Id
354 print "<tr>";
355 print '<td class="titlefield">'.$langs->trans("Id").'</td><td>';
356 print $object->id;
357 print '</td></tr>';
358
359 // Label
360 print '<tr><td class="tdtop">';
361 print $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'alpha:32');
362 print '</td><td>';
363 print $form->editfieldval("Label", 'label', $object->label, $object, 0, 'alpha:32');
364 print "</td></tr>";
365
366 // Date start
367 print '<tr><td>';
368 print $form->editfieldkey("DateStart", 'date_start', (string) $object->date_start, $object, 0, 'datepicker');
369 print '</td><td>';
370 print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, 0, 'datepicker');
371 print '</td></tr>';
372
373 // Date end
374 print '<tr><td>';
375 print $form->editfieldkey("DateEnd", 'date_end', (string) $object->date_end, $object, 0, 'datepicker');
376 print '</td><td>';
377 print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, 0, 'datepicker');
378 print '</td></tr>';
379
380 print '</table>';
381
382 print '</div>';
383 print '</div>';
384
385 print '<div class="clearboth"></div>';
386
387 print dol_get_fiche_end();
388
389
390 /*
391 * Action bar
392 */
393 if ($user->hasRight('accounting', 'fiscalyear', 'write')) {
394 print '<div class="tabsAction">';
395
396 if (getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD') && $object->status == $object::STATUS_CLOSED) {
397 print dolGetButtonAction($langs->trans("ReOpen"), '', 'reopen', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken(), 'reopen', (int) $permissiontoadd);
398 }
399
400 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
401
402 //print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
403
404 print '</div>';
405 }
406}
407
408// End of page
409llxFooter();
410$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 standard extra fields.
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.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.