* Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012 Juanjo Menent * Copyright (C) 2013 Florian Henry * Copyright (C) 2018-2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/compta/deplacement/card.php * \brief Page to show a trip card */ // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/trip.lib.php'; require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; if (isModEnabled('project')) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; } // Load translation files required by the page $langs->load("trips"); // Security check $id = GETPOSTINT('id'); if ($user->socid) { $socid = $user->socid; } // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context $hookmanager->initHooks(array('tripsandexpensescard', 'globalcard')); $result = restrictedArea($user, 'deplacement', $id, ''); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $object = new Deplacement($db); $permissionnote = $user->hasRight('deplacement', 'creer'); // Used by the include of actions_setnotes.inc.php /* * Actions */ include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once if ($action == 'validate' && $user->hasRight('deplacement', 'creer')) { $object->fetch($id); if ($object->statut == Deplacement::STATUS_DRAFT) { $result = $object->setStatut(1); if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } } elseif ($action == 'classifyrefunded' && $user->hasRight('deplacement', 'creer')) { $object->fetch($id); if ($object->statut == Deplacement::STATUS_VALIDATED) { $result = $object->setStatut(Deplacement::STATUS_REFUNDED); if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } } elseif ($action == 'confirm_delete' && $confirm == "yes" && $user->hasRight('deplacement', 'supprimer')) { $result = $object->delete($user); if ($result >= 0) { header("Location: index.php"); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } elseif ($action == 'add' && $user->hasRight('deplacement', 'creer')) { if (!GETPOST('cancel', 'alpha')) { $error = 0; $object->date = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear')); $object->km = (float) price2num(GETPOST('km', 'alpha'), 'MU'); // Not 'int', it may be a formatted amount $object->type = GETPOST('type', 'alpha'); $object->socid = GETPOSTINT('socid'); $object->fk_user = GETPOSTINT('fk_user'); $object->note_private = GETPOST('note_private', 'alpha'); $object->note_public = GETPOST('note_public', 'alpha'); $object->statut = Deplacement::STATUS_DRAFT; if (!$object->date) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); $error++; } if ($object->type == '-1') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); $error++; } if (!($object->fk_user > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Person")), null, 'errors'); $error++; } if (!$error) { $id = $object->create($user); if ($id > 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); $action = 'create'; } } else { $action = 'create'; } } else { header("Location: index.php"); exit; } } elseif ($action == 'update' && $user->hasRight('deplacement', 'creer')) { // Update record if (!GETPOST('cancel', 'alpha')) { $result = $object->fetch($id); $object->date = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear')); $object->km = (float) price2num(GETPOST('km', 'alpha'), 'MU'); // Not 'int', it may be a formatted amount $object->type = GETPOST('type', 'alpha'); $object->socid = GETPOSTINT('socid'); $object->fk_user = GETPOSTINT('fk_user'); $object->note_private = GETPOST('note_private', 'alpha'); $object->note_public = GETPOST('note_public', 'alpha'); $result = $object->update($user); if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } else { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } } elseif ($action == 'classin' && $user->hasRight('deplacement', 'creer')) { // Set into a project $object->fetch($id); $result = $object->setProject(GETPOSTINT('projectid')); if ($result < 0) { dol_print_error($db, $object->error); } } elseif ($action == 'setdated' && $user->hasRight('deplacement', 'creer')) { // Set fields $dated = dol_mktime(GETPOSTINT('datedhour'), GETPOSTINT('datedmin'), GETPOSTINT('datedsec'), GETPOSTINT('datedmonth'), GETPOSTINT('datedday'), GETPOSTINT('datedyear')); $object->fetch($id); $result = $object->setValueFrom('dated', $dated, '', '', 'date', '', $user, 'DEPLACEMENT_MODIFY'); if ($result < 0) { dol_print_error($db, $object->error); } } elseif ($action == 'setkm' && $user->hasRight('deplacement', 'creer')) { $object->fetch($id); $result = $object->setValueFrom('km', GETPOSTINT('km'), '', null, 'text', '', $user, 'DEPLACEMENT_MODIFY'); if ($result < 0) { dol_print_error($db, $object->error); } } /* * View */ llxHeader(); $form = new Form($db); /* * Action create */ if ($action == 'create') { //WYSIWYG Editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; print load_fiche_titre($langs->trans("NewTrip")); $datec = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear')); print '
'."\n"; print ''; print ''; print ''; print ""; print ''; print ""; print ''; print ""; print ''; // Km print ''; // Company print ""; print ''; // Public note print ''; print ''; print ''; // Private note if (empty($user->socid)) { print ''; print ''; print ''; } // Other attributes $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; print '
'.$langs->trans("Type").''; $form->select_type_fees(GETPOSTINT('type'), 'type', 1); print '
'.$langs->trans("Person").''; print $form->select_dolusers(GETPOSTINT('fk_user'), 'fk_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); print '
'.$langs->trans("Date").''; print $form->selectDate($datec ? $datec : -1, '', 0, 0, 0, 'add', 1, 1); print '
'.$langs->trans("FeesKilometersOrAmout").'
'.$langs->trans("CompanyVisited").''; print $form->select_company(GETPOSTINT('socid'), 'socid', '', 1); print '
'.$langs->trans('NotePublic').''; $doleditor = new DolEditor('note_public', GETPOST('note_public', 'restricthtml'), '', 200, 'dolibarr_notes', 'In', false, true, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_8, '90%'); print $doleditor->Create(1); print '
'.$langs->trans('NotePrivate').''; $doleditor = new DolEditor('note_private', GETPOST('note_private', 'restricthtml'), '', 200, 'dolibarr_notes', 'In', false, true, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_8, '90%'); print $doleditor->Create(1); print '
'; print '
'; print ''; print '     '; print ''; print '
'; print '
'; } elseif ($id) { $result = $object->fetch($id); if ($result > 0) { $head = trip_prepare_head($object); print dol_get_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip'); if ($action == 'edit' && $user->hasRight('deplacement', 'creer')) { //WYSIWYG Editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $soc = new Societe($db); if ($object->socid) { $soc->fetch($object->socid); } print '
'."\n"; print ''; print ''; print ''; print ''; // Ref print ""; print ''; // Type print ""; print ''; // Who print ""; print ''; // Date print ''; // Km print ''; // Where print ""; print ''; // Public note print ''; print '"; // Private note if (empty($user->socid)) { print ''; print '"; } // Other attributes $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; print '
'.$langs->trans("Ref").''; print $object->ref; print '
'.$langs->trans("Type").''; $form->select_type_fees(GETPOSTINT('type') ? GETPOSTINT('type') : $object->type, 'type', 0); print '
'.$langs->trans("Person").''; print $form->select_dolusers(GETPOSTINT('fk_user') ? GETPOSTINT('fk_user') : $object->fk_user, 'fk_user', 0, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); print '
'.$langs->trans("Date").''; print $form->selectDate($object->date, '', 0, 0, 0, 'update', 1, 0); print '
'.$langs->trans("FeesKilometersOrAmout").''; print ''; print '
'.$langs->trans("CompanyVisited").''; print $form->select_company($soc->id, 'socid', '', 1); print '
'.$langs->trans("NotePublic").''; $doleditor = new DolEditor('note_public', $object->note_public, '', 200, 'dolibarr_notes', 'In', false, true, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_8, '90%'); print $doleditor->Create(1); print "
'.$langs->trans("NotePrivate").''; $doleditor = new DolEditor('note_private', $object->note_private, '', 200, 'dolibarr_notes', 'In', false, true, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_8, '90%'); print $doleditor->Create(1); print "
'; print '
'; print ''; print '     '; print ''; print '
'; print '
'; print ''; } else { /* * Confirm delete trip */ if ($action == 'delete') { print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".urlencode((string) ($id)), $langs->trans("DeleteTrip"), $langs->trans("ConfirmDeleteTrip"), "confirm_delete"); } $soc = new Societe($db); if ($object->socid) { $soc->fetch($object->socid); } print ''; $linkback = ''.$langs->trans("BackToList").''; // Ref print ''; $form->load_cache_types_fees(); // Type print ''; // Who print ''; // Date print ''; // Km/Price print '"; // Where print ''; print ''; // Project if (isModEnabled('project')) { $langs->load('projects'); print ''; print ''; print ''; } // Statut print ''; // Other attributes $parameters = array('socid' => $object->id); include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; print "
'.$langs->trans("Ref").''; print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', ''); print '
'; print $form->editfieldkey("Type", 'type', $langs->trans($object->type), $object, $user->hasRight('deplacement', 'creer'), 'select:types_fees'); print ''; print $form->editfieldval("Type", 'type', $form->cache_types_fees[$object->type], $object, $user->hasRight('deplacement', 'creer'), 'select:types_fees'); print '
'.$langs->trans("Person").''; $userfee = new User($db); $userfee->fetch($object->fk_user); print $userfee->getNomUrl(1); print '
'; print $form->editfieldkey("Date", 'dated', $object->date, $object, $user->hasRight('deplacement', 'creer'), 'datepicker'); print ''; print $form->editfieldval("Date", 'dated', $object->date, $object, $user->hasRight('deplacement', 'creer'), 'datepicker'); print '
'; print $form->editfieldkey("FeesKilometersOrAmout", 'km', $object->km, $object, $user->hasRight('deplacement', 'creer'), 'numeric:6'); print ''; print $form->editfieldval("FeesKilometersOrAmout", 'km', $object->km, $object, $user->hasRight('deplacement', 'creer'), 'numeric:6'); print "
'.$langs->trans("CompanyVisited").''; if ($soc->id) { print $soc->getNomUrl(1); } print '
'; print ''; if ($action != 'classify' && $user->hasRight('deplacement', 'creer')) { print ''; } print '
'; print $langs->trans('Project'); print 'id.'">'; print img_edit($langs->trans('SetProject'), 1); print '
'; print '
'; if ($action == 'classify') { $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1); } else { $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0); } print '
'.$langs->trans("Status").''.$object->getLibStatut(4).'

"; // Notes $blocname = 'notes'; $title = $langs->trans('Notes'); include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; print ''; /* * Action bar */ print '
'; if ($object->statut < Deplacement::STATUS_REFUNDED) { // if not refunded if ($user->hasRight('deplacement', 'creer')) { print ''.$langs->trans('Modify').''; } else { print ''.$langs->trans('Modify').''; } } if ($object->statut == Deplacement::STATUS_DRAFT) { // if draft if ($user->hasRight('deplacement', 'creer')) { print ''.$langs->trans('Validate').''; } else { print ''.$langs->trans('Validate').''; } } if ($object->statut == Deplacement::STATUS_VALIDATED) { // if validated if ($user->hasRight('deplacement', 'creer')) { print ''.$langs->trans('ClassifyRefunded').''; } else { print ''.$langs->trans('ClassifyRefunded').''; } } $permissiontodelete = $user->hasRight('deplacement', 'supprimer'); print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); print '
'; } } else { dol_print_error($db); } } // End of page llxFooter(); $db->close();