From d84623dc6a7e2dc428935d54b3ec948b6e36c940 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Tue, 2 Sep 2003 17:41:30 +0000 Subject: [PATCH] Nouveau fichier --- .../compta/deplacement/deplacement.class.php | 128 ++++++++++++ htdocs/compta/deplacement/fiche.php | 186 ++++++++++++++++++ htdocs/compta/deplacement/index.php | 107 ++++++++++ 3 files changed, 421 insertions(+) create mode 100644 htdocs/compta/deplacement/deplacement.class.php create mode 100644 htdocs/compta/deplacement/fiche.php create mode 100644 htdocs/compta/deplacement/index.php diff --git a/htdocs/compta/deplacement/deplacement.class.php b/htdocs/compta/deplacement/deplacement.class.php new file mode 100644 index 00000000000..4b1e17ed04f --- /dev/null +++ b/htdocs/compta/deplacement/deplacement.class.php @@ -0,0 +1,128 @@ + + * + * 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 llx_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 llx_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 "
".$sql; + return 0; + } + } + /* + * + */ + Function fetch ($id) + { + $sql = "SELECT rowid, fk_user, km, fk_soc,".$this->db->pdate("dated")." as dated"; + $sql .= " FROM llx_deplacement WHERE rowid = $id"; + + $result = $this->db->query($sql) ; + + if ( $result ) + { + $result = $this->db->fetch_array(); + + $this->id = $result["rowid"]; + $this->date = $result["dated"]; + $this->userid = $result["fk_user"]; + $this->socid = $result["fk_soc"]; + $this->km = $result["km"]; + return 1; + } + } + /* + * + */ + Function delete() + { + $sql = "DELETE FROM llx_deplacement WHERE rowid = $this->id)"; + + $result = $this->db->query($sql); + if ($result) + { + return 1; + } + else + { + return 0; + } + } + /* + * + */ + +} + +?> diff --git a/htdocs/compta/deplacement/fiche.php b/htdocs/compta/deplacement/fiche.php new file mode 100644 index 00000000000..6106e40fa70 --- /dev/null +++ b/htdocs/compta/deplacement/fiche.php @@ -0,0 +1,186 @@ + + * + * 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$ + * + */ +require("./pre.inc.php"); + +$mesg = ''; + +if ($HTTP_POST_VARS["action"] == 'add' && $HTTP_POST_VARS["cancel"] <> 'Annuler') +{ + $deplacement = new Deplacement($db); + + $deplacement->date = mktime(12, 1 , 1, + $HTTP_POST_VARS["remonth"], + $HTTP_POST_VARS["reday"], + $HTTP_POST_VARS["reyear"]); + + $deplacement->km = $HTTP_POST_VARS["km"]; + $deplacement->socid = $HTTP_POST_VARS["socid"]; + $deplacement->userid = $user->id; //$HTTP_POST_VARS["km"]; + $id = $deplacement->create($user); + + if ($id > 0) + { + Header ( "Location: fiche.php?id=$id"); + } + else + { + print "Error"; + } +} + +if ($HTTP_POST_VARS["action"] == 'update' && $HTTP_POST_VARS["cancel"] <> 'Annuler') +{ + $deplacement = new Deplacement($db); + $result = $deplacement->fetch($id); + + $deplacement->date = mktime(12, 1 , 1, + $HTTP_POST_VARS["remonth"], + $HTTP_POST_VARS["reday"], + $HTTP_POST_VARS["reyear"]); + + $deplacement->km = $HTTP_POST_VARS["km"]; + + $result = $deplacement->update($user); + + if ($result > 0) + { + Header ( "Location: fiche.php?id=$id"); + } + else + { + print "Error"; + } +} + + +llxHeader(); + +/* + * + * + */ +$html = new Form($db); +if ($action == 'create') +{ + print "
\n"; + print ''; + print ''; + print '
Nouveau déplacement

'; + + print ''; + print ''; + print ""; + print ''; + + print ''; + print ''; + print '
Personne'.$user->fullname.'
Date du déplacement'; + print $html->select_date(); + print '
Kilomètres
  '; + print '
