Skip to content
Snippets Groups Projects
Commit 35b233b4 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Fix: bug #18063 : Cannot create trip

parent 9f816521
No related branches found
No related tags found
No related merge requests found
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
......@@ -20,6 +20,13 @@
* $Source$
*/
/**
\file htdocs/compta/deplacement/deplacement.class.php
\ingroup deplacement
\brief Fichier de la classe des deplacements
\version $Revision$
*/
class Deplacement
{
var $db;
......@@ -37,36 +44,60 @@ class Deplacement
return 1;
}
/*
*
*/
function create($user)
{
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."deplacement (datec, fk_user_author) VALUES (now(), $user->id)";
$result = $this->db->query($sql);
if ($result)
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."deplacement");
if ( $this->update($user) )
$result=$this->update($user);
if ($result > 0)
{
$this->db->commit();
return $this->id;
}
else
{
$this->db->rollback();
return $result;
}
}
else
{
$this->error=$this->db->error()." sql=".$sql;
$this->db->rollback();
return -1;
}
}
/*
*
*/
function update($user)
{
if (strlen($this->km)==0)
$this->km = 0;
global $langs;
if (! is_numeric($this->km)) $this->km = 0;
if (! $this->socid)
{
$this->error=$langs->trans("ErrorSocidNotDefined");
return -1;
}
$sql = "UPDATE ".MAIN_DB_PREFIX."deplacement ";
$sql .= " SET km = $this->km";
$sql .= " SET km = ".$this->km;
$sql .= " , dated = '".$this->db->idate($this->date)."'";
$sql .= " , fk_user = $this->userid";
$sql .= " , fk_soc = $this->socid";
$sql .= " , fk_user = ".$this->userid;
$sql .= " , fk_soc = ".$this->socid;
$sql .= " WHERE rowid = ".$this->id;
$result = $this->db->query($sql);
......@@ -76,11 +107,11 @@ class Deplacement
}
else
{
print $this->db->error();
print "<br>".$sql;
return 0;
$this->error=$this->db->error();
return -1;
}
}
/*
*
*/
......@@ -103,17 +134,19 @@ class Deplacement
$this->km = $result["km"];
return 1;
}
else {
print $this->db->error();
print "<br>".$sql;
else
{
$this->error=$this->db->error();
return -1;
}
}
/*
*
*/
function delete($id)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."deplacement WHERE rowid = $id";
$sql = "DELETE FROM ".MAIN_DB_PREFIX."deplacement WHERE rowid = ".$id;
$result = $this->db->query($sql);
if ($result)
......@@ -122,12 +155,10 @@ class Deplacement
}
else
{
return 0;
$this->error=$this->db->error();
return -1;
}
}
/*
*
*/
}
......
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
......@@ -43,6 +43,7 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes")
$deplacement = new Deplacement($db);
$deplacement->delete($_GET["id"]);
Header("Location: index.php");
exit;
}
if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
......@@ -59,14 +60,14 @@ if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
$deplacement->userid = $user->id; //$_POST["km"];
$id = $deplacement->create($user);
if ($id)
if ($id > 0)
{
Header ( "Location: fiche.php?id=".$id);
exit;
}
else
{
dolibarr_print_error($db);
dolibarr_print_error($db,$deplacement->error);
}
}
......@@ -125,8 +126,8 @@ if ($_GET["action"] == 'create')
print '</td></tr>';
print '<tr><td>'.$langs->trans("Kilometers").'</td><td><input name="km" size="10" value=""></td></tr>';
print '<tr><td>&nbsp;</td><td><input type="submit" value="'.$langs->trans("Save").'">&nbsp;';
print '<input type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
print '<tr><td colspan="2" align="center"><input class="button" type="submit" value="'.$langs->trans("Save").'">&nbsp;';
print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
print '</table>';
print '</form>';
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment