dolibarr  16.0.5
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 }
37 if (empty($user->rights->accounting->fiscalyear->write)) {
39 }
40 
41 $error = 0;
42 
43 $action = GETPOST('action', 'aZ09');
44 $confirm = GETPOST('confirm', 'alpha');
45 $id = GETPOST('id', 'int');
46 
47 // List of statut
48 static $tmpstatut2label = array(
49  '0' => 'OpenFiscalYear',
50  '1' => 'CloseFiscalYear'
51 );
52 $statut2label = array(
53  ''
54 );
55 foreach ($tmpstatut2label as $key => $val) {
56  $statut2label[$key] = $langs->trans($val);
57 }
58 
59 $object = new Fiscalyear($db);
60 
61 $date_start = dol_mktime(0, 0, 0, GETPOST('fiscalyearmonth', 'int'), GETPOST('fiscalyearday', 'int'), GETPOST('fiscalyearyear', 'int'));
62 $date_end = dol_mktime(0, 0, 0, GETPOST('fiscalyearendmonth', 'int'), GETPOST('fiscalyearendday', 'int'), GETPOST('fiscalyearendyear', 'int'));
63 
64 
65 /*
66  * Actions
67  */
68 
69 if ($action == 'confirm_delete' && $confirm == "yes") {
70  $result = $object->delete($id);
71  if ($result >= 0) {
72  header("Location: fiscalyear.php");
73  exit();
74  } else {
75  setEventMessages($object->error, $object->errors, 'errors');
76  }
77 } elseif ($action == 'add') {
78  if (!GETPOST('cancel', 'alpha')) {
79  $error = 0;
80 
81  $object->date_start = $date_start;
82  $object->date_end = $date_end;
83  $object->label = GETPOST('label', 'alpha');
84  $object->statut = GETPOST('statut', 'int');
85  $object->datec = dol_now();
86 
87  if (empty($object->date_start) && empty($object->date_end)) {
88  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
89  $error++;
90  }
91  if (empty($object->label)) {
92  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
93  $error++;
94  }
95 
96  if (!$error) {
97  $db->begin();
98 
99  $id = $object->create($user);
100 
101  if ($id > 0) {
102  $db->commit();
103 
104  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
105  exit();
106  } else {
107  $db->rollback();
108 
109  setEventMessages($object->error, $object->errors, 'errors');
110  $action = 'create';
111  }
112  } else {
113  $action = 'create';
114  }
115  } else {
116  header("Location: ./fiscalyear.php");
117  exit();
118  }
119 } elseif ($action == 'update') {
120  // Update record
121  if (!GETPOST('cancel', 'alpha')) {
122  $result = $object->fetch($id);
123 
124  $object->date_start = GETPOST("fiscalyear") ? $date_start : '';
125  $object->date_end = GETPOST("fiscalyearend") ? $date_end : '';
126  $object->label = GETPOST('label', 'alpha');
127  $object->statut = GETPOST('statut', 'int');
128 
129  $result = $object->update($user);
130 
131  if ($result > 0) {
132  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
133  exit();
134  } else {
135  setEventMessages($object->error, $object->errors, 'errors');
136  }
137  } else {
138  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
139  exit();
140  }
141 }
142 
143 
144 
145 /*
146  * View
147  */
148 
149 $form = new Form($db);
150 
151 $title = $langs->trans("Fiscalyear")." - ".$langs->trans("Card");
152 
153 $help_url = "EN:Module_Double_Entry_Accounting";
154 
155 llxHeader('', $title, $help_url);
156 
157 if ($action == 'create') {
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="'.newToken().'">';
162  print '<input type="hidden" name="action" value="add">';
163 
164  print dol_get_fiche_head();
165 
166  print '<table class="border centpercent">';
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  print dol_get_fiche_end();
193 
194  print '<div class="center">';
195  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
196  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
197  print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
198  print '</div>';
199 
200  print '</form>';
201 } elseif ($id) {
202  $result = $object->fetch($id);
203  if ($result > 0) {
204  $head = fiscalyear_prepare_head($object);
205 
206  if ($action == 'edit') {
207  print dol_get_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="'.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 centpercent">';
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 $form->buttonsSaveCancel();
246 
247  print '</form>';
248 
249  print dol_get_fiche_end();
250  } else {
251  /*
252  * Confirm delete
253  */
254  if ($action == 'delete') {
255  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete");
256  }
257 
258  print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron');
259 
260  print '<table class="border centpercent">';
261 
262  $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/fiscalyear.php">'.$langs->trans("BackToList").'</a>';
263 
264  // Ref
265  print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td width="50%">';
266  print $object->ref;
267  print '</td><td>';
268  print $linkback;
269  print '</td></tr>';
270 
271  // Label
272  print '<tr><td class="tdtop">';
273  print $form->editfieldkey("Label", 'label', $object->label, $object, 1, 'alpha:32');
274  print '</td><td colspan="2">';
275  print $form->editfieldval("Label", 'label', $object->label, $object, 1, 'alpha:32');
276  print "</td></tr>";
277 
278  // Date start
279  print '<tr><td>';
280  print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, 1, 'datepicker');
281  print '</td><td colspan="2">';
282  print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, 1, 'datepicker');
283  print '</td></tr>';
284 
285  // Date end
286  print '<tr><td>';
287  print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, 1, 'datepicker');
288  print '</td><td colspan="2">';
289  print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, 1, 'datepicker');
290  print '</td></tr>';
291 
292  // Statut
293  print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">'.$object->getLibStatut(4).'</td></tr>';
294 
295  print "</table>";
296 
297  print dol_get_fiche_end();
298 
299  /*
300  * Action bar
301  */
302  if (!empty($user->rights->accounting->fiscalyear->write)) {
303  print '<div class="tabsAction">';
304 
305  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
306 
307  // print '<a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?action=delete&token='.newToken().'&id=' . $id . '">' . $langs->trans('Delete') . '</a>';
308 
309  print '</div>';
310  }
311  }
312  } else {
313  dol_print_error($db);
314  }
315 }
316 
317 // End of page
318 llxFooter();
319 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
fiscalyear_prepare_head
fiscalyear_prepare_head(Fiscalyear $object)
Prepare array with list of tabs.
Definition: fiscalyear.lib.php:30
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
Fiscalyear
Class to manage fiscal year.
Definition: fiscalyear.class.php:31
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
dol_mktime
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...
Definition: functions.lib.php:2757
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59