dolibarr  9.0.0
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 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 <http://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->societe_id) $socid=$user->societe_id;
44 $result = restrictedArea($user, 'deplacement', $id,'');
45 
46 $action = GETPOST('action','alpha');
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 == 0)
67  {
68  $result = $object->setStatut(1);
69  if ($result > 0)
70  {
71  header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
72  exit;
73  }
74  else
75  {
76  setEventMessages($object->error, $object->errors, 'errors');
77  }
78  }
79 }
80 
81 else if ($action == 'classifyrefunded' && $user->rights->deplacement->creer)
82 {
83  $object->fetch($id);
84  if ($object->statut == 1)
85  {
86  $result = $object->setStatut(2);
87  if ($result > 0)
88  {
89  header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
90  exit;
91  }
92  else
93  {
94  setEventMessages($object->error, $object->errors, 'errors');
95  }
96  }
97 }
98 
99 else if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->deplacement->supprimer)
100 {
101  $result=$object->delete($id);
102  if ($result >= 0)
103  {
104  header("Location: index.php");
105  exit;
106  }
107  else
108  {
109  setEventMessages($object->error, $object->errors, 'errors');
110  }
111 }
112 
113 else if ($action == 'add' && $user->rights->deplacement->creer)
114 {
115  if (! GETPOST('cancel','alpha'))
116  {
117  $error=0;
118 
119  $object->date = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
120  $object->km = price2num(GETPOST('km','alpha'), 'MU'); // Not 'int', it may be a formated amount
121  $object->type = GETPOST('type','alpha');
122  $object->socid = GETPOST('socid','int');
123  $object->fk_user = GETPOST('fk_user','int');
124  $object->note_private = GETPOST('note_private','alpha');
125  $object->note_public = GETPOST('note_public','alpha');
126  $object->statut = 0;
127 
128  if (! $object->date)
129  {
130  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
131  $error++;
132  }
133  if ($object->type == '-1')
134  {
135  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
136  $error++;
137  }
138  if (! ($object->fk_user > 0))
139  {
140  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Person")), null, 'errors');
141  $error++;
142  }
143 
144  if (! $error)
145  {
146  $id = $object->create($user);
147 
148  if ($id > 0)
149  {
150  header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
151  exit;
152  }
153  else
154  {
155  setEventMessages($object->error, $object->errors, 'errors');
156  $action='create';
157  }
158  }
159  else
160  {
161  $action='create';
162  }
163  }
164  else
165  {
166  header("Location: index.php");
167  exit;
168  }
169 }
170 
171 // Update record
172 else if ($action == 'update' && $user->rights->deplacement->creer)
173 {
174  if (! GETPOST('cancel','alpha'))
175  {
176  $result = $object->fetch($id);
177 
178  $object->date = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
179  $object->km = price2num(GETPOST('km','alpha'), 'MU'); // Not 'int', it may be a formated amount
180  $object->type = GETPOST('type','alpha');
181  $object->socid = GETPOST('socid','int');
182  $object->fk_user = GETPOST('fk_user','int');
183  $object->note_private = GETPOST('note_private','alpha');
184  $object->note_public = GETPOST('note_public','alpha');
185 
186  $result = $object->update($user);
187 
188  if ($result > 0)
189  {
190  header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
191  exit;
192  }
193  else
194  {
195  setEventMessages($object->error, $object->errors, 'errors');
196  }
197  }
198  else
199  {
200  header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
201  exit;
202  }
203 }
204 
205 // Set into a project
206 else if ($action == 'classin' && $user->rights->deplacement->creer)
207 {
208  $object->fetch($id);
209  $result=$object->setProject(GETPOST('projectid','int'));
210  if ($result < 0) dol_print_error($db, $object->error);
211 }
212 
213 // Set fields
214 else if ($action == 'setdated' && $user->rights->deplacement->creer)
215 {
216  $dated=dol_mktime(GETPOST('datedhour','int'), GETPOST('datedmin','int'), GETPOST('datedsec','int'), GETPOST('datedmonth','int'), GETPOST('datedday','int'), GETPOST('datedyear','int'));
217  $object->fetch($id);
218  $result=$object->setValueFrom('dated', $dated, '', '', 'date', '', $user, 'DEPLACEMENT_MODIFY');
219  if ($result < 0) dol_print_error($db, $object->error);
220 }
221 else if ($action == 'setkm' && $user->rights->deplacement->creer)
222 {
223  $object->fetch($id);
224  $result=$object->setValueFrom('km', GETPOST('km','int'), '', null, 'text', '', $user, 'DEPLACEMENT_MODIFY');
225  if ($result < 0) dol_print_error($db, $object->error);
226 }
227 
228 
229 /*
230  * View
231  */
232 
233 llxHeader();
234 
235 $form = new Form($db);
236 
237 /*
238  * Action create
239 */
240 if ($action == 'create')
241 {
242  //WYSIWYG Editor
243  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
244 
245  print load_fiche_titre($langs->trans("NewTrip"));
246 
247  $datec = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
248 
249  print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
250  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
251  print '<input type="hidden" name="action" value="add">';
252 
253  print '<table class="border" width="100%">';
254 
255  print "<tr>";
256  print '<td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
257  $form->select_type_fees(GETPOST('type','int'),'type',1);
258  print '</td></tr>';
259 
260  print "<tr>";
261  print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
262  print $form->select_dolusers(GETPOST('fk_user','int'), 'fk_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
263  print '</td></tr>';
264 
265  print "<tr>";
266  print '<td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
267  print $form->selectDate($datec?$datec:-1, '', '', '', '', 'add', 1, 1);
268  print '</td></tr>';
269 
270  // Km
271  print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td><input name="km" size="10" value="' . GETPOST("km") . '"></td></tr>';
272 
273  // Company
274  print "<tr>";
275  print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
276  print $form->select_company(GETPOST('socid','int'),'socid','',1);
277  print '</td></tr>';
278 
279  // Public note
280  print '<tr>';
281  print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
282  print '<td>';
283 
284  $doleditor = new DolEditor('note_public', GETPOST('note_public', 'alpha'), '', 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8,'90%');
285  print $doleditor->Create(1);
286 
287  print '</td></tr>';
288 
289  // Private note
290  if (empty($user->societe_id))
291  {
292  print '<tr>';
293  print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
294  print '<td>';
295 
296  $doleditor = new DolEditor('note_private', GETPOST('note_private', 'alpha'), '', 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, '90%');
297  print $doleditor->Create(1);
298 
299  print '</td></tr>';
300  }
301 
302  // Other attributes
303  $parameters=array();
304  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
305  print $hookmanager->resPrint;
306 
307  print '</table>';
308 
309  print '<br><div class="center">';
310  print '<input class="button" type="submit" value="'.$langs->trans("Save").'">';
311  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
312  print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
313  print '</div>';
314 
315  print '</form>';
316 }
317 else if ($id)
318 {
319  $result = $object->fetch($id);
320  if ($result > 0)
321  {
322  $head = trip_prepare_head($object);
323 
324  dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip');
325 
326  if ($action == 'edit' && $user->rights->deplacement->creer)
327  {
328  //WYSIWYG Editor
329  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
330 
331  $soc = new Societe($db);
332  if ($object->socid)
333  {
334  $soc->fetch($object->socid);
335  }
336 
337  print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
338  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
339  print '<input type="hidden" name="action" value="update">';
340  print '<input type="hidden" name="id" value="'.$id.'">';
341 
342  print '<table class="border" width="100%">';
343 
344  // Ref
345  print "<tr>";
346  print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
347  print $object->ref;
348  print '</td></tr>';
349 
350  // Type
351  print "<tr>";
352  print '<td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
353  $form->select_type_fees(GETPOST('type','int')?GETPOST('type','int'):$object->type,'type',0);
354  print '</td></tr>';
355 
356  // Who
357  print "<tr>";
358  print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
359  print $form->select_dolusers(GETPOST('fk_user','int')?GETPOST('fk_user','int'):$object->fk_user, 'fk_user', 0, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
360  print '</td></tr>';
361 
362  // Date
363  print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
364  print $form->selectDate($object->date, '', 0, 0, 0, 'update', 1, 0);
365  print '</td></tr>';
366 
367  // Km
368  print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td>';
369  print '<input name="km" class="flat" size="10" value="'.$object->km.'">';
370  print '</td></tr>';
371 
372  // Where
373  print "<tr>";
374  print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
375  print $form->select_company($soc->id,'socid','',1);
376  print '</td></tr>';
377 
378  // Public note
379  print '<tr><td class="tdtop">'.$langs->trans("NotePublic").'</td>';
380  print '<td>';
381 
382  $doleditor = new DolEditor('note_public', $object->note_public, '', 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, '90%');
383  print $doleditor->Create(1);
384 
385  print "</td></tr>";
386 
387  // Private note
388  if (empty($user->societe_id))
389  {
390  print '<tr><td class="tdtop">'.$langs->trans("NotePrivate").'</td>';
391  print '<td>';
392 
393  $doleditor = new DolEditor('note_private', $object->note_private, '', 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, '90%');
394  print $doleditor->Create(1);
395 
396  print "</td></tr>";
397  }
398 
399  // Other attributes
400  $parameters=array();
401  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
402  print $hookmanager->resPrint;
403 
404  print '</table>';
405 
406  print '<br><div class="center">';
407  print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
408  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
409  print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">';
410  print '</div>';
411 
412  print '</form>';
413 
414  print '</div>';
415  }
416  else
417  {
418  /*
419  * Confirm delete trip
420  */
421  if ($action == 'delete')
422  {
423  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete");
424  }
425 
426  $soc = new Societe($db);
427  if ($object->socid) $soc->fetch($object->socid);
428 
429  print '<table class="border" width="100%">';
430 
431  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/deplacement/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
432 
433  // Ref
434  print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>';
435  print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', '');
436  print '</td></tr>';
437 
438  $form->load_cache_types_fees();
439 
440  // Type
441  print '<tr><td>';
442  print $form->editfieldkey("Type",'type',$langs->trans($object->type),$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
443  print '</td><td>';
444  print $form->editfieldval("Type",'type',$form->cache_types_fees[$object->type],$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
445  print '</td></tr>';
446 
447  // Who
448  print '<tr><td>'.$langs->trans("Person").'</td><td>';
449  $userfee=new User($db);
450  $userfee->fetch($object->fk_user);
451  print $userfee->getNomUrl(1);
452  print '</td></tr>';
453 
454  // Date
455  print '<tr><td>';
456  print $form->editfieldkey("Date",'dated',$object->date,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
457  print '</td><td>';
458  print $form->editfieldval("Date",'dated',$object->date,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
459  print '</td></tr>';
460 
461  // Km/Price
462  print '<tr><td class="tdtop">';
463  print $form->editfieldkey("FeesKilometersOrAmout",'km',$object->km,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
464  print '</td><td>';
465  print $form->editfieldval("FeesKilometersOrAmout",'km',$object->km,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
466  print "</td></tr>";
467 
468  // Where
469  print '<tr><td>'.$langs->trans("CompanyVisited").'</td>';
470  print '<td>';
471  if ($soc->id) print $soc->getNomUrl(1);
472  print '</td></tr>';
473 
474  // Project
475  if (! empty($conf->projet->enabled))
476  {
477  $langs->load('projects');
478  print '<tr>';
479  print '<td>';
480 
481  print '<table class="nobordernopadding" width="100%"><tr><td>';
482  print $langs->trans('Project');
483  print '</td>';
484  if ($action != 'classify' && $user->rights->deplacement->creer)
485  {
486  print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">';
487  print img_edit($langs->trans('SetProject'),1);
488  print '</a></td>';
489  }
490  print '</tr></table>';
491  print '</td><td colspan="3">';
492  if ($action == 'classify')
493  {
494  $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid', 0, 0, 1);
495  }
496  else
497  {
498  $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none', 0, 0);
499  }
500  print '</td>';
501  print '</tr>';
502  }
503 
504  // Statut
505  print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
506 
507  // Other attributes
508  $parameters=array('socid'=>$object->id);
509  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
510 
511  print "</table><br>";
512 
513  // Notes
514  $blocname = 'notes';
515  $title = $langs->trans('Notes');
516  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
517 
518  print '</div>';
519 
520  /*
521  * Barre d'actions
522  */
523 
524  print '<div class="tabsAction">';
525 
526  if ($object->statut < 2) // if not refunded
527  {
528  if ($user->rights->deplacement->creer)
529  {
530  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$id.'">'.$langs->trans('Modify').'</a>';
531  }
532  else
533  {
534  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Modify').'</a>';
535  }
536  }
537 
538  if ($object->statut == 0) // if draft
539  {
540  if ($user->rights->deplacement->creer)
541  {
542  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&id='.$id.'">'.$langs->trans('Validate').'</a>';
543  }
544  else
545  {
546  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Validate').'</a>';
547  }
548  }
549 
550  if ($object->statut == 1) // if validated
551  {
552  if ($user->rights->deplacement->creer)
553  {
554  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=classifyrefunded&id='.$id.'">'.$langs->trans('ClassifyRefunded').'</a>';
555  }
556  else
557  {
558  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('ClassifyRefunded').'</a>';
559  }
560  }
561 
562  if ($user->rights->deplacement->supprimer)
563  {
564  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&id='.$id.'">'.$langs->trans('Delete').'</a>';
565  }
566  else
567  {
568  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Delete').'</a>';
569  }
570 
571  print '</div>';
572  }
573  }
574  else
575  {
576  dol_print_error($db);
577  }
578 }
579 
580 // End of page
581 llxFooter();
582 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
Class to manage trips and working credit notes.
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...
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
llxHeader()
Empty header.
Definition: wrapper.php:44
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
trip_prepare_head(Deplacement $object)
Prepare array with list of tabs.
Definition: trip.lib.php:30
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.
Class to manage a WYSIWYG editor.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
$parameters
Actions.
Definition: card.php:114