* Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * * 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 2 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/fiche.php * \brief Page to show a trip card * \version $Id: fiche.php,v 1.56 2011/08/03 00:46:35 eldy Exp $ */ require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/compta/deplacement/class/deplacement.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); if ($conf->projet->enabled) { require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php"); require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php"); } $langs->load("trips"); // Security check $id=isset($_GET["id"])?$_GET["id"]:$_POST["id"]; if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'deplacement', $id,''); $mesg = ''; /* * Actions */ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->deplacement->supprimer) { $deplacement = new Deplacement($db); $result=$deplacement->delete($_GET["id"]); if ($result >= 0) { Header("Location: index.php"); exit; } else { $mesg=$deplacement->error; } } if ($_POST["action"] == 'add' && $user->rights->deplacement->creer) { if (! $_POST["cancel"]) { $error=0; $dated=dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); $deplacement = new Deplacement($db); $deplacement->date = $dated; $deplacement->km = $_POST["km"]; $deplacement->type = $_POST["type"]; $deplacement->socid = $_POST["socid"]; $deplacement->fk_user = $_POST["fk_user"]; if (! $deplacement->date) { $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")); $error++; } if ($deplacement->type == '-1') // Otherwise it is TF_LUNCH,... { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'
'; $error++; } if (! ($deplacement->fk_user > 0)) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Person")).'
'; $error++; } if (! $error) { $id = $deplacement->create($user); if ($id > 0) { Header ( "Location: fiche.php?id=".$id); exit; } else { $mesg=$deplacement->error; $_GET["action"]='create'; } } else { $_GET["action"]='create'; } } else { Header ( "Location: index.php"); exit; } } if ($_POST["action"] == 'update' && $user->rights->deplacement->creer) { if (empty($_POST["cancel"])) { $deplacement = new Deplacement($db); $result = $deplacement->fetch($_POST["id"]); $deplacement->date = dol_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); $deplacement->km = $_POST["km"]; $deplacement->type = $_POST["type"]; $deplacement->fk_user = $_POST["fk_user"]; $deplacement->socid = $_POST["socid"]; $result = $deplacement->update($user); if ($result > 0) { Header("Location: fiche.php?id=".$_POST["id"]); exit; } else { $mesg=$deplacement->error; } } else { Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST["id"]); exit; } } // Set into a project if ($_POST['action'] == 'classin') { $trip = new Deplacement($db); $trip->fetch($_GET['id']); $result=$trip->setProject($_POST['projectid']); if ($result < 0) dol_print_error($db,$trip->error); } /* * View */ llxHeader(); $html = new Form($db); /* * Action create */ if ($_GET["action"] == 'create') { print_fiche_titre($langs->trans("NewTrip")); dol_htmloutput_errors($mesg); $datec = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); print "
\n"; print ''; print ''; print ''; print ""; print ''; print ""; print ''; print ""; print ''; // Km print ''; // Company print ""; print ''; print '
'.$langs->trans("Type").''; print $html->select_type_fees($_POST["type"]?$_POST["type"]:$_GET["type"],'type',1); print '
'.$langs->trans("Person").''; print $html->select_users($_POST["fk_user"]?$_POST["fk_user"]:$_GET["fk_user"],'fk_user',1); print '
'.$langs->trans("Date").''; print $html->select_date($datec?$datec:-1,'','','','','add',1,1); print '
'.$langs->trans("FeesKilometersOrAmout").'
'.$langs->trans("CompanyVisited").''; print $html->select_societes($_POST["socid"]?$_POST["socid"]:$_GET["socid"],'socid','',1); print '
'; print '
    '; print ''; } else { if ($id) { $deplacement = new Deplacement($db); $result = $deplacement->fetch($id); if ($result > 0) { if ($mesg) print $mesg."
"; $h=0; $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/fiche.php?id=$deplacement->id"; $head[$h][1] = $langs->trans("Card"); $head[$h][2] = 'card'; $h++; $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/note.php?id=$deplacement->id"; $head[$h][1] = $langs->trans("Note"); $head[$h][2] = 'note'; $h++; dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip'); if ($_GET["action"] == 'edit') { $soc = new Societe($db); if ($deplacement->socid) { $soc->fetch($deplacement->socid); } print "\n"; print ''; print ''; print ''; print ''; // Ref print ""; print ''; // Type print ""; print ''; // Who print ""; print ''; // Date print ''; // Km print ''; // Where print ""; print ''; print '
'.$langs->trans("Ref").''; print $deplacement->ref; print '
'.$langs->trans("Type").''; print $html->select_type_fees($_POST["type"]?$_POST["type"]:$deplacement->type,'type',0); print '
'.$langs->trans("Person").''; print $html->select_users($_POST["fk_user"]?$_POST["fk_user"]:$deplacement->fk_user,'fk_user',0); print '
'.$langs->trans("Date").''; print $html->select_date($deplacement->date,'','','','','update'); print '
'.$langs->trans("FeesKilometersOrAmout").'
'.$langs->trans("CompanyVisited").''; print $html->select_societes($soc->id,'socid','',1); print '
'; print '
  '; print ''; print '
'; print ''; print ''; } else { /* * Confirmation de la suppression du deplacement */ if ($_GET["action"] == 'delete') { $ret=$html->form_confirm("fiche.php?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete"); if ($ret == 'html') print '
'; } $soc = new Societe($db); if ($deplacement->socid) $soc->fetch($deplacement->socid); print ''; // Ref print ""; print ''; // Type print ''; // Who print ''; // Date print ''; // Km/Price print ''; // Where print ''; print ''; // Project if ($conf->projet->enabled) { $langs->load('projects'); print ''; print ''; print ''; } // Statut print ''; print "
'.$langs->trans("Ref").''; print $html->showrefnav($deplacement,'id','',1,'rowid','ref',''); print '
'.$langs->trans("Type").''.$langs->trans($deplacement->type).'
'.$langs->trans("Person").''; $userfee=new User($db); $userfee->fetch($deplacement->fk_user); print $userfee->getNomUrl(1); print '
'.$langs->trans("Date").''; print dol_print_date($deplacement->date,'day'); print '
'.$langs->trans("FeesKilometersOrAmout").''.$deplacement->km.'
'.$langs->trans("CompanyVisited").''; if ($soc->id) print $soc->getNomUrl(1); print '
'; print ''; if ($_GET['action'] != 'classin') { print ''; } print '
'; print $langs->trans('Project'); print 'id.'">'; print img_edit($langs->trans('SetProject'),1); print '
'; print '
'; if ($_GET['action'] == 'classin') { $html->form_project($_SERVER['PHP_SELF'].'?id='.$deplacement->id, $deplacement->socid, $deplacement->fk_project,'projectid'); } else { $html->form_project($_SERVER['PHP_SELF'].'?id='.$deplacement->id, $deplacement->socid, $deplacement->fk_project,'none'); } print '
'.$langs->trans("Status").''.$deplacement->getLibStatut(4).'
"; print ''; } } else { dol_print_error($db); } } } /* * Barre d'actions * */ print '
'; if ($_GET["action"] != 'create' && $_GET["action"] != 'edit') { if ($user->rights->deplacement->creer) { print ''.$langs->trans('Modify').''; } else { print ''.$langs->trans('Modify').''; } if ($user->rights->deplacement->supprimer) { print ''.$langs->trans('Delete').''; } else { print ''.$langs->trans('Delete').''; } } print '
'; $db->close(); llxFooter('$Date: 2011/08/03 00:46:35 $ - $Revision: 1.56 $'); ?>