'; + print '
'; +} +else +{ + if ($id) + { + $deplacement = new Deplacement($db); + $result = $deplacement->fetch($id); + + if ( $result ) + { + + if ($action == 'edit') + { + print_fiche_titre('Fiche déplacement : '.$product->ref, $mesg); + + print "
\n"; + print ''; + + print ''; + + $soc = new Societe($db); + $soc->fetch($deplacement->socid); + print ''; + print ''; + print ''; + print ''; + + print ''; + print '
Personne'.$user->fullname.'
Société visitée'.$soc->nom_url.'
Date du déplacement'; + print $html->select_date($deplacement->date); + print strftime("%A %d %B %Y",$deplacement->date); + print '
Kilomètres '.$deplacement->km.'
  '; + print '
'; + print '
'; + } + else + { + print_fiche_titre('Fiche déplacement : '.$product->ref, $mesg); + + print ''; + + $soc = new Societe($db); + $soc->fetch($deplacement->socid); + print ''; + print ''; + print ''; + + print ''; + print "
Personne'.$user->fullname.'
Société visitée'.$soc->nom_url.'
Date du déplacement'; + print strftime("%A %d %B %Y",$deplacement->date); + print '
Kilomètres'.$deplacement->km.'
"; + } + + } + else + { + print "Error"; + } + } +} +/* ************************************************************************** */ +/* */ +/* Barre d'action */ +/* */ +/* ************************************************************************** */ + +print '
'; +print ''; +print ''; +print ''; + +if ($action == 'create') +{ + print ''; +} +else +{ + print ''; +} +print ''; +print '
----[Editer]-

'; + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?> diff --git a/htdocs/compta/deplacement/index.php b/htdocs/compta/deplacement/index.php new file mode 100644 index 00000000000..26fac7c6fb6 --- /dev/null +++ b/htdocs/compta/deplacement/index.php @@ -0,0 +1,107 @@ + + * + * 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$ + * + */ +require("./pre.inc.php"); +require("../../tva.class.php3"); + +/* + * + * + */ +/* + * + */ + +llxHeader(); + +/* + * Liste + * + */ + +if ($sortorder == "") +{ + $sortorder="DESC"; +} +if ($sortfield == "") +{ + $sortfield="d.dated"; +} + +if ($page == -1) { $page = 0 ; } + +$limit = $conf->liste_limit; +$offset = $limit * $page ; +$pageprev = $page - 1; +$pagenext = $page + 1; + +$sql = "SELECT s.nom,s.idp, d.km,".$db->pdate("d.dated")." as dd, u.name, u.firstname, d.rowid"; +$sql .= " FROM llx_societe as s, llx_deplacement as d, llx_user as u "; +$sql .= " WHERE d.fk_soc = s.idp AND d.fk_user = u.rowid"; + +if ($user->societe_id > 0) +{ + $sql .= " AND s.idp = " . $user->societe_id; +} + +$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit( $limit + 1 ,$offset); + +if ( $db->query($sql) ) +{ + $num = $db->num_rows(); + print_barre_liste("Liste des déplacements", $page, $PHP_SELF,"&socidp=$socidp",$sortfield,$sortorder,'',$num); + + $i = 0; + print ''; + print ""; + print_liste_field_titre_new ("Date",$PHP_SELF,"d.dated","","&socidp=$socidp",'',$sortfield); + print_liste_field_titre_new ("Société",$PHP_SELF,"s.nom","","&socidp=$socidp",'',$sortfield); + print ''; + + print "\n"; + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object( $i); + $var=!$var; + print ""; + print ''; + print "\n"; + + print ''; + + print "\n"; + + $i++; + } + + print "
Utilisateur
'.strftime("%d %B %Y",$objp->dd).'idp\">$objp->nom'.$objp->firstname.' '.$objp->name.'
"; + $db->free(); +} +else +{ + print $db->error(); + print "

$sql"; +} +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?>