dolibarr  13.0.2
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
7  * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/trip.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32 if (!empty($conf->projet->enabled))
33 {
34  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
35 }
36 
37 // Load translation files required by the page
38 $langs->load("trips");
39 
40 
41 // Security check
42 $id = GETPOST('id', 'int');
43 if ($user->socid) $socid = $user->socid;
44 $result = restrictedArea($user, 'deplacement', $id, '');
45 
46 $action = GETPOST('action', 'aZ09');
47 $confirm = GETPOST('confirm', 'alpha');
48 
49 $object = new Deplacement($db);
50 
51 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
52 $hookmanager->initHooks(array('tripsandexpensescard', 'globalcard'));
53 
54 $permissionnote = $user->rights->deplacement->creer; // Used by the include of actions_setnotes.inc.php
55 
56 
57 /*
58  * Actions
59  */
60 
61 include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
62 
63 if ($action == 'validate' && $user->rights->deplacement->creer)
64 {
65  $object->fetch($id);
66  if ($object->statut == Deplacement::STATUS_DRAFT)
67  {
68  $result = $object->setStatut(1);
69  if ($result > 0)
70  {
71  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
72  exit;
73  } else {
74  setEventMessages($object->error, $object->errors, 'errors');
75  }
76  }
77 } elseif ($action == 'classifyrefunded' && $user->rights->deplacement->creer)
78 {
79  $object->fetch($id);
80  if ($object->statut == Deplacement::STATUS_VALIDATED)
81  {
82  $result = $object->setStatut(Deplacement::STATUS_REFUNDED);
83  if ($result > 0)
84  {
85  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
86  exit;
87  } else {
88  setEventMessages($object->error, $object->errors, 'errors');
89  }
90  }
91 } elseif ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->deplacement->supprimer)
92 {
93  $result = $object->delete($id);
94  if ($result >= 0)
95  {
96  header("Location: index.php");
97  exit;
98  } else {
99  setEventMessages($object->error, $object->errors, 'errors');
100  }
101 } elseif ($action == 'add' && $user->rights->deplacement->creer)
102 {
103  if (!GETPOST('cancel', 'alpha'))
104  {
105  $error = 0;
106 
107  $object->date = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
108  $object->km = price2num(GETPOST('km', 'alpha'), 'MU'); // Not 'int', it may be a formated amount
109  $object->type = GETPOST('type', 'alpha');
110  $object->socid = (int) GETPOST('socid', 'int');
111  $object->fk_user = (int) GETPOST('fk_user', 'int');
112  $object->note_private = GETPOST('note_private', 'alpha');
113  $object->note_public = GETPOST('note_public', 'alpha');
114  $object->statut = Deplacement::STATUS_DRAFT;
115 
116  if (!$object->date)
117  {
118  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
119  $error++;
120  }
121  if ($object->type == '-1')
122  {
123  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
124  $error++;
125  }
126  if (!($object->fk_user > 0))
127  {
128  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Person")), null, 'errors');
129  $error++;
130  }
131 
132  if (!$error)
133  {
134  $id = $object->create($user);
135 
136  if ($id > 0)
137  {
138  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
139  exit;
140  } else {
141  setEventMessages($object->error, $object->errors, 'errors');
142  $action = 'create';
143  }
144  } else {
145  $action = 'create';
146  }
147  } else {
148  header("Location: index.php");
149  exit;
150  }
151 } // Update record
152 elseif ($action == 'update' && $user->rights->deplacement->creer)
153 {
154  if (!GETPOST('cancel', 'alpha'))
155  {
156  $result = $object->fetch($id);
157 
158  $object->date = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
159  $object->km = price2num(GETPOST('km', 'alpha'), 'MU'); // Not 'int', it may be a formated amount
160  $object->type = GETPOST('type', 'alpha');
161  $object->socid = (int) GETPOST('socid', 'int');
162  $object->fk_user = (int) GETPOST('fk_user', 'int');
163  $object->note_private = GETPOST('note_private', 'alpha');
164  $object->note_public = GETPOST('note_public', 'alpha');
165 
166  $result = $object->update($user);
167 
168  if ($result > 0)
169  {
170  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
171  exit;
172  } else {
173  setEventMessages($object->error, $object->errors, 'errors');
174  }
175  } else {
176  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
177  exit;
178  }
179 } // Set into a project
180 elseif ($action == 'classin' && $user->rights->deplacement->creer)
181 {
182  $object->fetch($id);
183  $result = $object->setProject(GETPOST('projectid', 'int'));
184  if ($result < 0) dol_print_error($db, $object->error);
185 } // Set fields
186 elseif ($action == 'setdated' && $user->rights->deplacement->creer)
187 {
188  $dated = dol_mktime(GETPOST('datedhour', 'int'), GETPOST('datedmin', 'int'), GETPOST('datedsec', 'int'), GETPOST('datedmonth', 'int'), GETPOST('datedday', 'int'), GETPOST('datedyear', 'int'));
189  $object->fetch($id);
190  $result = $object->setValueFrom('dated', $dated, '', '', 'date', '', $user, 'DEPLACEMENT_MODIFY');
191  if ($result < 0) dol_print_error($db, $object->error);
192 } elseif ($action == 'setkm' && $user->rights->deplacement->creer)
193 {
194  $object->fetch($id);
195  $result = $object->setValueFrom('km', GETPOST('km', 'int'), '', null, 'text', '', $user, 'DEPLACEMENT_MODIFY');
196  if ($result < 0) dol_print_error($db, $object->error);
197 }
198 
199 
200 /*
201  * View
202  */
203 
204 llxHeader();
205 
206 $form = new Form($db);
207 
208 /*
209  * Action create
210 */
211 if ($action == 'create')
212 {
213  //WYSIWYG Editor
214  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
215 
216  print load_fiche_titre($langs->trans("NewTrip"));
217 
218  $datec = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
219 
220  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
221  print '<input type="hidden" name="token" value="'.newToken().'">';
222  print '<input type="hidden" name="action" value="add">';
223 
224  print '<table class="border centpercent">';
225 
226  print "<tr>";
227  print '<td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
228  $form->select_type_fees(GETPOST('type', 'int'), 'type', 1);
229  print '</td></tr>';
230 
231  print "<tr>";
232  print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
233  print $form->select_dolusers(GETPOST('fk_user', 'int'), 'fk_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
234  print '</td></tr>';
235 
236  print "<tr>";
237  print '<td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
238  print $form->selectDate($datec ? $datec : -1, '', '', '', '', 'add', 1, 1);
239  print '</td></tr>';
240 
241  // Km
242  print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td><input name="km" size="10" value="'.GETPOST("km").'"></td></tr>';
243 
244  // Company
245  print "<tr>";
246  print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
247  print $form->select_company(GETPOST('socid', 'int'), 'socid', '', 1);
248  print '</td></tr>';
249 
250  // Public note
251  print '<tr>';
252  print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
253  print '<td>';
254 
255  $doleditor = new DolEditor('note_public', GETPOST('note_public', 'restricthtml'), '', 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, '90%');
256  print $doleditor->Create(1);
257 
258  print '</td></tr>';
259 
260  // Private note
261  if (empty($user->socid))
262  {
263  print '<tr>';
264  print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
265  print '<td>';
266 
267  $doleditor = new DolEditor('note_private', GETPOST('note_private', 'restricthtml'), '', 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, '90%');
268  print $doleditor->Create(1);
269 
270  print '</td></tr>';
271  }
272 
273  // Other attributes
274  $parameters = array();
275  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
276  print $hookmanager->resPrint;
277 
278  print '</table>';
279 
280  print '<br><div class="center">';
281  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
282  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
283  print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
284  print '</div>';
285 
286  print '</form>';
287 } elseif ($id)
288 {
289  $result = $object->fetch($id);
290  if ($result > 0)
291  {
292  $head = trip_prepare_head($object);
293 
294  print dol_get_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip');
295 
296  if ($action == 'edit' && $user->rights->deplacement->creer)
297  {
298  //WYSIWYG Editor
299  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
300 
301  $soc = new Societe($db);
302  if ($object->socid)
303  {
304  $soc->fetch($object->socid);
305  }
306 
307  print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
308  print '<input type="hidden" name="token" value="'.newToken().'">';
309  print '<input type="hidden" name="action" value="update">';
310  print '<input type="hidden" name="id" value="'.$id.'">';
311 
312  print '<table class="border centpercent">';
313 
314  // Ref
315  print "<tr>";
316  print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
317  print $object->ref;
318  print '</td></tr>';
319 
320  // Type
321  print "<tr>";
322  print '<td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
323  $form->select_type_fees(GETPOST('type', 'int') ?GETPOST('type', 'int') : $object->type, 'type', 0);
324  print '</td></tr>';
325 
326  // Who
327  print "<tr>";
328  print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
329  print $form->select_dolusers(GETPOST('fk_user', 'int') ?GETPOST('fk_user', 'int') : $object->fk_user, 'fk_user', 0, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
330  print '</td></tr>';
331 
332  // Date
333  print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
334  print $form->selectDate($object->date, '', 0, 0, 0, 'update', 1, 0);
335  print '</td></tr>';
336 
337  // Km
338  print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td>';
339  print '<input name="km" class="flat" size="10" value="'.$object->km.'">';
340  print '</td></tr>';
341 
342  // Where
343  print "<tr>";
344  print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
345  print $form->select_company($soc->id, 'socid', '', 1);
346  print '</td></tr>';
347 
348  // Public note
349  print '<tr><td class="tdtop">'.$langs->trans("NotePublic").'</td>';
350  print '<td>';
351 
352  $doleditor = new DolEditor('note_public', $object->note_public, '', 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, '90%');
353  print $doleditor->Create(1);
354 
355  print "</td></tr>";
356 
357  // Private note
358  if (empty($user->socid))
359  {
360  print '<tr><td class="tdtop">'.$langs->trans("NotePrivate").'</td>';
361  print '<td>';
362 
363  $doleditor = new DolEditor('note_private', $object->note_private, '', 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, '90%');
364  print $doleditor->Create(1);
365 
366  print "</td></tr>";
367  }
368 
369  // Other attributes
370  $parameters = array();
371  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
372  print $hookmanager->resPrint;
373 
374  print '</table>';
375 
376  print '<br><div class="center">';
377  print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
378  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
379  print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
380  print '</div>';
381 
382  print '</form>';
383 
384  print '</div>';
385  } else {
386  /*
387  * Confirm delete trip
388  */
389  if ($action == 'delete')
390  {
391  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteTrip"), $langs->trans("ConfirmDeleteTrip"), "confirm_delete");
392  }
393 
394  $soc = new Societe($db);
395  if ($object->socid) $soc->fetch($object->socid);
396 
397  print '<table class="border centpercent">';
398 
399  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/deplacement/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
400 
401  // Ref
402  print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>';
403  print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', '');
404  print '</td></tr>';
405 
406  $form->load_cache_types_fees();
407 
408  // Type
409  print '<tr><td>';
410  print $form->editfieldkey("Type", 'type', $langs->trans($object->type), $object, $user->rights->deplacement->creer, 'select:types_fees');
411  print '</td><td>';
412  print $form->editfieldval("Type", 'type', $form->cache_types_fees[$object->type], $object, $user->rights->deplacement->creer, 'select:types_fees');
413  print '</td></tr>';
414 
415  // Who
416  print '<tr><td>'.$langs->trans("Person").'</td><td>';
417  $userfee = new User($db);
418  $userfee->fetch($object->fk_user);
419  print $userfee->getNomUrl(1);
420  print '</td></tr>';
421 
422  // Date
423  print '<tr><td>';
424  print $form->editfieldkey("Date", 'dated', $object->date, $object, $user->rights->deplacement->creer, 'datepicker');
425  print '</td><td>';
426  print $form->editfieldval("Date", 'dated', $object->date, $object, $user->rights->deplacement->creer, 'datepicker');
427  print '</td></tr>';
428 
429  // Km/Price
430  print '<tr><td class="tdtop">';
431  print $form->editfieldkey("FeesKilometersOrAmout", 'km', $object->km, $object, $user->rights->deplacement->creer, 'numeric:6');
432  print '</td><td>';
433  print $form->editfieldval("FeesKilometersOrAmout", 'km', $object->km, $object, $user->rights->deplacement->creer, 'numeric:6');
434  print "</td></tr>";
435 
436  // Where
437  print '<tr><td>'.$langs->trans("CompanyVisited").'</td>';
438  print '<td>';
439  if ($soc->id) print $soc->getNomUrl(1);
440  print '</td></tr>';
441 
442  // Project
443  if (!empty($conf->projet->enabled))
444  {
445  $langs->load('projects');
446  print '<tr>';
447  print '<td>';
448 
449  print '<table class="nobordernopadding" width="100%"><tr><td>';
450  print $langs->trans('Project');
451  print '</td>';
452  if ($action != 'classify' && $user->rights->deplacement->creer)
453  {
454  print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">';
455  print img_edit($langs->trans('SetProject'), 1);
456  print '</a></td>';
457  }
458  print '</tr></table>';
459  print '</td><td colspan="3">';
460  if ($action == 'classify')
461  {
462  $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1);
463  } else {
464  $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0);
465  }
466  print '</td>';
467  print '</tr>';
468  }
469 
470  // Statut
471  print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
472 
473  // Other attributes
474  $parameters = array('socid'=>$object->id);
475  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
476 
477  print "</table><br>";
478 
479  // Notes
480  $blocname = 'notes';
481  $title = $langs->trans('Notes');
482  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
483 
484  print '</div>';
485 
486  /*
487  * Barre d'actions
488  */
489 
490  print '<div class="tabsAction">';
491 
492  if ($object->statut < Deplacement::STATUS_REFUNDED) // if not refunded
493  {
494  if ($user->rights->deplacement->creer)
495  {
496  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$id.'">'.$langs->trans('Modify').'</a>';
497  } else {
498  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Modify').'</a>';
499  }
500  }
501 
502  if ($object->statut == Deplacement::STATUS_DRAFT) // if draft
503  {
504  if ($user->rights->deplacement->creer)
505  {
506  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&id='.$id.'">'.$langs->trans('Validate').'</a>';
507  } else {
508  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Validate').'</a>';
509  }
510  }
511 
512  if ($object->statut == Deplacement::STATUS_VALIDATED) // if validated
513  {
514  if ($user->rights->deplacement->creer)
515  {
516  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=classifyrefunded&id='.$id.'">'.$langs->trans('ClassifyRefunded').'</a>';
517  } else {
518  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('ClassifyRefunded').'</a>';
519  }
520  }
521 
522  if ($user->rights->deplacement->supprimer)
523  {
524  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$id.'">'.$langs->trans('Delete').'</a>';
525  } else {
526  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Delete').'</a>';
527  }
528 
529  print '</div>';
530  }
531  } else {
532  dol_print_error($db);
533  }
534 }
535 
536 // End of page
537 llxFooter();
538 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
const STATUS_DRAFT
Draft status.
Class to manage trips and working credit notes.
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...
const STATUS_REFUNDED
Refunded status.
const STATUS_VALIDATED
Validated status.
Class to manage Dolibarr users.
Definition: user.class.php:44
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.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
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
trip_prepare_head(Deplacement $object)
Prepare array with list of tabs.
Definition: trip.lib.php:30
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;.
Class to manage a WYSIWYG editor.
llxFooter()
Empty footer.
Definition: wrapper.php:59