dolibarr 22.0.5
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-2024 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';
28
29require_once DOL_DOCUMENT_ROOT.'/core/lib/fiscalyear.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/fiscalyear.class.php';
31
40// Load translation files required by the page
41$langs->loadLangs(array("admin", "compta"));
42
43// Get parameters
44$id = GETPOSTINT('id');
45$ref = GETPOST('ref', 'alpha');
46
47$action = GETPOST('action', 'aZ09');
48$confirm = GETPOST('confirm', 'alpha');
49$cancel = GETPOST('cancel');
50$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
51$backtopage = GETPOST('backtopage', 'alpha'); // if not set, a default page will be used
52$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); // if not set, $backtopage will be used
53$dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
54
55$error = 0;
56
57// Initialize a technical objects
58$object = new Fiscalyear($db);
59$extrafields = new ExtraFields($db);
60
61// Load object
62include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
63
64// List of status
65static $tmpstatus2label = array(
66 '0' => 'OpenFiscalYear',
67 '1' => 'CloseFiscalYear'
68);
69$status2label = array(
70 '' => ''
71);
72foreach ($tmpstatus2label as $key => $val) {
73 $status2label[$key] = $langs->trans($val);
74}
75
76$date_start = dol_mktime(0, 0, 0, GETPOSTINT('fiscalyearmonth'), GETPOSTINT('fiscalyearday'), GETPOSTINT('fiscalyearyear'));
77$date_end = dol_mktime(0, 0, 0, GETPOSTINT('fiscalyearendmonth'), GETPOSTINT('fiscalyearendday'), GETPOSTINT('fiscalyearendyear'));
78
79$permissiontoadd = $user->hasRight('accounting', 'fiscalyear', 'write');
80
81// Security check
82if ($user->socid > 0) {
84}
85if (!$permissiontoadd) {
87}
88
89
90/*
91 * Actions
92 */
93
94$parameters = array();
95$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
96if ($reshook < 0) {
97 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
98}
99
100if ($action == 'confirm_delete' && $confirm == "yes" && $permissiontoadd) {
101 $result = $object->delete($user);
102 if ($result >= 0) {
103 header("Location: fiscalyear.php");
104 exit();
105 } else {
106 setEventMessages($object->error, $object->errors, 'errors');
107 }
108} elseif ($action == 'add' && $permissiontoadd) {
109 if (!GETPOST('cancel', 'alpha')) {
110 $error = 0;
111
112 $object->date_start = $date_start;
113 $object->date_end = $date_end;
114 $object->label = GETPOST('label', 'alpha');
115 $object->status = GETPOSTINT('status');
116 $object->datec = dol_now();
117
118 if (empty($object->date_start) && empty($object->date_end)) {
119 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
120 $error++;
121 }
122 if (empty($object->label)) {
123 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
124 $error++;
125 }
126
127 if (!$error) {
128 $db->begin();
129
130 $id = $object->create($user);
131 if ($id > 0) {
132 $db->commit();
133 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
134 exit;
135 } else {
136 $db->rollback();
137
138 // Handle overlap error
139 if ($id == -5 && !empty($object->errors[0])) {
140 setEventMessages($langs->trans($object->error, $object->errors[0]), null, 'errors');
141 } else {
142 setEventMessages($object->error, $object->errors, 'errors');
143 }
144 $action = 'create';
145 }
146 } else {
147 $action = 'create';
148 }
149 } else {
150 header("Location: ./fiscalyear.php");
151 exit;
152 }
153} elseif ($action == 'update' && $permissiontoadd) {
154 // Update record
155 if (!GETPOST('cancel', 'alpha')) {
156 $result = $object->fetch($id);
157
158 $object->date_start = GETPOST("fiscalyear") ? $date_start : '';
159 $object->date_end = GETPOST("fiscalyearend") ? $date_end : '';
160 $object->label = GETPOST('label', 'alpha');
161 $object->status = GETPOSTINT('status');
162
163 $result = $object->update($user);
164 if ($result > 0) {
165 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
166 exit;
167 } else {
168 // Handle overlap error
169 if ($result == -5 && !empty($object->errors[0])) {
170 setEventMessages($langs->trans($object->error, $object->errors[0]), null, 'errors');
171 } else {
172 setEventMessages($object->error, $object->errors, 'errors');
173 }
174 }
175 } else {
176 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
177 exit;
178 }
179} elseif ($action == 'reopen' && $permissiontoadd && getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD')) {
180 $result = $object->fetch($id);
181
182 $object->status = GETPOSTINT('status');
183 $result = $object->update($user);
184
185 if ($result > 0) {
186 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
187 exit();
188 } else {
189 setEventMessages($object->error, $object->errors, 'errors');
190 }
191}
192
193
194/*
195 * View
196 */
197
198$form = new Form($db);
199
200$title = $langs->trans("Fiscalyear")." - ".$langs->trans("Card");
201if ($action == 'create') {
202 $title = $langs->trans("NewFiscalYear");
203}
204
205$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
206
207llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-fiscalyear');
208
209if ($action == 'create') {
210 print load_fiche_titre($title, '', 'object_'.$object->picto);
211
212 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
213 print '<input type="hidden" name="token" value="'.newToken().'">';
214 print '<input type="hidden" name="action" value="add">';
215
216 print dol_get_fiche_head(array(), '');
217
218 print '<table class="border centpercent tableforfieldcreate">'."\n";
219
220 // Label
221 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td>';
222 print '<input name="label" size="32" value="'.GETPOST('label', 'alpha').'">';
223 print '</td></tr>';
224
225 // Date start
226 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
227 print $form->selectDate(($date_start ? $date_start : ''), 'fiscalyear');
228 print '</td></tr>';
229
230 // Date end
231 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
232 print $form->selectDate(($date_end ? $date_end : - 1), 'fiscalyearend');
233 print '</td></tr>';
234
235 /*
236 // Status
237 print '<tr>';
238 print '<td class="fieldrequired">' . $langs->trans("Status") . '</td>';
239 print '<td class="valeur">';
240 print $form->selectarray('status', $status2label, GETPOST('status', 'int'));
241 print '</td></tr>';
242 */
243
244 // Common attributes
245 //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
246
247 // Other attributes
248 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
249
250 print '</table>'."\n";
251
252 print dol_get_fiche_end();
253
254 print $form->buttonsSaveCancel("Create");
255
256 print '</form>';
257
258 dol_set_focus('input[name="label"]');
259}
260
261
262// Part to edit record
263if (($id || $ref) && $action == 'edit') {
264 print load_fiche_titre($langs->trans("Fiscalyear"), '', 'object_'.$object->picto);
265
266 print '<form method="POST" name="update" action="'.$_SERVER["PHP_SELF"].'">'."\n";
267 print '<input type="hidden" name="token" value="'.newToken().'">';
268 print '<input type="hidden" name="action" value="update">';
269 print '<input type="hidden" name="status" value="' . $object->status . '">';
270 print '<input type="hidden" name="id" value="'.$object->id.'">';
271 if ($backtopage) {
272 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
273 }
274 if ($backtopageforcancel) {
275 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
276 }
277
278 print dol_get_fiche_head();
279
280 print '<table class="border centpercent tableforfieldedit">'."\n";
281
282 // Ref
283 print "<tr>";
284 print '<td class="titlefieldcreate titlefield">'.$langs->trans("Ref").'</td><td>';
285 print $object->ref;
286 print '</td></tr>';
287
288 // Label
289 print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
290 print '<input name="label" class="flat" size="32" value="'.$object->label.'">';
291 print '</td></tr>';
292
293 // Date start
294 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
295 print $form->selectDate($object->date_start ? $object->date_start : - 1, 'fiscalyear');
296 print '</td></tr>';
297
298 // Date end
299 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
300 print $form->selectDate($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
301 print '</td></tr>';
302
303 // Status
304 print '<tr><td>'.$langs->trans("Status").'</td><td>';
305 print $object->getLibStatut(4);
306 print '</td></tr>';
307
308 // Common attributes
309 //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
310
311 // Other attributes
312 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
313
314 print '</table>';
315
316 print dol_get_fiche_end();
317
318 print $form->buttonsSaveCancel();
319
320 print '</form>';
321}
322
323// Part to show record
324if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
325 $head = fiscalyear_prepare_head($object);
326
327 print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), -1, $object->picto, 0, '', '', 0, '', 1);
328
329 $morehtmlref = '';
330 //$morehtmlref .= '<div class="refidno">';
331 //$morehtmlref .= '</div>';
332
333 $formconfirm = '';
334
335 // Confirmation to delete
336 if ($action == 'delete') {
337 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete", '', 0, 1);
338 }
339
340 // Print form confirm
341 print $formconfirm;
342
343 // Object card
344 // ------------------------------------------------------------
345 $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/fiscalyear.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
346
347 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
348
349
350 print '<div class="fichecenter">';
351 print '<div class="fichehalfleft">';
352 print '<div class="underbanner clearboth"></div>';
353 print '<table class="border centpercent tableforfield">'."\n";
354
355 // Label
356 print '<tr><td class="tdtop">';
357 print $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'alpha:32');
358 print '</td><td>';
359 print $form->editfieldval("Label", 'label', $object->label, $object, 0, 'alpha:32');
360 print "</td></tr>";
361
362 // Date start
363 print '<tr><td>';
364 print $form->editfieldkey("DateStart", 'date_start', (string) $object->date_start, $object, 0, 'datepicker');
365 print '</td><td>';
366 print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, 0, 'datepicker');
367 print '</td></tr>';
368
369 // Date end
370 print '<tr><td>';
371 print $form->editfieldkey("DateEnd", 'date_end', (string) $object->date_end, $object, 0, 'datepicker');
372 print '</td><td>';
373 print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, 0, 'datepicker');
374 print '</td></tr>';
375
376 print '</table>';
377 print '</div>';
378 print '</div>';
379
380 print '<div class="clearboth"></div>';
381
382 print dol_get_fiche_end();
383
384
385 /*
386 * Action bar
387 */
388 if ($user->hasRight('accounting', 'fiscalyear', 'write')) {
389 print '<div class="tabsAction">';
390
391 if (getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD') && $object->status == $object::STATUS_CLOSED) {
392 print dolGetButtonAction($langs->trans("ReOpen"), '', 'reopen', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken(), 'reopen', (int) $permissiontoadd);
393 }
394
395 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
396
397 //print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
398
399 print '</div>';
400 }
401}
402
403// End of page
404llxFooter();
405$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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_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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_now($mode='auto')
Return date for now.
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.
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.