dolibarr 21.0.0-alpha
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-2024 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 = GETPOSTINT('id');
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 = preg_replace('/[^a-z0-9_]/i', '', $tmpbacktopagejsfields[0]);
50}
51
52$error = 0;
53
54// Initialize a 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, 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) {
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($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) {
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
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 = GETPOSTINT('status');
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 = GETPOSTINT('status');
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, '', 0, 0, '', '', '', 'mod-accountancy page-fiscalyear');
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(array(), '');
207
208 print '<table class="border centpercent tableforfieldcreate">'."\n";
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 // Common attributes
233 //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
234
235 // Other attributes
236 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
237
238 print '</table>'."\n";
239
240 print dol_get_fiche_end();
241
242 print $form->buttonsSaveCancel("Create");
243
244 print '</form>';
245
246 dol_set_focus('input[name="label"]');
247}
248
249
250// Part to edit record
251if (($id || $ref) && $action == 'edit') {
252 print load_fiche_titre($langs->trans("Fiscalyear"), '', 'object_'.$object->picto);
253
254 print '<form method="POST" name="update" action="'.$_SERVER["PHP_SELF"].'">'."\n";
255 print '<input type="hidden" name="token" value="'.newToken().'">';
256 print '<input type="hidden" name="action" value="update">';
257 print '<input type="hidden" name="id" value="'.$object->id.'">';
258 if ($backtopage) {
259 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
260 }
261 if ($backtopageforcancel) {
262 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
263 }
264
265 print dol_get_fiche_head();
266
267 print '<table class="border centpercent tableforfieldedit">'."\n";
268
269 // Ref
270 print "<tr>";
271 print '<td class="titlefieldcreate titlefield">'.$langs->trans("Ref").'</td><td>';
272 print $object->ref;
273 print '</td></tr>';
274
275 // Label
276 print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
277 print '<input name="label" class="flat" size="32" value="'.$object->label.'">';
278 print '</td></tr>';
279
280 // Date start
281 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
282 print $form->selectDate($object->date_start ? $object->date_start : - 1, 'fiscalyear');
283 print '</td></tr>';
284
285 // Date end
286 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
287 print $form->selectDate($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
288 print '</td></tr>';
289
290 // Status
291 print '<tr><td>'.$langs->trans("Status").'</td><td>';
292 print $object->getLibStatut(4);
293 print '</td></tr>';
294
295 // Common attributes
296 //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
297
298 // Other attributes
299 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
300
301 print '</table>';
302
303 print dol_get_fiche_end();
304
305 print $form->buttonsSaveCancel();
306
307 print '</form>';
308}
309
310// Part to show record
311if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
312 $head = fiscalyear_prepare_head($object);
313
314 print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), -1, $object->picto, 0, '', '', 0, '', 1);
315
316 $morehtmlref = '';
317 //$morehtmlref .= '<div class="refidno">';
318 //$morehtmlref .= '</div>';
319
320 $formconfirm = '';
321
322 // Confirmation to delete
323 if ($action == 'delete') {
324 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete", '', 0, 1);
325 }
326
327 // Print form confirm
328 print $formconfirm;
329
330 // Object card
331 // ------------------------------------------------------------
332 $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/fiscalyear.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
333
334 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
335
336
337 print '<div class="fichecenter">';
338 print '<div class="fichehalfleft">';
339 print '<div class="underbanner clearboth"></div>';
340 print '<table class="border centpercent tableforfield">'."\n";
341
342 // Label
343 print '<tr><td class="tdtop">';
344 print $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'alpha:32');
345 print '</td><td>';
346 print $form->editfieldval("Label", 'label', $object->label, $object, 0, 'alpha:32');
347 print "</td></tr>";
348
349 // Date start
350 print '<tr><td>';
351 print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, 0, 'datepicker');
352 print '</td><td>';
353 print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, 0, 'datepicker');
354 print '</td></tr>';
355
356 // Date end
357 print '<tr><td>';
358 print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, 0, 'datepicker');
359 print '</td><td>';
360 print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, 0, 'datepicker');
361 print '</td></tr>';
362
363 print '</table>';
364 print '</div>';
365 print '</div>';
366
367 print '<div class="clearboth"></div>';
368
369 print dol_get_fiche_end();
370
371
372 /*
373 * Action bar
374 */
375 if ($user->hasRight('accounting', 'fiscalyear', 'write')) {
376 print '<div class="tabsAction">';
377
378 if (getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD') && $object->status == $object::STATUS_CLOSED) {
379 print dolGetButtonAction($langs->trans("ReOpen"), '', 'reopen', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken(), 'reopen', $permissiontoadd);
380 }
381
382 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
383
384 //print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
385
386 print '</div>';
387 }
388}
389
390// End of page
391llxFooter();
392$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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:70
Class to manage standard extra fields.
Class to manage fiscal year.
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
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)
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.