dolibarr 19.0.3
fiscalyear_card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014-2024 Alexandre Spangaro <aspangaro@easya.solutions>
3 * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.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/fiscalyear.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/fiscalyear.class.php';
30
31// Load translation files required by the page
32$langs->loadLangs(array("admin", "compta"));
33
34// Get parameters
35$id = GETPOST('id', 'int');
36$ref = GETPOST('ref', 'alpha');
37
38$action = GETPOST('action', 'aZ09');
39$confirm = GETPOST('confirm', 'alpha');
40$cancel = GETPOST('cancel', 'aZ09');
41$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
42$backtopage = GETPOST('backtopage', 'alpha'); // if not set, a default page will be used
43$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); // if not set, $backtopage will be used
44$backtopagejsfields = GETPOST('backtopagejsfields', 'alpha');
45$dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
46
47if (!empty($backtopagejsfields)) {
48 $tmpbacktopagejsfields = explode(':', $backtopagejsfields);
49 $dol_openinpopup = $tmpbacktopagejsfields[0];
50}
51
52$error = 0;
53
54// Initialize technical objects
55$object = new Fiscalyear($db);
56$extrafields = new ExtraFields($db);
57
58// Load object
59include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
60
61// List of status
62static $tmpstatus2label = array(
63 '0' => 'OpenFiscalYear',
64 '1' => 'CloseFiscalYear'
65);
66$status2label = array(
67 ''
68);
69foreach ($tmpstatus2label as $key => $val) {
70 $status2label[$key] = $langs->trans($val);
71}
72
73$date_start = dol_mktime(0, 0, 0, GETPOST('fiscalyearmonth', 'int'), GETPOST('fiscalyearday', 'int'), GETPOST('fiscalyearyear', 'int'));
74$date_end = dol_mktime(0, 0, 0, GETPOST('fiscalyearendmonth', 'int'), GETPOST('fiscalyearendday', 'int'), GETPOST('fiscalyearendyear', 'int'));
75
76$permissiontoadd = $user->hasRight('accounting', 'fiscalyear', 'write');
77
78// Security check
79if ($user->socid > 0) {
81}
82if (!$permissiontoadd) {
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) {
98 $result = $object->delete($id);
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) {
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 = GETPOST('status', 'int');
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
129 if ($id > 0) {
130 $db->commit();
131
132 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
133 exit();
134 } else {
135 $db->rollback();
136
137 setEventMessages($object->error, $object->errors, 'errors');
138 $action = 'create';
139 }
140 } else {
141 $action = 'create';
142 }
143 } else {
144 header("Location: ./fiscalyear.php");
145 exit();
146 }
147} elseif ($action == 'update' && $permissiontoadd) {
148 // Update record
149 if (!GETPOST('cancel', 'alpha')) {
150 $result = $object->fetch($id);
151
152 $object->date_start = GETPOST("fiscalyear") ? $date_start : '';
153 $object->date_end = GETPOST("fiscalyearend") ? $date_end : '';
154 $object->label = GETPOST('label', 'alpha');
155 $object->status = GETPOST('status', 'int');
156
157 $result = $object->update($user);
158
159 if ($result > 0) {
160 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
161 exit();
162 } else {
163 setEventMessages($object->error, $object->errors, 'errors');
164 }
165 } else {
166 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
167 exit();
168 }
169} elseif ($action == 'reopen' && $permissiontoadd && getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD')) {
170 $result = $object->fetch($id);
171
172 $object->status = GETPOST('status', 'int');
173 $result = $object->update($user);
174
175 if ($result > 0) {
176 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
177 exit();
178 } else {
179 setEventMessages($object->error, $object->errors, 'errors');
180 }
181}
182
183
184/*
185 * View
186 */
187
188$form = new Form($db);
189
190$title = $langs->trans("Fiscalyear")." - ".$langs->trans("Card");
191if ($action == 'create') {
192 $title = $langs->trans("NewFiscalYear");
193}
194
195$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
196
197llxHeader('', $title, $help_url);
198
199if ($action == 'create') {
200 print load_fiche_titre($title, '', 'object_'.$object->picto);
201
202 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
203 print '<input type="hidden" name="token" value="'.newToken().'">';
204 print '<input type="hidden" name="action" value="add">';
205
206 print dol_get_fiche_head();
207
208 print '<table class="border centpercent">';
209
210 // Label
211 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="32" value="'.GETPOST('label', 'alpha').'"></td></tr>';
212
213 // Date start
214 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
215 print $form->selectDate(($date_start ? $date_start : ''), 'fiscalyear');
216 print '</td></tr>';
217
218 // Date end
219 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
220 print $form->selectDate(($date_end ? $date_end : - 1), 'fiscalyearend');
221 print '</td></tr>';
222
223 /*
224 // Status
225 print '<tr>';
226 print '<td class="fieldrequired">' . $langs->trans("Status") . '</td>';
227 print '<td class="valeur">';
228 print $form->selectarray('status', $status2label, GETPOST('status', 'int'));
229 print '</td></tr>';
230 */
231
232 print '</table>';
233
234 print dol_get_fiche_end();
235
236 print $form->buttonsSaveCancel("Create");
237
238 print '</form>';
239}
240
241
242// Part to edit record
243if (($id || $ref) && $action == 'edit') {
244 print load_fiche_titre($langs->trans("Fiscalyear"), '', 'object_'.$object->picto);
245
246 print '<form method="POST" name="update" action="'.$_SERVER["PHP_SELF"].'">'."\n";
247 print '<input type="hidden" name="token" value="'.newToken().'">';
248 print '<input type="hidden" name="action" value="update">';
249 print '<input type="hidden" name="id" value="'.$object->id.'">';
250 if ($backtopage) {
251 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
252 }
253 if ($backtopageforcancel) {
254 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
255 }
256
257 print dol_get_fiche_head();
258
259 print '<table class="border centpercent tableforfieldedit">'."\n";
260
261 // Ref
262 print "<tr>";
263 print '<td class="titlefieldcreate titlefield">'.$langs->trans("Ref").'</td><td>';
264 print $object->ref;
265 print '</td></tr>';
266
267 // Label
268 print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
269 print '<input name="label" class="flat" size="32" value="'.$object->label.'">';
270 print '</td></tr>';
271
272 // Date start
273 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
274 print $form->selectDate($object->date_start ? $object->date_start : - 1, 'fiscalyear');
275 print '</td></tr>';
276
277 // Date end
278 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
279 print $form->selectDate($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
280 print '</td></tr>';
281
282 // Status
283 print '<tr><td>'.$langs->trans("Status").'</td><td>';
284 print $object->getLibStatut(4);
285 print '</td></tr>';
286
287 print '</table>';
288
289 print dol_get_fiche_end();
290
291 print $form->buttonsSaveCancel();
292
293 print '</form>';
294}
295
296// Part to show record
297if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
298 $head = fiscalyear_prepare_head($object);
299
300 print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'calendar');
301
302 $formconfirm = '';
303
304 // Confirmation to delete
305 if ($action == 'delete') {
306 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete", '', 0, 1);
307 }
308
309 // Print form confirm
310 print $formconfirm;
311
312 // Object card
313 // ------------------------------------------------------------
314 $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/fiscalyear.php">'.$langs->trans("BackToList").'</a>';
315
316 print '<table class="border centpercent">';
317
318 // Ref
319 print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td width="50%">';
320 print $object->ref;
321 print '</td><td>';
322 print $linkback;
323 print '</td></tr>';
324
325 // Label
326 print '<tr><td class="tdtop">';
327 print $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'alpha:32');
328 print '</td><td colspan="2">';
329 print $form->editfieldval("Label", 'label', $object->label, $object, 0, 'alpha:32');
330 print "</td></tr>";
331
332 // Date start
333 print '<tr><td>';
334 print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, 0, 'datepicker');
335 print '</td><td colspan="2">';
336 print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, 0, 'datepicker');
337 print '</td></tr>';
338
339 // Date end
340 print '<tr><td>';
341 print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, 0, 'datepicker');
342 print '</td><td colspan="2">';
343 print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, 0, 'datepicker');
344 print '</td></tr>';
345
346 // Status
347 print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">'.$object->getLibStatut(4).'</td></tr>';
348
349 print "</table>";
350
351 print dol_get_fiche_end();
352
353 /*
354 * Action bar
355 */
356 if ($user->hasRight('accounting', 'fiscalyear', 'write')) {
357 print '<div class="tabsAction">';
358
359 if (getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD') && $object->status == $object::STATUS_CLOSED) {
360 print dolGetButtonAction($langs->trans("ReOpen"), '', 'reopen', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken(), 'reopen', $permissiontoadd);
361 }
362
363 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
364
365 //print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
366
367 print '</div>';
368 }
369}
370
371// End of page
372llxFooter();
373$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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 informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return 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.