dolibarr 18.0.6
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// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/trip.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
33if (isModEnabled('project')) {
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');
43if ($user->socid) {
44 $socid = $user->socid;
45}
46$result = restrictedArea($user, 'deplacement', $id, '');
47
48$action = GETPOST('action', 'aZ09');
49$confirm = GETPOST('confirm', 'alpha');
50
51$object = new Deplacement($db);
52
53// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
54$hookmanager->initHooks(array('tripsandexpensescard', 'globalcard'));
55
56$permissionnote = $user->rights->deplacement->creer; // Used by the include of actions_setnotes.inc.php
57
58
59/*
60 * Actions
61 */
62
63include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
64
65if ($action == 'validate' && $user->rights->deplacement->creer) {
66 $object->fetch($id);
67 if ($object->statut == Deplacement::STATUS_DRAFT) {
68 $result = $object->setStatut(1);
69 if ($result > 0) {
70 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
71 exit;
72 } else {
73 setEventMessages($object->error, $object->errors, 'errors');
74 }
75 }
76} elseif ($action == 'classifyrefunded' && $user->rights->deplacement->creer) {
77 $object->fetch($id);
78 if ($object->statut == Deplacement::STATUS_VALIDATED) {
79 $result = $object->setStatut(Deplacement::STATUS_REFUNDED);
80 if ($result > 0) {
81 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
82 exit;
83 } else {
84 setEventMessages($object->error, $object->errors, 'errors');
85 }
86 }
87} elseif ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->deplacement->supprimer) {
88 $result = $object->delete($user);
89 if ($result >= 0) {
90 header("Location: index.php");
91 exit;
92 } else {
93 setEventMessages($object->error, $object->errors, 'errors');
94 }
95} elseif ($action == 'add' && $user->rights->deplacement->creer) {
96 if (!GETPOST('cancel', 'alpha')) {
97 $error = 0;
98
99 $object->date = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
100 $object->km = price2num(GETPOST('km', 'alpha'), 'MU'); // Not 'int', it may be a formated amount
101 $object->type = GETPOST('type', 'alpha');
102 $object->socid = (int) GETPOST('socid', 'int');
103 $object->fk_user = (int) GETPOST('fk_user', 'int');
104 $object->note_private = GETPOST('note_private', 'alpha');
105 $object->note_public = GETPOST('note_public', 'alpha');
106 $object->statut = Deplacement::STATUS_DRAFT;
107
108 if (!$object->date) {
109 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
110 $error++;
111 }
112 if ($object->type == '-1') {
113 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
114 $error++;
115 }
116 if (!($object->fk_user > 0)) {
117 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Person")), null, 'errors');
118 $error++;
119 }
120
121 if (!$error) {
122 $id = $object->create($user);
123
124 if ($id > 0) {
125 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
126 exit;
127 } else {
128 setEventMessages($object->error, $object->errors, 'errors');
129 $action = 'create';
130 }
131 } else {
132 $action = 'create';
133 }
134 } else {
135 header("Location: index.php");
136 exit;
137 }
138} elseif ($action == 'update' && $user->rights->deplacement->creer) {
139 // Update record
140 if (!GETPOST('cancel', 'alpha')) {
141 $result = $object->fetch($id);
142
143 $object->date = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
144 $object->km = price2num(GETPOST('km', 'alpha'), 'MU'); // Not 'int', it may be a formated amount
145 $object->type = GETPOST('type', 'alpha');
146 $object->socid = (int) GETPOST('socid', 'int');
147 $object->fk_user = (int) GETPOST('fk_user', 'int');
148 $object->note_private = GETPOST('note_private', 'alpha');
149 $object->note_public = GETPOST('note_public', 'alpha');
150
151 $result = $object->update($user);
152
153 if ($result > 0) {
154 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
155 exit;
156 } else {
157 setEventMessages($object->error, $object->errors, 'errors');
158 }
159 } else {
160 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
161 exit;
162 }
163} elseif ($action == 'classin' && $user->rights->deplacement->creer) {
164 // Set into a project
165 $object->fetch($id);
166 $result = $object->setProject(GETPOST('projectid', 'int'));
167 if ($result < 0) {
168 dol_print_error($db, $object->error);
169 }
170} elseif ($action == 'setdated' && $user->rights->deplacement->creer) {
171 // Set fields
172 $dated = dol_mktime(GETPOST('datedhour', 'int'), GETPOST('datedmin', 'int'), GETPOST('datedsec', 'int'), GETPOST('datedmonth', 'int'), GETPOST('datedday', 'int'), GETPOST('datedyear', 'int'));
173 $object->fetch($id);
174 $result = $object->setValueFrom('dated', $dated, '', '', 'date', '', $user, 'DEPLACEMENT_MODIFY');
175 if ($result < 0) {
176 dol_print_error($db, $object->error);
177 }
178} elseif ($action == 'setkm' && $user->rights->deplacement->creer) {
179 $object->fetch($id);
180 $result = $object->setValueFrom('km', GETPOST('km', 'int'), '', null, 'text', '', $user, 'DEPLACEMENT_MODIFY');
181 if ($result < 0) {
182 dol_print_error($db, $object->error);
183 }
184}
185
186
187/*
188 * View
189 */
190
191llxHeader();
192
193$form = new Form($db);
194
195/*
196 * Action create
197*/
198if ($action == 'create') {
199 //WYSIWYG Editor
200 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
201
202 print load_fiche_titre($langs->trans("NewTrip"));
203
204 $datec = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
205
206 print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
207 print '<input type="hidden" name="token" value="'.newToken().'">';
208 print '<input type="hidden" name="action" value="add">';
209
210 print '<table class="border centpercent">';
211
212 print "<tr>";
213 print '<td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
214 $form->select_type_fees(GETPOST('type', 'int'), 'type', 1);
215 print '</td></tr>';
216
217 print "<tr>";
218 print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
219 print $form->select_dolusers(GETPOST('fk_user', 'int'), 'fk_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
220 print '</td></tr>';
221
222 print "<tr>";
223 print '<td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
224 print $form->selectDate($datec ? $datec : -1, '', '', '', '', 'add', 1, 1);
225 print '</td></tr>';
226
227 // Km
228 print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td><input name="km" size="10" value="'.GETPOST("km").'"></td></tr>';
229
230 // Company
231 print "<tr>";
232 print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
233 print $form->select_company(GETPOST('socid', 'int'), 'socid', '', 1);
234 print '</td></tr>';
235
236 // Public note
237 print '<tr>';
238 print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
239 print '<td>';
240
241 $doleditor = new DolEditor('note_public', GETPOST('note_public', 'restricthtml'), '', 200, 'dolibarr_notes', 'In', false, true, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_8, '90%');
242 print $doleditor->Create(1);
243
244 print '</td></tr>';
245
246 // Private note
247 if (empty($user->socid)) {
248 print '<tr>';
249 print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
250 print '<td>';
251
252 $doleditor = new DolEditor('note_private', GETPOST('note_private', 'restricthtml'), '', 200, 'dolibarr_notes', 'In', false, true, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_8, '90%');
253 print $doleditor->Create(1);
254
255 print '</td></tr>';
256 }
257
258 // Other attributes
259 $parameters = array();
260 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
261 print $hookmanager->resPrint;
262
263 print '</table>';
264
265 print '<br><div class="center">';
266 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
267 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
268 print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
269 print '</div>';
270
271 print '</form>';
272} elseif ($id) {
273 $result = $object->fetch($id);
274 if ($result > 0) {
275 $head = trip_prepare_head($object);
276
277 print dol_get_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip');
278
279 if ($action == 'edit' && $user->rights->deplacement->creer) {
280 //WYSIWYG Editor
281 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
282
283 $soc = new Societe($db);
284 if ($object->socid) {
285 $soc->fetch($object->socid);
286 }
287
288 print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
289 print '<input type="hidden" name="token" value="'.newToken().'">';
290 print '<input type="hidden" name="action" value="update">';
291 print '<input type="hidden" name="id" value="'.$id.'">';
292
293 print '<table class="border centpercent">';
294
295 // Ref
296 print "<tr>";
297 print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
298 print $object->ref;
299 print '</td></tr>';
300
301 // Type
302 print "<tr>";
303 print '<td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
304 $form->select_type_fees(GETPOST('type', 'int') ?GETPOST('type', 'int') : $object->type, 'type', 0);
305 print '</td></tr>';
306
307 // Who
308 print "<tr>";
309 print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
310 print $form->select_dolusers(GETPOST('fk_user', 'int') ?GETPOST('fk_user', 'int') : $object->fk_user, 'fk_user', 0, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
311 print '</td></tr>';
312
313 // Date
314 print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
315 print $form->selectDate($object->date, '', 0, 0, 0, 'update', 1, 0);
316 print '</td></tr>';
317
318 // Km
319 print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td>';
320 print '<input name="km" class="flat" size="10" value="'.$object->km.'">';
321 print '</td></tr>';
322
323 // Where
324 print "<tr>";
325 print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
326 print $form->select_company($soc->id, 'socid', '', 1);
327 print '</td></tr>';
328
329 // Public note
330 print '<tr><td class="tdtop">'.$langs->trans("NotePublic").'</td>';
331 print '<td>';
332
333 $doleditor = new DolEditor('note_public', $object->note_public, '', 200, 'dolibarr_notes', 'In', false, true, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_8, '90%');
334 print $doleditor->Create(1);
335
336 print "</td></tr>";
337
338 // Private note
339 if (empty($user->socid)) {
340 print '<tr><td class="tdtop">'.$langs->trans("NotePrivate").'</td>';
341 print '<td>';
342
343 $doleditor = new DolEditor('note_private', $object->note_private, '', 200, 'dolibarr_notes', 'In', false, true, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_8, '90%');
344 print $doleditor->Create(1);
345
346 print "</td></tr>";
347 }
348
349 // Other attributes
350 $parameters = array();
351 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
352 print $hookmanager->resPrint;
353
354 print '</table>';
355
356 print '<br><div class="center">';
357 print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
358 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
359 print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
360 print '</div>';
361
362 print '</form>';
363
364 print '</div>';
365 } else {
366 /*
367 * Confirm delete trip
368 */
369 if ($action == 'delete') {
370 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".urlencode($id), $langs->trans("DeleteTrip"), $langs->trans("ConfirmDeleteTrip"), "confirm_delete");
371 }
372
373 $soc = new Societe($db);
374 if ($object->socid) {
375 $soc->fetch($object->socid);
376 }
377
378 print '<table class="border centpercent">';
379
380 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/deplacement/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
381
382 // Ref
383 print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>';
384 print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', '');
385 print '</td></tr>';
386
387 $form->load_cache_types_fees();
388
389 // Type
390 print '<tr><td>';
391 print $form->editfieldkey("Type", 'type', $langs->trans($object->type), $object, $user->rights->deplacement->creer, 'select:types_fees');
392 print '</td><td>';
393 print $form->editfieldval("Type", 'type', $form->cache_types_fees[$object->type], $object, $user->rights->deplacement->creer, 'select:types_fees');
394 print '</td></tr>';
395
396 // Who
397 print '<tr><td>'.$langs->trans("Person").'</td><td>';
398 $userfee = new User($db);
399 $userfee->fetch($object->fk_user);
400 print $userfee->getNomUrl(1);
401 print '</td></tr>';
402
403 // Date
404 print '<tr><td>';
405 print $form->editfieldkey("Date", 'dated', $object->date, $object, $user->rights->deplacement->creer, 'datepicker');
406 print '</td><td>';
407 print $form->editfieldval("Date", 'dated', $object->date, $object, $user->rights->deplacement->creer, 'datepicker');
408 print '</td></tr>';
409
410 // Km/Price
411 print '<tr><td class="tdtop">';
412 print $form->editfieldkey("FeesKilometersOrAmout", 'km', $object->km, $object, $user->rights->deplacement->creer, 'numeric:6');
413 print '</td><td>';
414 print $form->editfieldval("FeesKilometersOrAmout", 'km', $object->km, $object, $user->rights->deplacement->creer, 'numeric:6');
415 print "</td></tr>";
416
417 // Where
418 print '<tr><td>'.$langs->trans("CompanyVisited").'</td>';
419 print '<td>';
420 if ($soc->id) {
421 print $soc->getNomUrl(1);
422 }
423 print '</td></tr>';
424
425 // Project
426 if (isModEnabled('project')) {
427 $langs->load('projects');
428 print '<tr>';
429 print '<td>';
430
431 print '<table class="nobordernopadding" width="100%"><tr><td>';
432 print $langs->trans('Project');
433 print '</td>';
434 if ($action != 'classify' && $user->rights->deplacement->creer) {
435 print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&token='.newToken().'&id='.$object->id.'">';
436 print img_edit($langs->trans('SetProject'), 1);
437 print '</a></td>';
438 }
439 print '</tr></table>';
440 print '</td><td colspan="3">';
441 if ($action == 'classify') {
442 $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1);
443 } else {
444 $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0);
445 }
446 print '</td>';
447 print '</tr>';
448 }
449
450 // Statut
451 print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
452
453 // Other attributes
454 $parameters = array('socid'=>$object->id);
455 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
456
457 print "</table><br>";
458
459 // Notes
460 $blocname = 'notes';
461 $title = $langs->trans('Notes');
462 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
463
464 print '</div>';
465
466 /*
467 * Action bar
468 */
469 print '<div class="tabsAction">';
470
471 if ($object->statut < Deplacement::STATUS_REFUNDED) { // if not refunded
472 if ($user->rights->deplacement->creer) {
473 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
474 } else {
475 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Modify').'</a>';
476 }
477 }
478
479 if ($object->statut == Deplacement::STATUS_DRAFT) { // if draft
480 if ($user->rights->deplacement->creer) {
481 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&id='.$id.'">'.$langs->trans('Validate').'</a>';
482 } else {
483 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Validate').'</a>';
484 }
485 }
486
487 if ($object->statut == Deplacement::STATUS_VALIDATED) { // if validated
488 if ($user->rights->deplacement->creer) {
489 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=classifyrefunded&token='.newToken().'&id='.$id.'">'.$langs->trans('ClassifyRefunded').'</a>';
490 } else {
491 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('ClassifyRefunded').'</a>';
492 }
493 }
494
495 $permissiontodelete = $user->rights->deplacement->supprimer;
496 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
497
498 print '</div>';
499 }
500 } else {
501 dol_print_error($db);
502 }
503}
504
505// End of page
506llxFooter();
507$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage trips and working credit notes.
const STATUS_DRAFT
Draft status.
const STATUS_REFUNDED
Refunded status.
const STATUS_VALIDATED
Validated status.
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
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...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
trip_prepare_head(Deplacement $object)
Prepare array with list of tabs.
Definition trip.lib.php:30