dolibarr 21.0.0-beta
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@free.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
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');
45
46$action = GETPOST('action', 'aZ09');
47$confirm = GETPOST('confirm', 'alpha');
48$cancel = GETPOST('cancel', 'aZ09');
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$backtopagejsfields = GETPOST('backtopagejsfields', 'alpha');
53$dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
54
55if (!empty($backtopagejsfields)) {
56 $tmpbacktopagejsfields = explode(':', $backtopagejsfields);
57 $dol_openinpopup = preg_replace('/[^a-z0-9_]/i', '', $tmpbacktopagejsfields[0]);
58}
59
60$error = 0;
61
62// Initialize a technical objects
63$object = new Fiscalyear($db);
64$extrafields = new ExtraFields($db);
65
66// Load object
67include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
68
69// List of status
70static $tmpstatus2label = array(
71 '0' => 'OpenFiscalYear',
72 '1' => 'CloseFiscalYear'
73);
74$status2label = array(
75 '' => ''
76);
77foreach ($tmpstatus2label as $key => $val) {
78 $status2label[$key] = $langs->trans($val);
79}
80
81$date_start = dol_mktime(0, 0, 0, GETPOSTINT('fiscalyearmonth'), GETPOSTINT('fiscalyearday'), GETPOSTINT('fiscalyearyear'));
82$date_end = dol_mktime(0, 0, 0, GETPOSTINT('fiscalyearendmonth'), GETPOSTINT('fiscalyearendday'), GETPOSTINT('fiscalyearendyear'));
83
84$permissiontoadd = $user->hasRight('accounting', 'fiscalyear', 'write');
85
86// Security check
87if ($user->socid > 0) {
89}
90if (!$permissiontoadd) {
92}
93
94
95/*
96 * Actions
97 */
98
99$parameters = array();
100$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
101if ($reshook < 0) {
102 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
103}
104
105if ($action == 'confirm_delete' && $confirm == "yes" && $permissiontoadd) {
106 $result = $object->delete($user);
107 if ($result >= 0) {
108 header("Location: fiscalyear.php");
109 exit();
110 } else {
111 setEventMessages($object->error, $object->errors, 'errors');
112 }
113} elseif ($action == 'add' && $permissiontoadd) {
114 if (!GETPOST('cancel', 'alpha')) {
115 $error = 0;
116
117 $object->date_start = $date_start;
118 $object->date_end = $date_end;
119 $object->label = GETPOST('label', 'alpha');
120 $object->status = GETPOSTINT('status');
121 $object->datec = dol_now();
122
123 if (empty($object->date_start) && empty($object->date_end)) {
124 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
125 $error++;
126 }
127 if (empty($object->label)) {
128 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
129 $error++;
130 }
131
132 if (!$error) {
133 $db->begin();
134
135 $id = $object->create($user);
136
137 if ($id > 0) {
138 $db->commit();
139
140 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
141 exit();
142 } else {
143 $db->rollback();
144
145 setEventMessages($object->error, $object->errors, 'errors');
146 $action = 'create';
147 }
148 } else {
149 $action = 'create';
150 }
151 } else {
152 header("Location: ./fiscalyear.php");
153 exit();
154 }
155} elseif ($action == 'update' && $permissiontoadd) {
156 // Update record
157 if (!GETPOST('cancel', 'alpha')) {
158 $result = $object->fetch($id);
159
160 $object->date_start = GETPOST("fiscalyear") ? $date_start : '';
161 $object->date_end = GETPOST("fiscalyearend") ? $date_end : '';
162 $object->label = GETPOST('label', 'alpha');
163 $object->status = GETPOSTINT('status');
164
165 $result = $object->update($user);
166
167 if ($result > 0) {
168 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
169 exit();
170 } else {
171 setEventMessages($object->error, $object->errors, 'errors');
172 }
173 } else {
174 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
175 exit();
176 }
177} elseif ($action == 'reopen' && $permissiontoadd && 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="'.$_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><input name="label" size="32" value="'.GETPOST('label', 'alpha').'"></td></tr>';
220
221 // Date start
222 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
223 print $form->selectDate(($date_start ? $date_start : ''), 'fiscalyear');
224 print '</td></tr>';
225
226 // Date end
227 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
228 print $form->selectDate(($date_end ? $date_end : - 1), 'fiscalyearend');
229 print '</td></tr>';
230
231 /*
232 // Status
233 print '<tr>';
234 print '<td class="fieldrequired">' . $langs->trans("Status") . '</td>';
235 print '<td class="valeur">';
236 print $form->selectarray('status', $status2label, GETPOST('status', 'int'));
237 print '</td></tr>';
238 */
239
240 // Common attributes
241 //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
242
243 // Other attributes
244 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
245
246 print '</table>'."\n";
247
248 print dol_get_fiche_end();
249
250 print $form->buttonsSaveCancel("Create");
251
252 print '</form>';
253
254 dol_set_focus('input[name="label"]');
255}
256
257
258// Part to edit record
259if (($id || $ref) && $action == 'edit') {
260 print load_fiche_titre($langs->trans("Fiscalyear"), '', 'object_'.$object->picto);
261
262 print '<form method="POST" name="update" action="'.$_SERVER["PHP_SELF"].'">'."\n";
263 print '<input type="hidden" name="token" value="'.newToken().'">';
264 print '<input type="hidden" name="action" value="update">';
265 print '<input type="hidden" name="id" value="'.$object->id.'">';
266 if ($backtopage) {
267 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
268 }
269 if ($backtopageforcancel) {
270 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
271 }
272
273 print dol_get_fiche_head();
274
275 print '<table class="border centpercent tableforfieldedit">'."\n";
276
277 // Ref
278 print "<tr>";
279 print '<td class="titlefieldcreate titlefield">'.$langs->trans("Ref").'</td><td>';
280 print $object->ref;
281 print '</td></tr>';
282
283 // Label
284 print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
285 print '<input name="label" class="flat" size="32" value="'.$object->label.'">';
286 print '</td></tr>';
287
288 // Date start
289 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
290 print $form->selectDate($object->date_start ? $object->date_start : - 1, 'fiscalyear');
291 print '</td></tr>';
292
293 // Date end
294 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
295 print $form->selectDate($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
296 print '</td></tr>';
297
298 // Status
299 print '<tr><td>'.$langs->trans("Status").'</td><td>';
300 print $object->getLibStatut(4);
301 print '</td></tr>';
302
303 // Common attributes
304 //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
305
306 // Other attributes
307 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
308
309 print '</table>';
310
311 print dol_get_fiche_end();
312
313 print $form->buttonsSaveCancel();
314
315 print '</form>';
316}
317
318// Part to show record
319if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
320 $head = fiscalyear_prepare_head($object);
321
322 print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), -1, $object->picto, 0, '', '', 0, '', 1);
323
324 $morehtmlref = '';
325 //$morehtmlref .= '<div class="refidno">';
326 //$morehtmlref .= '</div>';
327
328 $formconfirm = '';
329
330 // Confirmation to delete
331 if ($action == 'delete') {
332 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete", '', 0, 1);
333 }
334
335 // Print form confirm
336 print $formconfirm;
337
338 // Object card
339 // ------------------------------------------------------------
340 $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/fiscalyear.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
341
342 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
343
344
345 print '<div class="fichecenter">';
346 print '<div class="fichehalfleft">';
347 print '<div class="underbanner clearboth"></div>';
348 print '<table class="border centpercent tableforfield">'."\n";
349
350 // Label
351 print '<tr><td class="tdtop">';
352 print $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'alpha:32');
353 print '</td><td>';
354 print $form->editfieldval("Label", 'label', $object->label, $object, 0, 'alpha:32');
355 print "</td></tr>";
356
357 // Date start
358 print '<tr><td>';
359 print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, 0, 'datepicker');
360 print '</td><td>';
361 print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, 0, 'datepicker');
362 print '</td></tr>';
363
364 // Date end
365 print '<tr><td>';
366 print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, 0, 'datepicker');
367 print '</td><td>';
368 print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, 0, 'datepicker');
369 print '</td></tr>';
370
371 print '</table>';
372 print '</div>';
373 print '</div>';
374
375 print '<div class="clearboth"></div>';
376
377 print dol_get_fiche_end();
378
379
380 /*
381 * Action bar
382 */
383 if ($user->hasRight('accounting', 'fiscalyear', 'write')) {
384 print '<div class="tabsAction">';
385
386 if (getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD') && $object->status == $object::STATUS_CLOSED) {
387 print dolGetButtonAction($langs->trans("ReOpen"), '', 'reopen', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken(), 'reopen', $permissiontoadd);
388 }
389
390 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
391
392 //print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
393
394 print '</div>';
395 }
396}
397
398// End of page
399llxFooter();
400$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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.