dolibarr  13.0.2
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 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->socid > 0)
36 if (empty($user->rights->accounting->fiscalyear->write))
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 } elseif ($action == 'add') {
75  if (!GETPOST('cancel', 'alpha')) {
76  $error = 0;
77 
78  $object->date_start = $date_start;
79  $object->date_end = $date_end;
80  $object->label = GETPOST('label', 'alpha');
81  $object->statut = GETPOST('statut', 'int');
82  $object->datec = dol_now();
83 
84  if (empty($object->date_start) && empty($object->date_end)) {
85  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
86  $error++;
87  }
88  if (empty($object->label)) {
89  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
90  $error++;
91  }
92 
93  if (!$error) {
94  $db->begin();
95 
96  $id = $object->create($user);
97 
98  if ($id > 0) {
99  $db->commit();
100 
101  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
102  exit();
103  } else {
104  $db->rollback();
105 
106  setEventMessages($object->error, $object->errors, 'errors');
107  $action = 'create';
108  }
109  } else {
110  $action = 'create';
111  }
112  } else {
113  header("Location: ./fiscalyear.php");
114  exit();
115  }
116 }
117 
118 // Update record
119 elseif ($action == 'update') {
120  if (!GETPOST('cancel', 'alpha')) {
121  $result = $object->fetch($id);
122 
123  $object->date_start = empty($_POST["fiscalyear"]) ? '' : $date_start;
124  $object->date_end = empty($_POST["fiscalyearend"]) ? '' : $date_end;
125  $object->label = GETPOST('label', 'alpha');
126  $object->statut = GETPOST('statut', 'int');
127 
128  $result = $object->update($user);
129 
130  if ($result > 0) {
131  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
132  exit();
133  } else {
134  setEventMessages($object->error, $object->errors, 'errors');
135  }
136  } else {
137  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
138  exit();
139  }
140 }
141 
142 
143 
144 /*
145  * View
146  */
147 
148 $form = new Form($db);
149 
150 $title = $langs->trans("Fiscalyear")." - ".$langs->trans("Card");
151 $helpurl = "";
152 llxHeader("", $title, $helpurl);
153 
154 if ($action == 'create')
155 {
156  print load_fiche_titre($langs->trans("NewFiscalYear"));
157 
158  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
159  print '<input type="hidden" name="token" value="'.newToken().'">';
160  print '<input type="hidden" name="action" value="add">';
161 
163 
164  print '<table class="border centpercent">';
165 
166  // Label
167  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="32" value="'.GETPOST('label', 'alpha').'"></td></tr>';
168 
169  // Date start
170  print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
171  print $form->selectDate(($date_start ? $date_start : ''), 'fiscalyear');
172  print '</td></tr>';
173 
174  // Date end
175  print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
176  print $form->selectDate(($date_end ? $date_end : - 1), 'fiscalyearend');
177  print '</td></tr>';
178 
179  /*
180  // Statut
181  print '<tr>';
182  print '<td class="fieldrequired">' . $langs->trans("Status") . '</td>';
183  print '<td class="valeur">';
184  print $form->selectarray('statut', $statut2label, GETPOST('statut', 'int'));
185  print '</td></tr>';
186  */
187 
188  print '</table>';
189 
191 
192  print '<div class="center">';
193  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
194  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
195  print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
196  print '</div>';
197 
198  print '</form>';
199 } elseif ($id) {
200  $result = $object->fetch($id);
201  if ($result > 0) {
202  $head = fiscalyear_prepare_head($object);
203 
204  if ($action == 'edit') {
205  print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron');
206 
207  print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
208  print '<input type="hidden" name="token" value="'.newToken().'">';
209  print '<input type="hidden" name="action" value="update">';
210  print '<input type="hidden" name="id" value="'.$id.'">';
211 
212  print '<table class="border centpercent">';
213 
214  // Ref
215  print "<tr>";
216  print '<td class="titlefieldcreate titlefield">'.$langs->trans("Ref").'</td><td>';
217  print $object->ref;
218  print '</td></tr>';
219 
220  // Label
221  print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
222  print '<input name="label" class="flat" size="32" value="'.$object->label.'">';
223  print '</td></tr>';
224 
225  // Date start
226  print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
227  print $form->selectDate($object->date_start ? $object->date_start : - 1, 'fiscalyear');
228  print '</td></tr>';
229 
230  // Date end
231  print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
232  print $form->selectDate($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
233  print '</td></tr>';
234 
235  // Statut
236  print '<tr><td>'.$langs->trans("Statut").'</td><td>';
237  // print $form->selectarray('statut', $statut2label, $object->statut);
238  print $object->getLibStatut(4);
239  print '</td></tr>';
240 
241  print '</table>';
242 
243  print '<br><div class="center">';
244  print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
245  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
246  print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
247  print '</div>';
248 
249  print '</form>';
250 
252  } else {
253  /*
254  * Confirm delete
255  */
256  if ($action == 'delete') {
257  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete");
258  }
259 
260  print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron');
261 
262  print '<table class="border centpercent">';
263 
264  $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/fiscalyear.php">'.$langs->trans("BackToList").'</a>';
265 
266  // Ref
267  print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td width="50%">';
268  print $object->ref;
269  print '</td><td>';
270  print $linkback;
271  print '</td></tr>';
272 
273  // Label
274  print '<tr><td class="tdtop">';
275  print $form->editfieldkey("Label", 'label', $object->label, $object, 1, 'alpha:32');
276  print '</td><td colspan="2">';
277  print $form->editfieldval("Label", 'label', $object->label, $object, 1, 'alpha:32');
278  print "</td></tr>";
279 
280  // Date start
281  print '<tr><td>';
282  print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, 1, 'datepicker');
283  print '</td><td colspan="2">';
284  print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, 1, 'datepicker');
285  print '</td></tr>';
286 
287  // Date end
288  print '<tr><td>';
289  print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, 1, 'datepicker');
290  print '</td><td colspan="2">';
291  print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, 1, 'datepicker');
292  print '</td></tr>';
293 
294  // Statut
295  print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">'.$object->getLibStatut(4).'</td></tr>';
296 
297  print "</table>";
298 
299  print dol_get_fiche_end();
300 
301  if (!empty($user->rights->accounting->fiscalyear->write))
302  {
303  /*
304  * Barre d'actions
305  */
306  print '<div class="tabsAction">';
307 
308  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
309 
310  // print '<a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?action=delete&token='.newToken().'&id=' . $id . '">' . $langs->trans('Delete') . '</a>';
311 
312  print '</div>';
313  }
314  }
315  } else {
316  dol_print_error($db);
317  }
318 }
319 
320 // End of page
321 llxFooter();
322 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
dol_now($mode= 'auto')
Return date for now.
fiscalyear_prepare_head(Fiscalyear $object)
Prepare array with list of tabs.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to manage fiscal year.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59