Management of fees.

This commit is contained in:
Laurent Destailleur 2008-05-25 23:46:19 +00:00
parent 36aa89ba84
commit d266c4cc5c
7 changed files with 144 additions and 60 deletions

View File

@ -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

View File

@ -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

View File

@ -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 "<form name='add' action=\"fiche.php\" method=\"post\">\n";
print '<input type="hidden" name="action" value="add">';
print_fiche_titre($langs->trans("NewTrip"));
if ($mesg) print $mesg."<br>";
print "<form name='add' action=\"fiche.php\" method=\"post\">\n";
print '<input type="hidden" name="action" value="add">';
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("Person").'</td><td>'.$user->fullname.'</td></tr>';
print "<tr>";
print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
print $html->select_societes($_GET["socid"]);
print $html->select_societes($_GET["socid"],'socid','',1);
print '</td></tr>';
print "<tr>";
print '<td>'.$langs->trans("Type").'</td><td>';
print $html->select_type_fees($_GET["type"],'type',1);
print '</td></tr>';
print "<tr>";
print '<td>'.$langs->trans("Date").'</td><td>';
print $html->select_date('','','','','','add');
@ -157,8 +167,8 @@ else
if ($result)
{
if ($mesg) print "$mesg<br>";
if ($mesg) print $mesg."<br>";
if ($_GET["action"] == 'edit')
{
$h=0;
@ -184,6 +194,11 @@ else
print $html->select_societes($soc->id);
print '</td></tr>';
print "<tr>";
print '<td>'.$langs->trans("Type").'</td><td>';
print $html->select_type_fees($deplacement->type,'type',1);
print '</td></tr>';
print '<tr><td>'.$langs->trans("Date").'</td><td>';
print $html->select_date($deplacement->date,'','','','','update');
print '</td></tr>';
@ -223,6 +238,7 @@ else
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("Person").'</td><td><a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$user->id.'">'.$user->fullname.'</a></td></tr>';
print '<tr><td width="20%">'.$langs->trans("CompanyVisited").'</td><td>'.$soc->getNomUrl(1).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("Type").'</td><td>'.$langs->trans($deplacement->type).'</td></tr>';
print '<tr><td>'.$langs->trans("Date").'</td><td>';
print dolibarr_print_date($deplacement->date);
print '</td></tr>';

View File

@ -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");

View File

@ -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 '<select class="flat" name="'.$htmlname.'">';
$sql = "SELECT c.id, c.libelle as type FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
$sql .= " ORDER BY lower(c.libelle) ASC";
$resql=$db->query($sql);
if ($resql)
@ -597,18 +598,62 @@ class Form
while ($i < $num)
{
$obj = $db->fetch_object($resql);
print '<option value="'.$obj->id.'">'.$obj->type;
print '<option value="'.$obj->id.'"';
if ($obj->id == $selected) print ' selected="true"';
print '>'.$obj->type;
$i++;
}
}
print '</select>';
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 '<select class="flat" name="'.$htmlname.'">';
if ($showempty)
{
print '<option value="-1"';
if ($selected == -1) print ' selected="true"';
print '>&nbsp;</option>';
}
$sql = "SELECT c.code, c.libelle as type FROM ".MAIN_DB_PREFIX."c_type_fees as c";
$sql.= " ORDER BY lower(c.libelle) ASC";
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
print '<option value="'.$obj->code.'"';
if ($obj->code == $selected) print ' selected="true"';
print '>';
if ($obj->code != $langs->trans($obj->code)) print $langs->trans($obj->code);
else print $langs->trans($obj->type);
$i++;
}
}
print '</select>';
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
*/

View File

@ -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

View File

@ -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