Files
dolibarr/htdocs/compta/deplacement/deplacement.class.php
opensides ba95c1b6fc changement de <?PHPen <?php
suivra l'indentation correcte du code ;-)
2004-10-19 20:35:36 +00:00

135 lines
2.8 KiB
PHP

<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 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
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/
class Deplacement
{
var $db;
var $id;
var $user;
var $km;
var $note;
/*
* Initialistation automatique de la classe
*/
function Deplacement($DB)
{
$this->db = $DB;
return 1;
}
/*
*
*/
function create($user)
{
$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();
if ( $this->update($user) )
{
return $this->id;
}
}
}
/*
*
*/
function update($user)
{
if (strlen($this->km)==0)
$this->km = 0;
$sql = "UPDATE ".MAIN_DB_PREFIX."deplacement ";
$sql .= " SET km = $this->km";
$sql .= " , dated = '".$this->db->idate($this->date)."'";
$sql .= " , fk_user = $this->userid";
$sql .= " , fk_soc = $this->socid";
$sql .= " WHERE rowid = ".$this->id;
$result = $this->db->query($sql);
if ($result)
{
return 1;
}
else
{
print $this->db->error();
print "<br>".$sql;
return 0;
}
}
/*
*
*/
function fetch ($id)
{
$sql = "SELECT fk_user, km, fk_soc,".$this->db->pdate("dated")." as dated";
$sql .= " FROM ".MAIN_DB_PREFIX."deplacement WHERE rowid = $id";
$result = $this->db->query($sql) ;
if ( $result )
{
$result = $this->db->fetch_array();
$this->id = $id;
$this->date = $result["dated"];
$this->userid = $result["fk_user"];
$this->socid = $result["fk_soc"];
$this->km = $result["km"];
return 1;
}
else {
print $this->db->error();
print "<br>".$sql;
}
}
/*
*
*/
function delete($id)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."deplacement WHERE rowid = $id";
$result = $this->db->query($sql);
if ($result)
{
return 1;
}
else
{
return 0;
}
}
/*
*
*/
}
?>