dolibarr/htdocs/compta/deplacement/fiche.php

436 lines
12 KiB
PHP
Raw Normal View History

<?php
2005-01-09 22:20:30 +01:00
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
2003-09-02 19:41:30 +02:00
*
* 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
2011-08-03 02:45:22 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2003-09-02 19:41:30 +02:00
*/
2005-04-27 23:53:41 +02:00
/**
2008-11-15 22:18:40 +01:00
* \file htdocs/compta/deplacement/fiche.php
* \brief Page to show a trip card
2008-11-15 22:18:40 +01:00
*/
2010-03-27 03:35:08 +01:00
require("../../main.inc.php");
2010-04-25 14:55:26 +02:00
require_once(DOL_DOCUMENT_ROOT."/compta/deplacement/class/deplacement.class.php");
2010-05-03 10:43:32 +02:00
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
if ($conf->projet->enabled)
{
require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
2010-04-29 16:34:21 +02:00
require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
}
2003-09-02 19:41:30 +02:00
2005-04-27 23:53:41 +02:00
$langs->load("trips");
2008-02-25 17:30:43 +01:00
// Security check
2005-04-27 23:53:41 +02:00
$id=isset($_GET["id"])?$_GET["id"]:$_POST["id"];
2008-02-25 21:03:21 +01:00
if ($user->societe_id) $socid=$user->societe_id;
2008-03-01 02:26:41 +01:00
$result = restrictedArea($user, 'deplacement', $id,'');
2005-04-27 23:53:41 +02:00
2003-09-02 19:41:30 +02:00
$mesg = '';
2005-04-27 23:53:41 +02:00
2005-04-27 23:53:41 +02:00
/*
* Actions
*/
2008-02-25 17:30:43 +01:00
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->deplacement->supprimer)
2003-09-03 02:26:19 +02:00
{
2006-11-11 02:50:38 +01:00
$deplacement = new Deplacement($db);
2009-10-15 15:39:40 +02:00
$result=$deplacement->delete($_GET["id"]);
if ($result >= 0)
{
Header("Location: index.php");
exit;
}
else
{
$mesg=$deplacement->error;
}
2003-09-03 02:26:19 +02:00
}
2008-02-25 17:30:43 +01:00
if ($_POST["action"] == 'add' && $user->rights->deplacement->creer)
2003-09-02 19:41:30 +02:00
{
2008-02-25 17:30:43 +01:00
if (! $_POST["cancel"])
2006-11-11 02:50:38 +01:00
{
$error=0;
$dated=dol_mktime(12, 0, 0,
2008-11-15 22:18:40 +01:00
$_POST["remonth"],
$_POST["reday"],
$_POST["reyear"]);
2008-02-25 17:30:43 +01:00
$deplacement = new Deplacement($db);
$deplacement->date = $dated;
2008-02-25 17:30:43 +01:00
$deplacement->km = $_POST["km"];
2008-05-26 01:46:19 +02:00
$deplacement->type = $_POST["type"];
2008-02-25 17:30:43 +01:00
$deplacement->socid = $_POST["socid"];
2008-05-26 02:03:51 +02:00
$deplacement->fk_user = $_POST["fk_user"];
2008-11-15 22:18:40 +01:00
if (! $deplacement->date)
{
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date"));
$error++;
}
if ($deplacement->type == '-1') // Otherwise it is TF_LUNCH,...
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'</div>';
$error++;
}
if (! ($deplacement->fk_user > 0))
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Person")).'</div>';
$error++;
}
2008-02-25 17:30:43 +01:00
if (! $error)
2008-02-25 17:30:43 +01:00
{
$id = $deplacement->create($user);
if ($id > 0)
{
Header("Location: fiche.php?id=".$id);
exit;
}
else
{
$mesg=$deplacement->error;
$_GET["action"]='create';
}
2008-02-25 17:30:43 +01:00
}
else
{
2008-05-26 01:46:19 +02:00
$_GET["action"]='create';
2008-02-25 17:30:43 +01:00
}
2006-11-11 02:50:38 +01:00
}
else
{
Header("Location: index.php");
2008-02-25 17:30:43 +01:00
exit;
2006-11-11 02:50:38 +01:00
}
2003-09-02 19:41:30 +02:00
}
2008-02-25 17:30:43 +01:00
if ($_POST["action"] == 'update' && $user->rights->deplacement->creer)
2003-09-02 19:41:30 +02:00
{
2008-06-04 02:19:36 +02:00
if (empty($_POST["cancel"]))
2006-11-11 02:50:38 +01:00
{
2008-02-25 17:30:43 +01:00
$deplacement = new Deplacement($db);
$result = $deplacement->fetch($_POST["id"]);
2008-11-15 22:18:40 +01:00
$deplacement->date = dol_mktime(12, 0 , 0,
2008-11-15 22:18:40 +01:00
$_POST["remonth"],
$_POST["reday"],
$_POST["reyear"]);
$deplacement->km = $_POST["km"];
$deplacement->type = $_POST["type"];
2008-05-26 02:03:51 +02:00
$deplacement->fk_user = $_POST["fk_user"];
2008-11-15 22:18:40 +01:00
$deplacement->socid = $_POST["socid"];
2008-02-25 17:30:43 +01:00
$result = $deplacement->update($user);
2008-11-15 22:18:40 +01:00
2008-02-25 17:30:43 +01:00
if ($result > 0)
{
2008-05-26 01:46:19 +02:00
Header("Location: fiche.php?id=".$_POST["id"]);
2008-02-25 17:30:43 +01:00
exit;
}
else
{
2008-05-26 01:46:19 +02:00
$mesg=$deplacement->error;
2008-02-25 17:30:43 +01:00
}
2006-11-11 02:50:38 +01:00
}
else
{
2008-06-04 02:19:36 +02:00
Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST["id"]);
2008-02-25 17:30:43 +01:00
exit;
2006-11-11 02:50:38 +01:00
}
2003-09-02 19:41:30 +02:00
}
// 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);
}
2003-09-02 19:41:30 +02:00
/*
* View
*/
2005-04-27 23:53:41 +02:00
2003-09-02 19:41:30 +02:00
llxHeader();
2005-04-27 23:53:41 +02:00
$html = new Form($db);
2003-09-02 19:41:30 +02:00
/*
2005-04-27 23:53:41 +02:00
* Action create
2003-09-02 19:41:30 +02:00
*/
if ($_GET["action"] == 'create')
2003-09-02 19:41:30 +02:00
{
2008-11-15 22:18:40 +01:00
print_fiche_titre($langs->trans("NewTrip"));
2006-11-11 02:50:38 +01:00
2011-06-18 00:24:52 +02:00
dol_htmloutput_errors($mesg);
2008-11-15 22:18:40 +01:00
$datec = dol_mktime(12, 0, 0,
$_POST["remonth"],
$_POST["reday"],
$_POST["reyear"]);
2008-11-15 22:18:40 +01:00
print "<form name='add' action=\"fiche.php\" method=\"post\">\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2008-11-15 22:18:40 +01:00
print '<input type="hidden" name="action" value="add">';
print '<table class="border" width="100%">';
print "<tr>";
print '<td width="25%" class="fieldrequired">'.$langs->trans("Type").'</td><td>';
print $html->select_type_fees($_POST["type"]?$_POST["type"]:$_GET["type"],'type',1);
2008-11-15 22:18:40 +01:00
print '</td></tr>';
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
print $html->select_users($_POST["fk_user"]?$_POST["fk_user"]:$_GET["fk_user"],'fk_user',1);
2008-11-15 22:18:40 +01:00
print '</td></tr>';
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
2010-03-26 22:39:12 +01:00
print $html->select_date($datec?$datec:-1,'','','','','add',1,1);
2008-11-15 22:18:40 +01:00
print '</td></tr>';
2011-06-29 19:55:32 +02:00
// Km
print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td><input name="km" size="10" value="'.($_POST["km"]?$_POST["km"]:'').'"></td></tr>';
// Company
print "<tr>";
print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
print $html->select_societes($_POST["socid"]?$_POST["socid"]:$_GET["socid"],'socid','',1);
print '</td></tr>';
2011-06-29 19:55:32 +02:00
print '</table>';
2011-06-29 19:55:32 +02:00
print '<br><center><input class="button" type="submit" value="'.$langs->trans("Save").'"> &nbsp; &nbsp; ';
print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></center';
2008-11-15 22:18:40 +01:00
print '</form>';
2003-09-02 19:41:30 +02:00
}
else
{
2008-11-15 22:18:40 +01:00
if ($id)
2006-11-11 02:50:38 +01:00
{
2008-11-15 22:18:40 +01:00
$deplacement = new Deplacement($db);
$result = $deplacement->fetch($id);
if ($result > 0)
2008-11-15 22:18:40 +01:00
{
if ($mesg) print $mesg."<br>";
2010-01-15 00:21:22 +01:00
$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');
2008-11-15 22:18:40 +01:00
if ($_GET["action"] == 'edit')
{
$soc = new Societe($db);
if ($deplacement->socid)
{
$soc->fetch($deplacement->socid);
}
2008-11-15 22:18:40 +01:00
print "<form name='update' action=\"fiche.php\" method=\"post\">\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2008-11-15 22:18:40 +01:00
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$id.'">';
print '<table class="border" width="100%">';
// Ref
2008-11-15 22:18:40 +01:00
print "<tr>";
print '<td width="20%">'.$langs->trans("Ref").'</td><td>';
print $deplacement->ref;
print '</td></tr>';
// Type
2008-11-15 22:18:40 +01:00
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
print $html->select_type_fees($_POST["type"]?$_POST["type"]:$deplacement->type,'type',0);
2008-11-15 22:18:40 +01:00
print '</td></tr>';
// Who
2008-11-15 22:18:40 +01:00
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
print $html->select_users($_POST["fk_user"]?$_POST["fk_user"]:$deplacement->fk_user,'fk_user',0);
2008-11-15 22:18:40 +01:00
print '</td></tr>';
// Date
print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
print $html->select_date($deplacement->date,'','','','','update');
print '</td></tr>';
2011-06-29 19:55:32 +02:00
// Km
print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td><input name="km" class="flat" size="10" value="'.$deplacement->km.'"></td></tr>';
// Where
print "<tr>";
print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
print $html->select_societes($soc->id,'socid','',1);
print '</td></tr>';
2008-11-15 22:18:40 +01:00
print '</table>';
print '<br><center><input type="submit" class="button" value="'.$langs->trans("Save").'"> &nbsp; ';
print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">';
print '</center>';
2008-11-15 22:18:40 +01:00
print '</form>';
print '</div>';
}
else
{
/*
2010-01-15 00:21:22 +01:00
* Confirmation de la suppression du deplacement
2008-11-15 22:18:40 +01:00
*/
if ($_GET["action"] == 'delete')
{
$ret=$html->form_confirm("fiche.php?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete");
if ($ret == 'html') print '<br>';
2008-11-15 22:18:40 +01:00
}
$soc = new Societe($db);
if ($deplacement->socid) $soc->fetch($deplacement->socid);
print '<table class="border" width="100%">';
// Ref
2008-11-15 22:18:40 +01:00
print "<tr>";
print '<td width="20%">'.$langs->trans("Ref").'</td><td>';
2011-06-02 00:58:20 +02:00
print $html->showrefnav($deplacement,'id','',1,'rowid','ref','');
2008-11-15 22:18:40 +01:00
print '</td></tr>';
// Type
2008-11-15 22:18:40 +01:00
print '<tr><td>'.$langs->trans("Type").'</td><td>'.$langs->trans($deplacement->type).'</td></tr>';
// Who
2008-11-15 22:18:40 +01:00
print '<tr><td>'.$langs->trans("Person").'</td><td>';
$userfee=new User($db);
$userfee->fetch($deplacement->fk_user);
2008-11-15 22:18:40 +01:00
print $userfee->getNomUrl(1);
print '</td></tr>';
// Date
print '<tr><td>'.$langs->trans("Date").'</td><td>';
2011-05-12 01:05:03 +02:00
print dol_print_date($deplacement->date,'day');
print '</td></tr>';
// Km/Price
2008-11-15 22:18:40 +01:00
print '<tr><td>'.$langs->trans("FeesKilometersOrAmout").'</td><td>'.$deplacement->km.'</td></tr>';
2011-06-29 19:55:32 +02:00
// Where
print '<tr><td>'.$langs->trans("CompanyVisited").'</td>';
print '<td>';
if ($soc->id) print $soc->getNomUrl(1);
print '</td></tr>';
// Project
if ($conf->projet->enabled)
{
$langs->load('projects');
print '<tr>';
print '<td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Project');
print '</td>';
2011-08-23 20:40:45 +02:00
if ($_GET['action'] != 'classify')
{
2011-08-23 20:40:45 +02:00
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$deplacement->id.'">';
print img_edit($langs->trans('SetProject'),1);
print '</a></td>';
}
print '</tr></table>';
print '</td><td colspan="3">';
2011-08-23 20:40:45 +02:00
if ($_GET['action'] == 'classify')
{
$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 '</td>';
print '</tr>';
}
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$deplacement->getLibStatut(4).'</td></tr>';
2008-11-15 22:18:40 +01:00
print "</table>";
print '</div>';
}
2006-11-11 02:50:38 +01:00
2008-11-15 22:18:40 +01:00
}
else
{
dol_print_error($db);
2008-11-15 22:18:40 +01:00
}
2003-09-02 19:41:30 +02:00
}
}
/*
* Barre d'actions
*
*/
print '<div class="tabsAction">';
2005-04-27 23:53:41 +02:00
if ($_GET["action"] != 'create' && $_GET["action"] != 'edit')
2003-09-02 19:41:30 +02:00
{
2009-10-15 15:39:40 +02:00
if ($user->rights->deplacement->creer)
{
print '<a class="butAction" href="fiche.php?action=edit&id='.$id.'">'.$langs->trans('Modify').'</a>';
}
else
{
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Modify').'</a>';
}
if ($user->rights->deplacement->supprimer)
{
print '<a class="butActionDelete" href="fiche.php?action=delete&id='.$id.'">'.$langs->trans('Delete').'</a>';
}
else
{
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Delete').'</a>';
}
2003-09-02 19:41:30 +02:00
}
2003-09-03 02:26:19 +02:00
print '</div>';
2003-09-02 19:41:30 +02:00
$db->close();
llxFooter();
2003-09-02 19:41:30 +02:00
?>