Fix: bug #18063 : Cannot create trip
This commit is contained in:
parent
9f81652147
commit
35b233b45f
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -20,6 +20,13 @@
|
|||||||
* $Source$
|
* $Source$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\file htdocs/compta/deplacement/deplacement.class.php
|
||||||
|
\ingroup deplacement
|
||||||
|
\brief Fichier de la classe des deplacements
|
||||||
|
\version $Revision$
|
||||||
|
*/
|
||||||
|
|
||||||
class Deplacement
|
class Deplacement
|
||||||
{
|
{
|
||||||
var $db;
|
var $db;
|
||||||
@ -37,36 +44,60 @@ class Deplacement
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function create($user)
|
function create($user)
|
||||||
{
|
{
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."deplacement (datec, fk_user_author) VALUES (now(), $user->id)";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."deplacement (datec, fk_user_author) VALUES (now(), $user->id)";
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."deplacement");
|
$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;
|
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)
|
function update($user)
|
||||||
{
|
{
|
||||||
if (strlen($this->km)==0)
|
global $langs;
|
||||||
$this->km = 0;
|
|
||||||
|
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 = "UPDATE ".MAIN_DB_PREFIX."deplacement ";
|
||||||
$sql .= " SET km = $this->km";
|
$sql .= " SET km = ".$this->km;
|
||||||
$sql .= " , dated = '".$this->db->idate($this->date)."'";
|
$sql .= " , dated = '".$this->db->idate($this->date)."'";
|
||||||
$sql .= " , fk_user = $this->userid";
|
$sql .= " , fk_user = ".$this->userid;
|
||||||
$sql .= " , fk_soc = $this->socid";
|
$sql .= " , fk_soc = ".$this->socid;
|
||||||
$sql .= " WHERE rowid = ".$this->id;
|
$sql .= " WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
@ -76,11 +107,11 @@ class Deplacement
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print $this->db->error();
|
$this->error=$this->db->error();
|
||||||
print "<br>".$sql;
|
return -1;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -103,17 +134,19 @@ class Deplacement
|
|||||||
$this->km = $result["km"];
|
$this->km = $result["km"];
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
print $this->db->error();
|
{
|
||||||
print "<br>".$sql;
|
$this->error=$this->db->error();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function delete($id)
|
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);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
@ -122,12 +155,10 @@ class Deplacement
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return 0;
|
$this->error=$this->db->error();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* 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
|
* 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
|
* 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 = new Deplacement($db);
|
||||||
$deplacement->delete($_GET["id"]);
|
$deplacement->delete($_GET["id"]);
|
||||||
Header("Location: index.php");
|
Header("Location: index.php");
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
|
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"];
|
$deplacement->userid = $user->id; //$_POST["km"];
|
||||||
$id = $deplacement->create($user);
|
$id = $deplacement->create($user);
|
||||||
|
|
||||||
if ($id)
|
if ($id > 0)
|
||||||
{
|
{
|
||||||
Header ( "Location: fiche.php?id=".$id);
|
Header ( "Location: fiche.php?id=".$id);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_print_error($db);
|
dolibarr_print_error($db,$deplacement->error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,8 +126,8 @@ if ($_GET["action"] == 'create')
|
|||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("Kilometers").'</td><td><input name="km" size="10" value=""></td></tr>';
|
print '<tr><td>'.$langs->trans("Kilometers").'</td><td><input name="km" size="10" value=""></td></tr>';
|
||||||
print '<tr><td> </td><td><input type="submit" value="'.$langs->trans("Save").'"> ';
|
print '<tr><td colspan="2" align="center"><input class="button" type="submit" value="'.$langs->trans("Save").'"> ';
|
||||||
print '<input type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
|
print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
|
||||||
print '</table>';
|
print '</table>';
|
||||||
print '</form>';
|
print '</form>';
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user