dolibarr 18.0.6
fiscalyear_card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
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// Security check
35if ($user->socid > 0) {
37}
38if (!$user->hasRight('accounting', 'fiscalyear', 'write')) {
40}
41
42$error = 0;
43
44$action = GETPOST('action', 'aZ09');
45$confirm = GETPOST('confirm', 'alpha');
46$id = GETPOST('id', 'int');
47
48// List of statut
49static $tmpstatut2label = array(
50 '0' => 'OpenFiscalYear',
51 '1' => 'CloseFiscalYear'
52);
53$statut2label = array(
54 ''
55);
56foreach ($tmpstatut2label as $key => $val) {
57 $statut2label[$key] = $langs->trans($val);
58}
59
60$object = new Fiscalyear($db);
61
62$date_start = dol_mktime(0, 0, 0, GETPOST('fiscalyearmonth', 'int'), GETPOST('fiscalyearday', 'int'), GETPOST('fiscalyearyear', 'int'));
63$date_end = dol_mktime(0, 0, 0, GETPOST('fiscalyearendmonth', 'int'), GETPOST('fiscalyearendday', 'int'), GETPOST('fiscalyearendyear', 'int'));
64
65
66/*
67 * Actions
68 */
69
70if ($action == 'confirm_delete' && $confirm == "yes") {
71 $result = $object->delete($id);
72 if ($result >= 0) {
73 header("Location: fiscalyear.php");
74 exit();
75 } else {
76 setEventMessages($object->error, $object->errors, 'errors');
77 }
78} elseif ($action == 'add') {
79 if (!GETPOST('cancel', 'alpha')) {
80 $error = 0;
81
82 $object->date_start = $date_start;
83 $object->date_end = $date_end;
84 $object->label = GETPOST('label', 'alpha');
85 $object->statut = GETPOST('statut', 'int');
86 $object->datec = dol_now();
87
88 if (empty($object->date_start) && empty($object->date_end)) {
89 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
90 $error++;
91 }
92 if (empty($object->label)) {
93 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
94 $error++;
95 }
96
97 if (!$error) {
98 $db->begin();
99
100 $id = $object->create($user);
101
102 if ($id > 0) {
103 $db->commit();
104
105 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
106 exit();
107 } else {
108 $db->rollback();
109
110 setEventMessages($object->error, $object->errors, 'errors');
111 $action = 'create';
112 }
113 } else {
114 $action = 'create';
115 }
116 } else {
117 header("Location: ./fiscalyear.php");
118 exit();
119 }
120} elseif ($action == 'update') {
121 // Update record
122 if (!GETPOST('cancel', 'alpha')) {
123 $result = $object->fetch($id);
124
125 $object->date_start = GETPOST("fiscalyear") ? $date_start : '';
126 $object->date_end = GETPOST("fiscalyearend") ? $date_end : '';
127 $object->label = GETPOST('label', 'alpha');
128 $object->statut = GETPOST('statut', 'int');
129
130 $result = $object->update($user);
131
132 if ($result > 0) {
133 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
134 exit();
135 } else {
136 setEventMessages($object->error, $object->errors, 'errors');
137 }
138 } else {
139 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
140 exit();
141 }
142}
143
144
145
146/*
147 * View
148 */
149
150$form = new Form($db);
151
152$title = $langs->trans("Fiscalyear")." - ".$langs->trans("Card");
153
154$help_url = "EN:Module_Double_Entry_Accounting";
155
156llxHeader('', $title, $help_url);
157
158if ($action == 'create') {
159 print load_fiche_titre($langs->trans("NewFiscalYear"));
160
161 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
162 print '<input type="hidden" name="token" value="'.newToken().'">';
163 print '<input type="hidden" name="action" value="add">';
164
165 print dol_get_fiche_head();
166
167 print '<table class="border centpercent">';
168
169 // Label
170 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="32" value="'.GETPOST('label', 'alpha').'"></td></tr>';
171
172 // Date start
173 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
174 print $form->selectDate(($date_start ? $date_start : ''), 'fiscalyear');
175 print '</td></tr>';
176
177 // Date end
178 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
179 print $form->selectDate(($date_end ? $date_end : - 1), 'fiscalyearend');
180 print '</td></tr>';
181
182 /*
183 // Statut
184 print '<tr>';
185 print '<td class="fieldrequired">' . $langs->trans("Status") . '</td>';
186 print '<td class="valeur">';
187 print $form->selectarray('statut', $statut2label, GETPOST('statut', 'int'));
188 print '</td></tr>';
189 */
190
191 print '</table>';
192
193 print dol_get_fiche_end();
194
195 print '<div class="center">';
196 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
197 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
198 print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
199 print '</div>';
200
201 print '</form>';
202} elseif ($id) {
203 $result = $object->fetch($id);
204 if ($result > 0) {
205 $head = fiscalyear_prepare_head($object);
206
207 if ($action == 'edit') {
208 print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron');
209
210 print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
211 print '<input type="hidden" name="token" value="'.newToken().'">';
212 print '<input type="hidden" name="action" value="update">';
213 print '<input type="hidden" name="id" value="'.$id.'">';
214
215 print '<table class="border centpercent">';
216
217 // Ref
218 print "<tr>";
219 print '<td class="titlefieldcreate titlefield">'.$langs->trans("Ref").'</td><td>';
220 print $object->ref;
221 print '</td></tr>';
222
223 // Label
224 print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
225 print '<input name="label" class="flat" size="32" value="'.$object->label.'">';
226 print '</td></tr>';
227
228 // Date start
229 print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
230 print $form->selectDate($object->date_start ? $object->date_start : - 1, 'fiscalyear');
231 print '</td></tr>';
232
233 // Date end
234 print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
235 print $form->selectDate($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
236 print '</td></tr>';
237
238 // Statut
239 print '<tr><td>'.$langs->trans("Statut").'</td><td>';
240 // print $form->selectarray('statut', $statut2label, $object->statut);
241 print $object->getLibStatut(4);
242 print '</td></tr>';
243
244 print '</table>';
245
246 print $form->buttonsSaveCancel();
247
248 print '</form>';
249
250 print dol_get_fiche_end();
251 } else {
252 /*
253 * Confirm delete
254 */
255 if ($action == 'delete') {
256 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete");
257 }
258
259 print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron');
260
261 print '<table class="border centpercent">';
262
263 $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/fiscalyear.php">'.$langs->trans("BackToList").'</a>';
264
265 // Ref
266 print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td width="50%">';
267 print $object->ref;
268 print '</td><td>';
269 print $linkback;
270 print '</td></tr>';
271
272 // Label
273 print '<tr><td class="tdtop">';
274 print $form->editfieldkey("Label", 'label', $object->label, $object, 1, 'alpha:32');
275 print '</td><td colspan="2">';
276 print $form->editfieldval("Label", 'label', $object->label, $object, 1, 'alpha:32');
277 print "</td></tr>";
278
279 // Date start
280 print '<tr><td>';
281 print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, 1, 'datepicker');
282 print '</td><td colspan="2">';
283 print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, 1, 'datepicker');
284 print '</td></tr>';
285
286 // Date end
287 print '<tr><td>';
288 print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, 1, 'datepicker');
289 print '</td><td colspan="2">';
290 print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, 1, 'datepicker');
291 print '</td></tr>';
292
293 // Statut
294 print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">'.$object->getLibStatut(4).'</td></tr>';
295
296 print "</table>";
297
298 print dol_get_fiche_end();
299
300 /*
301 * Action bar
302 */
303 if ($user->hasRight('accounting', 'fiscalyear', 'write')) {
304 print '<div class="tabsAction">';
305
306 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
307
308 //print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
309
310 print '</div>';
311 }
312 }
313 } else {
314 dol_print_error($db);
315 }
316}
317
318// End of page
319llxFooter();
320$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:56
llxFooter()
Empty footer.
Definition wrapper.php:70
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.