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