dolibarr  7.0.0-beta
fiscalyear_card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2014-2016 Alexandre Spangaro <aspangaro@zendsi.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
24 require '../../main.inc.php';
25 
26 require_once DOL_DOCUMENT_ROOT . '/core/lib/fiscalyear.lib.php';
27 require_once DOL_DOCUMENT_ROOT . '/core/class/fiscalyear.class.php';
28 
29 $langs->load("admin");
30 $langs->load("compta");
31 
32 // Security check
33 if ($user->societe_id > 0)
35 if (empty($user->rights->accounting->fiscalyear))
37 
38 $error = 0;
39 
40 $action = GETPOST('action', 'alpha');
41 $confirm = GETPOST('confirm', 'alpha');
42 $id = GETPOST('id', 'int');
43 
44 // List of statut
45 static $tmpstatut2label = array (
46  '0' => 'OpenFiscalYear',
47  '1' => 'CloseFiscalYear'
48 );
49 $statut2label = array (
50  ''
51 );
52 foreach ( $tmpstatut2label as $key => $val )
53  $statut2label[$key] = $langs->trans($val);
54 
55 $object = new Fiscalyear($db);
56 
57 $date_start = dol_mktime(0, 0, 0, GETPOST('fiscalyearmonth', 'int'), GETPOST('fiscalyearday', 'int'), GETPOST('fiscalyearyear', 'int'));
58 $date_end = dol_mktime(0, 0, 0, GETPOST('fiscalyearendmonth', 'int'), GETPOST('fiscalyearendday', 'int'), GETPOST('fiscalyearendyear', 'int'));
59 
60 
61 /*
62  * Actions
63  */
64 
65 if ($action == 'confirm_delete' && $confirm == "yes") {
66  $result = $object->delete($id);
67  if ($result >= 0) {
68  header("Location: fiscalyear.php");
69  exit();
70  } else {
71  setEventMessages($object->error, $object->errors, 'errors');
72  }
73 }
74 
75 else if ($action == 'add') {
76  if (! GETPOST('cancel', 'alpha')) {
77  $error = 0;
78 
79  $object->date_start = $date_start;
80  $object->date_end = $date_end;
81  $object->label = GETPOST('label', 'alpha');
82  $object->statut = GETPOST('statut', 'int');
83  $object->datec = dol_now();
84 
85  if (empty($object->date_start) && empty($object->date_end)) {
86  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
87  $error ++;
88  }
89  if (empty($object->label)) {
90  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
91  $error ++;
92  }
93 
94  if (! $error) {
95  $db->begin();
96 
97  $id = $object->create($user);
98 
99  if ($id > 0) {
100  $db->commit();
101 
102  header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
103  exit();
104  } else {
105  $db->rollback();
106 
107  setEventMessages($object->error, $object->errors, 'errors');
108  $action = 'create';
109  }
110  } else {
111  $action = 'create';
112  }
113  } else {
114  header("Location: ./fiscalyear.php");
115  exit();
116  }
117 }
118 
119 // Update record
120 else if ($action == 'update') {
121  if (! GETPOST('cancel', 'alpha')) {
122  $result = $object->fetch($id);
123 
124  $object->date_start = empty($_POST["fiscalyear"]) ? '' : $date_start;
125  $object->date_end = empty($_POST["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 $helpurl = "";
153 llxHeader("",$title,$helpurl);
154 
155 if ($action == 'create')
156 {
157  print load_fiche_titre($langs->trans("NewFiscalYear"));
158 
159  print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
160  print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
161  print '<input type="hidden" name="action" value="add">';
162 
163  dol_fiche_head();
164 
165  print '<table class="border" width="100%">';
166 
167  // Label
168  print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans("Label") . '</td><td><input name="label" size="32" value="' . GETPOST("label") . '"></td></tr>';
169 
170  // Date start
171  print '<tr><td class="fieldrequired">' . $langs->trans("DateStart") . '</td><td>';
172  print $form->select_date(($date_start ? $date_start : ''), 'fiscalyear');
173  print '</td></tr>';
174 
175  // Date end
176  print '<tr><td class="fieldrequired">' . $langs->trans("DateEnd") . '</td><td>';
177  print $form->select_date(($date_end ? $date_end : - 1), 'fiscalyearend');
178  print '</td></tr>';
179 
180  /*
181  // Statut
182  print '<tr>';
183  print '<td class="fieldrequired">' . $langs->trans("Status") . '</td>';
184  print '<td class="valeur">';
185  print $form->selectarray('statut', $statut2label, GETPOST('statut'));
186  print '</td></tr>';
187  */
188 
189  print '</table>';
190 
191  dol_fiche_end();
192 
193  print '<div class="center">';
194  print '<input class="button" type="submit" value="' . $langs->trans("Save") . '">';
195  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
196  print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
197  print '</div>';
198 
199  print '</form>';
200 } else if ($id) {
201  $result = $object->fetch($id);
202  if ($result > 0) {
203  $head = fiscalyear_prepare_head($object);
204 
205  if ($action == 'edit') {
206  dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron');
207 
208  print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
209  print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
210  print '<input type="hidden" name="action" value="update">';
211  print '<input type="hidden" name="id" value="' . $id . '">';
212 
213  print '<table class="border" width="100%">';
214 
215  // Ref
216  print "<tr>";
217  print '<td class="titlefieldcreate titlefield">' . $langs->trans("Ref") . '</td><td>';
218  print $object->ref;
219  print '</td></tr>';
220 
221  // Label
222  print '<tr><td class="fieldrequired">' . $langs->trans("Label") . '</td><td>';
223  print '<input name="label" class="flat" size="32" value="' . $object->label . '">';
224  print '</td></tr>';
225 
226  // Date start
227  print '<tr><td class="fieldrequired">' . $langs->trans("DateStart") . '</td><td>';
228  print $form->select_date($object->date_start ? $object->date_start : - 1, 'fiscalyear');
229  print '</td></tr>';
230 
231  // Date end
232  print '<tr><td class="fieldrequired">' . $langs->trans("DateEnd") . '</td><td>';
233  print $form->select_date($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
234  print '</td></tr>';
235 
236  // Statut
237  print '<tr><td>' . $langs->trans("Statut") . '</td><td>';
238  // print $form->selectarray('statut', $statut2label, $object->statut);
239  print $object->getLibStatut(4);
240  print '</td></tr>';
241 
242  print '</table>';
243 
244  print '<br><div class="center">';
245  print '<input type="submit" class="button" value="' . $langs->trans("Save") . '">';
246  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
247  print '<input type="submit" name="cancel" class="button" value="' . $langs->trans("Cancel") . '">';
248  print '</div>';
249 
250  print '</form>';
251 
252  dol_fiche_end();
253  } else {
254  /*
255  * Confirm delete
256  */
257  if ($action == 'delete') {
258  print $form->formconfirm($_SERVER["PHP_SELF"] . "?id=" . $id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete");
259  }
260 
261  dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron');
262 
263  print '<table class="border" width="100%">';
264 
265  $linkback = '<a href="' . DOL_URL_ROOT . '/accountancy/admin/fiscalyear.php">' . $langs->trans("BackToList") . '</a>';
266 
267  // Ref
268  print '<tr><td class="titlefield">' . $langs->trans("Ref") . '</td><td width="50%">';
269  print $object->ref;
270  print '</td><td>';
271  print $linkback;
272  print '</td></tr>';
273 
274  // Label
275  print '<tr><td class="tdtop">';
276  print $form->editfieldkey("Label", 'label', $object->label, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'alpha:32');
277  print '</td><td colspan="2">';
278  print $form->editfieldval("Label", 'label', $object->label, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'alpha:32');
279  print "</td></tr>";
280 
281  // Date start
282  print '<tr><td>';
283  print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
284  print '</td><td colspan="2">';
285  print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
286  print '</td></tr>';
287 
288  // Date end
289  print '<tr><td>';
290  print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
291  print '</td><td colspan="2">';
292  print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
293  print '</td></tr>';
294 
295  // Statut
296  print '<tr><td>' . $langs->trans("Status") . '</td><td colspan="2">' . $object->getLibStatut(4) . '</td></tr>';
297 
298  print "</table>";
299 
300  dol_fiche_end();
301 
302  if (! empty($user->rights->accounting->fiscalyear))
303  {
304  /*
305  * Barre d'actions
306  */
307  print '<div class="tabsAction">';
308 
309  print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=edit&id=' . $id . '">' . $langs->trans('Modify') . '</a>';
310 
311  // print '<a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?action=delete&id=' . $id . '">' . $langs->trans('Delete') . '</a>';
312 
313  print '</div>';
314  }
315  }
316  } else {
317  dol_print_error($db);
318  }
319 }
320 
321 llxFooter();
322 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
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...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
Class to manage fiscal year.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
dol_now($mode='gmt')
Return date for now.
print
Draft customers invoices.
Definition: index.php:91