From d266c4cc5c35483a003d72ad34beb773931e1809 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 25 May 2008 23:46:19 +0000 Subject: [PATCH] Management of fees. --- htdocs/compta/comptacompte.class.php | 15 ++-- .../compta/deplacement/deplacement.class.php | 74 ++++++++++++------- htdocs/compta/deplacement/fiche.php | 42 +++++++---- htdocs/compta/paiement_charge.php | 4 +- htdocs/html.form.class.php | 63 +++++++++++++--- htdocs/langs/en_US/trips.lang | 3 + htdocs/langs/fr_FR/trips.lang | 3 + 7 files changed, 144 insertions(+), 60 deletions(-) diff --git a/htdocs/compta/comptacompte.class.php b/htdocs/compta/comptacompte.class.php index 63d5362ec4d..1ec69c1192b 100644 --- a/htdocs/compta/comptacompte.class.php +++ b/htdocs/compta/comptacompte.class.php @@ -14,17 +14,14 @@ * 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$ - * */ -/*! \file htdocs/compta/comptacompte.class.php - \ingroup compta - \brief Fichier de la classe des comptes comptable - \version $Revision$ -*/ +/** + * \file htdocs/compta/comptacompte.class.php + * \ingroup compta + * \brief Fichier de la classe des comptes comptable + * \version $Id$ + */ /*! \class ComptaCompte diff --git a/htdocs/compta/deplacement/deplacement.class.php b/htdocs/compta/deplacement/deplacement.class.php index c3a3b8fa07e..2e3468278f8 100644 --- a/htdocs/compta/deplacement/deplacement.class.php +++ b/htdocs/compta/deplacement/deplacement.class.php @@ -15,19 +15,22 @@ * 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$ */ /** \file htdocs/compta/deplacement/deplacement.class.php \ingroup deplacement \brief Fichier de la classe des deplacements - \version $Revision$ + \version $Id$ */ -class Deplacement +require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); + +/** + \class Deplacement + \brief Class to manage trips and working credit notes +*/ +class Deplacement extends CommonObject { var $db; var $id; @@ -45,15 +48,29 @@ class Deplacement return 1; } - /* - * - */ + /** + * Create object in database + * + * @param unknown_type $user User that creat + * @param unknown_type $type Type of record: 0=trip, 1=credit note + * @return unknown + */ function create($user) { + // Check parameters + if (empty($this->type) || $this->type < 0) + { + $this->error='ErrorBadParameter'; + return -1; + } + $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"; + $sql.= " (datec, fk_user_author, fk_user, type)"; + $sql.= " VALUES (now(), ".$user->id.", ".$user->id.", '".$this->type."')"; + dolibarr_syslog("Deplacement::create sql=".$sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { @@ -85,21 +102,24 @@ class Deplacement function update($user) { global $langs; - + + // Check parameters if (! is_numeric($this->km)) $this->km = 0; - if (! $this->socid) + if (empty($this->type) || $this->type < 0) { - $this->error=$langs->trans("ErrorSocidNotDefined"); - return -1; + $this->error='ErrorBadParameter'; + return -1; } - + $sql = "UPDATE ".MAIN_DB_PREFIX."deplacement "; $sql .= " SET km = ".$this->km; $sql .= " , dated = '".$this->db->idate($this->date)."'"; + $sql .= " , type = '".$this->type."'"; $sql .= " , fk_user = ".$this->userid; - $sql .= " , fk_soc = ".$this->socid; + $sql .= " , fk_soc = ".($this->socid > 0?$this->socid:'null'); $sql .= " WHERE rowid = ".$this->id; + dolibarr_syslog("Deplacement::update sql=".$sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { @@ -112,26 +132,28 @@ class Deplacement } } - /* + /** * */ - function fetch ($id) + 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"; + $sql = "SELECT rowid, fk_user, type, km, fk_soc,".$this->db->pdate("dated")." as dated"; + $sql.= " FROM ".MAIN_DB_PREFIX."deplacement"; + $sql.= " WHERE rowid = ".$id; + dolibarr_syslog("Deplacement::fetch sql=".$sql, LOG_DEBUG); $result = $this->db->query($sql) ; - if ( $result ) { - $result = $this->db->fetch_array(); + $obj = $this->db->fetch_object($result); - $this->id = $id; + $this->id = $obj->rowid; + $this->date = $obj->dated; + $this->userid = $obj->fk_user; + $this->socid = $obj->fk_soc; + $this->km = $obj->km; + $this->type = $obj->type; - $this->date = $result["dated"]; - $this->userid = $result["fk_user"]; - $this->socid = $result["fk_soc"]; - $this->km = $result["km"]; return 1; } else diff --git a/htdocs/compta/deplacement/fiche.php b/htdocs/compta/deplacement/fiche.php index 1f478300ff3..18e89963271 100644 --- a/htdocs/compta/deplacement/fiche.php +++ b/htdocs/compta/deplacement/fiche.php @@ -18,9 +18,9 @@ */ /** - \file htdocs/compta/deplacement/fiche.php - \brief Page fiche d'un deplacement - \version $Id$ + \file htdocs/compta/deplacement/fiche.php + \brief Page fiche d'un deplacement + \version $Id$ */ require("./pre.inc.php"); @@ -59,6 +59,7 @@ if ($_POST["action"] == 'add' && $user->rights->deplacement->creer) $_POST["reyear"]); $deplacement->km = $_POST["km"]; + $deplacement->type = $_POST["type"]; $deplacement->socid = $_POST["socid"]; $deplacement->userid = $user->id; //$_POST["km"]; $id = $deplacement->create($user); @@ -70,7 +71,8 @@ if ($_POST["action"] == 'add' && $user->rights->deplacement->creer) } else { - dolibarr_print_error($db,$deplacement->error); + $mesg=$deplacement->error; + $_GET["action"]='create'; } } else @@ -93,22 +95,23 @@ if ($_POST["action"] == 'update' && $user->rights->deplacement->creer) $_POST["reyear"]); $deplacement->km = $_POST["km"]; + $deplacement->type = $_POST["type"]; $result = $deplacement->update($user); if ($result > 0) { - Header ( "Location: fiche.php?id=".$_POST["id"]); + Header("Location: fiche.php?id=".$_POST["id"]); exit; } else { - print $mesg=$langs->trans("ErrorUnknown"); + $mesg=$deplacement->error; } } else { - Header ( "Location: index.php"); + Header("Location: index.php"); exit; } } @@ -124,19 +127,26 @@ $html = new Form($db); */ if ($_GET["action"] == 'create') { - print "
\n"; - print ''; - print_fiche_titre($langs->trans("NewTrip")); + if ($mesg) print $mesg."
"; + + print "\n"; + print ''; + print ''; print ''; print ""; print ''; + print ""; + print ''; + print ""; print ''; + print ""; + print ''; + print ''; @@ -223,6 +238,7 @@ else print '
'.$langs->trans("Person").''.$user->fullname.'
'.$langs->trans("CompanyVisited").''; - print $html->select_societes($_GET["socid"]); + print $html->select_societes($_GET["socid"],'socid','',1); print '
'.$langs->trans("Type").''; + print $html->select_type_fees($_GET["type"],'type',1); + print '
'.$langs->trans("Date").''; print $html->select_date('','','','','','add'); @@ -157,8 +167,8 @@ else if ($result) { - if ($mesg) print "$mesg
"; - + if ($mesg) print $mesg."
"; + if ($_GET["action"] == 'edit') { $h=0; @@ -184,6 +194,11 @@ else print $html->select_societes($soc->id); print '
'.$langs->trans("Type").''; + print $html->select_type_fees($deplacement->type,'type',1); + print '
'.$langs->trans("Date").''; print $html->select_date($deplacement->date,'','','','','update'); print '
'; print ''; print ''; + print ''; print ''; diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index cda8d0013ef..e5b448864da 100755 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -14,15 +14,13 @@ * 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$ */ /** \file htdocs/compta/paiement_charge.php \ingroup compta \brief Page de création d'un paiement d'une charge - \version $Revision$ + \version $Id$ */ include_once("./pre.inc.php"); diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 9424ee02d94..11aa81ece9f 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -578,15 +578,16 @@ class Form /** - * \brief Retourne la liste des types de comptes financiers - * \param selected Type pré-sélectionné - * \param htmlname Nom champ formulaire - */ + * \brief Return list of social contributions + * \param selected Preselected type + * \param htmlname Name of field in form + */ function select_type_socialcontrib($selected='',$htmlname='actioncode') { global $db,$langs,$user; - $sql = "SELECT c.id, c.libelle as type FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + print ''; + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); + } + + /** + * \brief Return list of types of notes + * \param selected Preselected type + * \param htmlname Name of field in form + * \param showempty Add an empty field + */ + function select_type_fees($selected='',$htmlname='type',$showempty=0) + { + global $db,$langs,$user; + $langs->load("trips"); + + print ''; if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); } - + /** * \brief Output html form to select a third party - * \param selected Societe pré-sélectionnée - * \param htmlname Nom champ formulaire + * \param selected Preselected type + * \param htmlname Name of field in form * \param filter Criteres optionnels de filtre * \param showempty Add an empty field */ diff --git a/htdocs/langs/en_US/trips.lang b/htdocs/langs/en_US/trips.lang index a2eb56a2244..54f5c1ba8d3 100644 --- a/htdocs/langs/en_US/trips.lang +++ b/htdocs/langs/en_US/trips.lang @@ -10,3 +10,6 @@ CompanyVisited=Company/fundation visited Kilometers=Kilometers DeleteTrip=Delete trip ConfirmDeleteTrip=Are you sure you want to delete this trip ? +TF_OTHER=Other +TF_LUNCH=Lunch +TF_TRIP=Trip \ No newline at end of file diff --git a/htdocs/langs/fr_FR/trips.lang b/htdocs/langs/fr_FR/trips.lang index 08868b490c5..6fc7903d0ff 100644 --- a/htdocs/langs/fr_FR/trips.lang +++ b/htdocs/langs/fr_FR/trips.lang @@ -10,3 +10,6 @@ CompanyVisited=Soci Kilometers=Kilomètres DeleteTrip=Supprimer déplacement ConfirmDeleteTrip=Êtes vous sur de vouloir supprimer ce déplacement ? +TF_OTHER=Autre +TF_LUNCH=Repas +TF_TRIP=Déplacement \ No newline at end of file
'.$langs->trans("Person").''.$user->fullname.'
'.$langs->trans("CompanyVisited").''.$soc->getNomUrl(1).'
'.$langs->trans("Type").''.$langs->trans($deplacement->type).'
'.$langs->trans("Date").''; print dolibarr_print_date($deplacement->date); print '