dolibarr  9.0.0
fiscalyear_card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2014-2016 Alexandre Spangaro <aspangaro@zendsi.com>
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 <http://www.gnu.org/licenses/>.
17  */
18 
25 require '../../main.inc.php';
26 
27 require_once DOL_DOCUMENT_ROOT . '/core/lib/fiscalyear.lib.php';
28 require_once DOL_DOCUMENT_ROOT . '/core/class/fiscalyear.class.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array("admin","compta"));
32 
33 // Security check
34 if ($user->societe_id > 0)
36 if (empty($user->rights->accounting->fiscalyear))
38 
39 $error = 0;
40 
41 $action = GETPOST('action', 'aZ09');
42 $confirm = GETPOST('confirm', 'alpha');
43 $id = GETPOST('id', 'int');
44 
45 // List of statut
46 static $tmpstatut2label = array (
47  '0' => 'OpenFiscalYear',
48  '1' => 'CloseFiscalYear'
49 );
50 $statut2label = array (
51  ''
52 );
53 foreach ( $tmpstatut2label as $key => $val )
54  $statut2label[$key] = $langs->trans($val);
55 
56 $object = new Fiscalyear($db);
57 
58 $date_start = dol_mktime(0, 0, 0, GETPOST('fiscalyearmonth', 'int'), GETPOST('fiscalyearday', 'int'), GETPOST('fiscalyearyear', 'int'));
59 $date_end = dol_mktime(0, 0, 0, GETPOST('fiscalyearendmonth', 'int'), GETPOST('fiscalyearendday', 'int'), GETPOST('fiscalyearendyear', 'int'));
60 
61 
62 /*
63  * Actions
64  */
65 
66 if ($action == 'confirm_delete' && $confirm == "yes") {
67  $result = $object->delete($id);
68  if ($result >= 0) {
69  header("Location: fiscalyear.php");
70  exit();
71  } else {
72  setEventMessages($object->error, $object->errors, 'errors');
73  }
74 }
75 
76 else if ($action == 'add') {
77  if (! GETPOST('cancel', 'alpha')) {
78  $error = 0;
79 
80  $object->date_start = $date_start;
81  $object->date_end = $date_end;
82  $object->label = GETPOST('label', 'alpha');
83  $object->statut = GETPOST('statut', 'int');
84  $object->datec = dol_now();
85 
86  if (empty($object->date_start) && empty($object->date_end)) {
87  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
88  $error ++;
89  }
90  if (empty($object->label)) {
91  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
92  $error ++;
93  }
94 
95  if (! $error) {
96  $db->begin();
97 
98  $id = $object->create($user);
99 
100  if ($id > 0) {
101  $db->commit();
102 
103  header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
104  exit();
105  } else {
106  $db->rollback();
107 
108  setEventMessages($object->error, $object->errors, 'errors');
109  $action = 'create';
110  }
111  } else {
112  $action = 'create';
113  }
114  } else {
115  header("Location: ./fiscalyear.php");
116  exit();
117  }
118 }
119 
120 // Update record
121 else if ($action == 'update') {
122  if (! GETPOST('cancel', 'alpha')) {
123  $result = $object->fetch($id);
124 
125  $object->date_start = empty($_POST["fiscalyear"]) ? '' : $date_start;
126  $object->date_end = empty($_POST["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 $helpurl = "";
154 llxHeader("",$title,$helpurl);
155 
156 if ($action == 'create')
157 {
158  print load_fiche_titre($langs->trans("NewFiscalYear"));
159 
160  print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
161  print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
162  print '<input type="hidden" name="action" value="add">';
163 
164  dol_fiche_head();
165 
166  print '<table class="border" width="100%">';
167 
168  // Label
169  print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans("Label") . '</td><td><input name="label" size="32" value="' . GETPOST('label', 'alpha') . '"></td></tr>';
170 
171  // Date start
172  print '<tr><td class="fieldrequired">' . $langs->trans("DateStart") . '</td><td>';
173  print $form->selectDate(($date_start ? $date_start : ''), 'fiscalyear');
174  print '</td></tr>';
175 
176  // Date end
177  print '<tr><td class="fieldrequired">' . $langs->trans("DateEnd") . '</td><td>';
178  print $form->selectDate(($date_end ? $date_end : - 1), 'fiscalyearend');
179  print '</td></tr>';
180 
181  /*
182  // Statut
183  print '<tr>';
184  print '<td class="fieldrequired">' . $langs->trans("Status") . '</td>';
185  print '<td class="valeur">';
186  print $form->selectarray('statut', $statut2label, GETPOST('statut', 'int'));
187  print '</td></tr>';
188  */
189 
190  print '</table>';
191 
192  dol_fiche_end();
193 
194  print '<div class="center">';
195  print '<input class="button" type="submit" value="' . $langs->trans("Save") . '">';
196  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
197  print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
198  print '</div>';
199 
200  print '</form>';
201 } else if ($id) {
202  $result = $object->fetch($id);
203  if ($result > 0) {
204  $head = fiscalyear_prepare_head($object);
205 
206  if ($action == 'edit') {
207  dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron');
208 
209  print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
210  print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
211  print '<input type="hidden" name="action" value="update">';
212  print '<input type="hidden" name="id" value="' . $id . '">';
213 
214  print '<table class="border" width="100%">';
215 
216  // Ref
217  print "<tr>";
218  print '<td class="titlefieldcreate titlefield">' . $langs->trans("Ref") . '</td><td>';
219  print $object->ref;
220  print '</td></tr>';
221 
222  // Label
223  print '<tr><td class="fieldrequired">' . $langs->trans("Label") . '</td><td>';
224  print '<input name="label" class="flat" size="32" value="' . $object->label . '">';
225  print '</td></tr>';
226 
227  // Date start
228  print '<tr><td class="fieldrequired">' . $langs->trans("DateStart") . '</td><td>';
229  print $form->selectDate($object->date_start ? $object->date_start : - 1, 'fiscalyear');
230  print '</td></tr>';
231 
232  // Date end
233  print '<tr><td class="fieldrequired">' . $langs->trans("DateEnd") . '</td><td>';
234  print $form->selectDate($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
235  print '</td></tr>';
236 
237  // Statut
238  print '<tr><td>' . $langs->trans("Statut") . '</td><td>';
239  // print $form->selectarray('statut', $statut2label, $object->statut);
240  print $object->getLibStatut(4);
241  print '</td></tr>';
242 
243  print '</table>';
244 
245  print '<br><div class="center">';
246  print '<input type="submit" class="button" value="' . $langs->trans("Save") . '">';
247  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
248  print '<input type="submit" name="cancel" class="button" value="' . $langs->trans("Cancel") . '">';
249  print '</div>';
250 
251  print '</form>';
252 
253  dol_fiche_end();
254  } else {
255  /*
256  * Confirm delete
257  */
258  if ($action == 'delete') {
259  print $form->formconfirm($_SERVER["PHP_SELF"] . "?id=" . $id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete");
260  }
261 
262  dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron');
263 
264  print '<table class="border" width="100%">';
265 
266  $linkback = '<a href="' . DOL_URL_ROOT . '/accountancy/admin/fiscalyear.php">' . $langs->trans("BackToList") . '</a>';
267 
268  // Ref
269  print '<tr><td class="titlefield">' . $langs->trans("Ref") . '</td><td width="50%">';
270  print $object->ref;
271  print '</td><td>';
272  print $linkback;
273  print '</td></tr>';
274 
275  // Label
276  print '<tr><td class="tdtop">';
277  print $form->editfieldkey("Label", 'label', $object->label, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'alpha:32');
278  print '</td><td colspan="2">';
279  print $form->editfieldval("Label", 'label', $object->label, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'alpha:32');
280  print "</td></tr>";
281 
282  // Date start
283  print '<tr><td>';
284  print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
285  print '</td><td colspan="2">';
286  print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
287  print '</td></tr>';
288 
289  // Date end
290  print '<tr><td>';
291  print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
292  print '</td><td colspan="2">';
293  print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
294  print '</td></tr>';
295 
296  // Statut
297  print '<tr><td>' . $langs->trans("Status") . '</td><td colspan="2">' . $object->getLibStatut(4) . '</td></tr>';
298 
299  print "</table>";
300 
301  dol_fiche_end();
302 
303  if (! empty($user->rights->accounting->fiscalyear))
304  {
305  /*
306  * Barre d'actions
307  */
308  print '<div class="tabsAction">';
309 
310  print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=edit&id=' . $id . '">' . $langs->trans('Modify') . '</a>';
311 
312  // print '<a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?action=delete&id=' . $id . '">' . $langs->trans('Delete') . '</a>';
313 
314  print '</div>';
315  }
316  }
317  } else {
318  dol_print_error($db);
319  }
320 }
321 
322 // End of page
323 llxFooter();
324 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
fiscalyear_prepare_head(Fiscalyear $object)
Prepare array with list of tabs.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_fiche_end($notab=0)
Show tab footer of a card.
Class to manage fiscal year.
llxHeader()
Empty header.
Definition: wrapper.php:44
dol_now($mode='gmt')
Return date for now.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.