dolibarr  20.0.0-beta
fiscalyear_card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2014-2024 Alexandre Spangaro <aspangaro@easya.solutions>
3  * Copyright (C) 2018-2024 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
26 require '../../main.inc.php';
27 
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/fiscalyear.lib.php';
29 require_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 // Get parameters
35 $id = GETPOSTINT('id');
36 $ref = GETPOST('ref', 'alpha');
37 
38 $action = GETPOST('action', 'aZ09');
39 $confirm = GETPOST('confirm', 'alpha');
40 $cancel = GETPOST('cancel', 'aZ09');
41 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
42 $backtopage = GETPOST('backtopage', 'alpha'); // if not set, a default page will be used
43 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); // if not set, $backtopage will be used
44 $backtopagejsfields = GETPOST('backtopagejsfields', 'alpha');
45 $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
46 
47 if (!empty($backtopagejsfields)) {
48  $tmpbacktopagejsfields = explode(':', $backtopagejsfields);
49  $dol_openinpopup = $tmpbacktopagejsfields[0];
50 }
51 
52 $error = 0;
53 
54 // Initialize technical objects
55 $object = new Fiscalyear($db);
56 $extrafields = new ExtraFields($db);
57 
58 // Load object
59 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
60 
61 // List of status
62 static $tmpstatus2label = array(
63  '0' => 'OpenFiscalYear',
64  '1' => 'CloseFiscalYear'
65 );
66 $status2label = array(
67  '' => ''
68 );
69 foreach ($tmpstatus2label as $key => $val) {
70  $status2label[$key] = $langs->trans($val);
71 }
72 
73 $date_start = dol_mktime(0, 0, 0, GETPOSTINT('fiscalyearmonth'), GETPOSTINT('fiscalyearday'), GETPOSTINT('fiscalyearyear'));
74 $date_end = dol_mktime(0, 0, 0, GETPOSTINT('fiscalyearendmonth'), GETPOSTINT('fiscalyearendday'), GETPOSTINT('fiscalyearendyear'));
75 
76 $permissiontoadd = $user->hasRight('accounting', 'fiscalyear', 'write');
77 
78 // Security check
79 if ($user->socid > 0) {
81 }
82 if (!$permissiontoadd) {
84 }
85 
86 
87 /*
88  * Actions
89  */
90 
91 $parameters = array();
92 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
93 if ($reshook < 0) {
94  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
95 }
96 
97 if ($action == 'confirm_delete' && $confirm == "yes") {
98  $result = $object->delete($user);
99  if ($result >= 0) {
100  header("Location: fiscalyear.php");
101  exit();
102  } else {
103  setEventMessages($object->error, $object->errors, 'errors');
104  }
105 } elseif ($action == 'add') {
106  if (!GETPOST('cancel', 'alpha')) {
107  $error = 0;
108 
109  $object->date_start = $date_start;
110  $object->date_end = $date_end;
111  $object->label = GETPOST('label', 'alpha');
112  $object->status = GETPOSTINT('status');
113  $object->datec = dol_now();
114 
115  if (empty($object->date_start) && empty($object->date_end)) {
116  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
117  $error++;
118  }
119  if (empty($object->label)) {
120  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
121  $error++;
122  }
123 
124  if (!$error) {
125  $db->begin();
126 
127  $id = $object->create($user);
128 
129  if ($id > 0) {
130  $db->commit();
131 
132  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
133  exit();
134  } else {
135  $db->rollback();
136 
137  setEventMessages($object->error, $object->errors, 'errors');
138  $action = 'create';
139  }
140  } else {
141  $action = 'create';
142  }
143  } else {
144  header("Location: ./fiscalyear.php");
145  exit();
146  }
147 } elseif ($action == 'update') {
148  // Update record
149  if (!GETPOST('cancel', 'alpha')) {
150  $result = $object->fetch($id);
151 
152  $object->date_start = GETPOST("fiscalyear") ? $date_start : '';
153  $object->date_end = GETPOST("fiscalyearend") ? $date_end : '';
154  $object->label = GETPOST('label', 'alpha');
155  $object->status = GETPOSTINT('status');
156 
157  $result = $object->update($user);
158 
159  if ($result > 0) {
160  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
161  exit();
162  } else {
163  setEventMessages($object->error, $object->errors, 'errors');
164  }
165  } else {
166  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
167  exit();
168  }
169 }
170 
171 
172 
173 /*
174  * View
175  */
176 
177 $form = new Form($db);
178 
179 $title = $langs->trans("Fiscalyear")." - ".$langs->trans("Card");
180 if ($action == 'create') {
181  $title = $langs->trans("NewFiscalYear");
182 }
183 
184 $help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
185 
186 llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-fiscalyear');
187 
188 if ($action == 'create') {
189  print load_fiche_titre($title, '', 'object_'.$object->picto);
190 
191  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
192  print '<input type="hidden" name="token" value="'.newToken().'">';
193  print '<input type="hidden" name="action" value="add">';
194 
195  print dol_get_fiche_head(array(), '');
196 
197  print '<table class="border centpercent tableforfieldcreate">'."\n";
198 
199  // Label
200  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="32" value="'.GETPOST('label', 'alpha').'"></td></tr>';
201 
202  // Date start
203  print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
204  print $form->selectDate(($date_start ? $date_start : ''), 'fiscalyear');
205  print '</td></tr>';
206 
207  // Date end
208  print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
209  print $form->selectDate(($date_end ? $date_end : - 1), 'fiscalyearend');
210  print '</td></tr>';
211 
212  /*
213  // Status
214  print '<tr>';
215  print '<td class="fieldrequired">' . $langs->trans("Status") . '</td>';
216  print '<td class="valeur">';
217  print $form->selectarray('status', $status2label, GETPOST('status', 'int'));
218  print '</td></tr>';
219  */
220 
221  // Common attributes
222  //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
223 
224  // Other attributes
225  //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
226 
227  print '</table>'."\n";
228 
229  print dol_get_fiche_end();
230 
231  print $form->buttonsSaveCancel("Create");
232 
233  print '</form>';
234 
235  dol_set_focus('input[name="label"]');
236 }
237 
238 
239 // Part to edit record
240 if (($id || $ref) && $action == 'edit') {
241  print load_fiche_titre($langs->trans("Fiscalyear"), '', 'object_'.$object->picto);
242 
243  print '<form method="POST" name="update" action="'.$_SERVER["PHP_SELF"].'">'."\n";
244  print '<input type="hidden" name="token" value="'.newToken().'">';
245  print '<input type="hidden" name="action" value="update">';
246  print '<input type="hidden" name="id" value="'.$object->id.'">';
247  if ($backtopage) {
248  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
249  }
250  if ($backtopageforcancel) {
251  print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
252  }
253 
254  print dol_get_fiche_head();
255 
256  print '<table class="border centpercent tableforfieldedit">'."\n";
257 
258  // Ref
259  print "<tr>";
260  print '<td class="titlefieldcreate titlefield">'.$langs->trans("Ref").'</td><td>';
261  print $object->ref;
262  print '</td></tr>';
263 
264  // Label
265  print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
266  print '<input name="label" class="flat" size="32" value="'.$object->label.'">';
267  print '</td></tr>';
268 
269  // Date start
270  print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
271  print $form->selectDate($object->date_start ? $object->date_start : - 1, 'fiscalyear');
272  print '</td></tr>';
273 
274  // Date end
275  print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
276  print $form->selectDate($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
277  print '</td></tr>';
278 
279  // Status
280  print '<tr><td>'.$langs->trans("Status").'</td><td>';
281  print $object->getLibStatut(4);
282  print '</td></tr>';
283 
284  // Common attributes
285  //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
286 
287  // Other attributes
288  //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
289 
290  print '</table>';
291 
292  print dol_get_fiche_end();
293 
294  print $form->buttonsSaveCancel();
295 
296  print '</form>';
297 }
298 
299 // Part to show record
300 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
302 
303  print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), -1, $object->picto, 0, '', '', 0, '', 1);
304 
305  $morehtmlref = '';
306  //$morehtmlref .= '<div class="refidno">';
307  //$morehtmlref .= '</div>';
308 
309  $formconfirm = '';
310 
311  // Confirmation to delete
312  if ($action == 'delete') {
313  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete", '', 0, 1);
314  }
315 
316  // Print form confirm
317  print $formconfirm;
318 
319  // Object card
320  // ------------------------------------------------------------
321  $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/fiscalyear.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
322 
323  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
324 
325 
326  print '<div class="fichecenter">';
327  print '<div class="fichehalfleft">';
328  print '<div class="underbanner clearboth"></div>';
329  print '<table class="border centpercent tableforfield">'."\n";
330 
331  // Label
332  print '<tr><td class="tdtop">';
333  print $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'alpha:32');
334  print '</td><td>';
335  print $form->editfieldval("Label", 'label', $object->label, $object, 0, 'alpha:32');
336  print "</td></tr>";
337 
338  // Date start
339  print '<tr><td>';
340  print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, 0, 'datepicker');
341  print '</td><td>';
342  print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, 0, 'datepicker');
343  print '</td></tr>';
344 
345  // Date end
346  print '<tr><td>';
347  print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, 0, 'datepicker');
348  print '</td><td>';
349  print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, 0, 'datepicker');
350  print '</td></tr>';
351 
352  print '</table>';
353  print '</div>';
354  print '</div>';
355 
356  print '<div class="clearboth"></div>';
357 
358  print dol_get_fiche_end();
359 
360 
361  /*
362  * Action bar
363  */
364  if ($user->hasRight('accounting', 'fiscalyear', 'write')) {
365  print '<div class="tabsAction">';
366 
367  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
368 
369  //print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
370 
371  print '</div>';
372  }
373 }
374 
375 // End of page
376 llxFooter();
377 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
Class to manage standard extra fields.
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 information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
$formconfirm
if ($action == 'delbookkeepingyear') {
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.