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") {
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') {
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') {
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}
170
171
172
173/*
174 * View
175 */
176
177$form = new Form($db);
178
179$title = $langs->trans("Fiscalyear")." - ".$langs->trans("Card");
180if ($action == 'create') {
181 $title = $langs->trans("NewFiscalYear");
182}
183
184$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
185
186llxHeader('', $title, $help_url);
187
188if ($action == 'create') {
189 print load_fiche_titre($title, '', 'object_'.$object->picto);
190
191 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
192 print '<input type="hidden" name="token" value="'.newToken().'">';
193 print '<input type="hidden" name="action" value="add">';
194
195 print dol_get_fiche_head();
196
197 print '<table class="border centpercent">';
198
199 // Label
200 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="32" value="'.GETPOST('label', 'alpha').'"></td></tr>';
201
202 // Date start
203 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
204 print $form->selectDate(($date_start ? $date_start : ''), 'fiscalyear');
205 print '</td></tr>';
206
207 // Date end
208 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
209 print $form->selectDate(($date_end ? $date_end : - 1), 'fiscalyearend');
210 print '</td></tr>';
211
212 /*
213 // Status
214 print '<tr>';
215 print '<td class="fieldrequired">' . $langs->trans("Status") . '</td>';
216 print '<td class="valeur">';
217 print $form->selectarray('status', $status2label, GETPOST('status', 'int'));
218 print '</td></tr>';
219 */
220
221 print '</table>';
222
223 print dol_get_fiche_end();
224
225 print $form->buttonsSaveCancel("Create");
226
227 print '</form>';
228}
229
230
231// Part to edit record
232if (($id || $ref) && $action == 'edit') {
233 print load_fiche_titre($langs->trans("Fiscalyear"), '', 'object_'.$object->picto);
234
235 print '<form method="POST" name="update" action="'.$_SERVER["PHP_SELF"].'">'."\n";
236 print '<input type="hidden" name="token" value="'.newToken().'">';
237 print '<input type="hidden" name="action" value="update">';
238 print '<input type="hidden" name="id" value="'.$object->id.'">';
239 if ($backtopage) {
240 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
241 }
242 if ($backtopageforcancel) {
243 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
244 }
245
246 print dol_get_fiche_head();
247
248 print '<table class="border centpercent tableforfieldedit">'."\n";
249
250 // Ref
251 print "<tr>";
252 print '<td class="titlefieldcreate titlefield">'.$langs->trans("Ref").'</td><td>';
253 print $object->ref;
254 print '</td></tr>';
255
256 // Label
257 print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
258 print '<input name="label" class="flat" size="32" value="'.$object->label.'">';
259 print '</td></tr>';
260
261 // Date start
262 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
263 print $form->selectDate($object->date_start ? $object->date_start : - 1, 'fiscalyear');
264 print '</td></tr>';
265
266 // Date end
267 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
268 print $form->selectDate($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
269 print '</td></tr>';
270
271 // Status
272 print '<tr><td>'.$langs->trans("Status").'</td><td>';
273 print $object->getLibStatut(4);
274 print '</td></tr>';
275
276 print '</table>';
277
278 print dol_get_fiche_end();
279
280 print $form->buttonsSaveCancel();
281
282 print '</form>';
283}
284
285// Part to show record
286if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
287 $head = fiscalyear_prepare_head($object);
288
289 print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'calendar');
290
291 $formconfirm = '';
292
293 // Confirmation to delete
294 if ($action == 'delete') {
295 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete", '', 0, 1);
296 }
297
298 // Print form confirm
299 print $formconfirm;
300
301 // Object card
302 // ------------------------------------------------------------
303 $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/fiscalyear.php">'.$langs->trans("BackToList").'</a>';
304
305 print '<table class="border centpercent">';
306
307 // Ref
308 print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td width="50%">';
309 print $object->ref;
310 print '</td><td>';
311 print $linkback;
312 print '</td></tr>';
313
314 // Label
315 print '<tr><td class="tdtop">';
316 print $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'alpha:32');
317 print '</td><td colspan="2">';
318 print $form->editfieldval("Label", 'label', $object->label, $object, 0, 'alpha:32');
319 print "</td></tr>";
320
321 // Date start
322 print '<tr><td>';
323 print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, 0, 'datepicker');
324 print '</td><td colspan="2">';
325 print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, 0, 'datepicker');
326 print '</td></tr>';
327
328 // Date end
329 print '<tr><td>';
330 print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, 0, 'datepicker');
331 print '</td><td colspan="2">';
332 print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, 0, 'datepicker');
333 print '</td></tr>';
334
335 // Status
336 print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">'.$object->getLibStatut(4).'</td></tr>';
337
338 print "</table>";
339
340 print dol_get_fiche_end();
341
342 /*
343 * Action bar
344 */
345 if ($user->hasRight('accounting', 'fiscalyear', 'write')) {
346 print '<div class="tabsAction">';
347
348 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
349
350 //print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
351
352 print '</div>';
353 }
354}
355
356// End of page
357llxFooter();
358$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.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.