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,16 +14,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/ */
/*! \file htdocs/compta/comptacompte.class.php /**
\ingroup compta * \file htdocs/compta/comptacompte.class.php
\brief Fichier de la classe des comptes comptable * \ingroup compta
\version $Revision$ * \brief Fichier de la classe des comptes comptable
* \version $Id$
*/ */

View File

@ -15,19 +15,22 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/ */
/** /**
\file htdocs/compta/deplacement/deplacement.class.php \file htdocs/compta/deplacement/deplacement.class.php
\ingroup deplacement \ingroup deplacement
\brief Fichier de la classe des deplacements \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 $db;
var $id; var $id;
@ -45,15 +48,29 @@ class Deplacement
return 1; 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) function create($user)
{ {
// Check parameters
if (empty($this->type) || $this->type < 0)
{
$this->error='ErrorBadParameter';
return -1;
}
$this->db->begin(); $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); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -86,20 +103,23 @@ class Deplacement
{ {
global $langs; global $langs;
// Check parameters
if (! is_numeric($this->km)) $this->km = 0; if (! is_numeric($this->km)) $this->km = 0;
if (! $this->socid) if (empty($this->type) || $this->type < 0)
{ {
$this->error=$langs->trans("ErrorSocidNotDefined"); $this->error='ErrorBadParameter';
return -1; 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 .= " , type = '".$this->type."'";
$sql .= " , fk_user = ".$this->userid; $sql .= " , fk_user = ".$this->userid;
$sql .= " , fk_soc = ".$this->socid; $sql .= " , fk_soc = ".($this->socid > 0?$this->socid:'null');
$sql .= " WHERE rowid = ".$this->id; $sql .= " WHERE rowid = ".$this->id;
dolibarr_syslog("Deplacement::update sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) 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 = "SELECT rowid, fk_user, type, km, fk_soc,".$this->db->pdate("dated")." as dated";
$sql .= " FROM ".MAIN_DB_PREFIX."deplacement WHERE rowid = $id"; $sql.= " FROM ".MAIN_DB_PREFIX."deplacement";
$sql.= " WHERE rowid = ".$id;
dolibarr_syslog("Deplacement::fetch sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
if ( $result ) 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; return 1;
} }
else else

View File

@ -59,6 +59,7 @@ if ($_POST["action"] == 'add' && $user->rights->deplacement->creer)
$_POST["reyear"]); $_POST["reyear"]);
$deplacement->km = $_POST["km"]; $deplacement->km = $_POST["km"];
$deplacement->type = $_POST["type"];
$deplacement->socid = $_POST["socid"]; $deplacement->socid = $_POST["socid"];
$deplacement->userid = $user->id; //$_POST["km"]; $deplacement->userid = $user->id; //$_POST["km"];
$id = $deplacement->create($user); $id = $deplacement->create($user);
@ -70,7 +71,8 @@ if ($_POST["action"] == 'add' && $user->rights->deplacement->creer)
} }
else else
{ {
dolibarr_print_error($db,$deplacement->error); $mesg=$deplacement->error;
$_GET["action"]='create';
} }
} }
else else
@ -93,6 +95,7 @@ if ($_POST["action"] == 'update' && $user->rights->deplacement->creer)
$_POST["reyear"]); $_POST["reyear"]);
$deplacement->km = $_POST["km"]; $deplacement->km = $_POST["km"];
$deplacement->type = $_POST["type"];
$result = $deplacement->update($user); $result = $deplacement->update($user);
@ -103,7 +106,7 @@ if ($_POST["action"] == 'update' && $user->rights->deplacement->creer)
} }
else else
{ {
print $mesg=$langs->trans("ErrorUnknown"); $mesg=$deplacement->error;
} }
} }
else else
@ -124,17 +127,24 @@ $html = new Form($db);
*/ */
if ($_GET["action"] == 'create') if ($_GET["action"] == 'create')
{ {
print_fiche_titre($langs->trans("NewTrip"));
if ($mesg) print $mesg."<br>";
print "<form name='add' action=\"fiche.php\" method=\"post\">\n"; print "<form name='add' action=\"fiche.php\" method=\"post\">\n";
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
print_fiche_titre($langs->trans("NewTrip"));
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("Person").'</td><td>'.$user->fullname.'</td></tr>'; print '<tr><td width="20%">'.$langs->trans("Person").'</td><td>'.$user->fullname.'</td></tr>';
print "<tr>"; print "<tr>";
print '<td>'.$langs->trans("CompanyVisited").'</td><td>'; 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 '</td></tr>';
print "<tr>"; print "<tr>";
@ -157,7 +167,7 @@ else
if ($result) if ($result)
{ {
if ($mesg) print "$mesg<br>"; if ($mesg) print $mesg."<br>";
if ($_GET["action"] == 'edit') if ($_GET["action"] == 'edit')
{ {
@ -184,6 +194,11 @@ else
print $html->select_societes($soc->id); print $html->select_societes($soc->id);
print '</td></tr>'; 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 '<tr><td>'.$langs->trans("Date").'</td><td>';
print $html->select_date($deplacement->date,'','','','','update'); print $html->select_date($deplacement->date,'','','','','update');
print '</td></tr>'; print '</td></tr>';
@ -223,6 +238,7 @@ else
print '<table class="border" width="100%">'; 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("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("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 '<tr><td>'.$langs->trans("Date").'</td><td>';
print dolibarr_print_date($deplacement->date); print dolibarr_print_date($deplacement->date);
print '</td></tr>'; print '</td></tr>';

View File

@ -14,15 +14,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/ */
/** /**
\file htdocs/compta/paiement_charge.php \file htdocs/compta/paiement_charge.php
\ingroup compta \ingroup compta
\brief Page de création d'un paiement d'une charge \brief Page de création d'un paiement d'une charge
\version $Revision$ \version $Id$
*/ */
include_once("./pre.inc.php"); include_once("./pre.inc.php");

View File

@ -578,14 +578,15 @@ class Form
/** /**
* \brief Retourne la liste des types de comptes financiers * \brief Return list of social contributions
* \param selected Type pré-sélectionné * \param selected Preselected type
* \param htmlname Nom champ formulaire * \param htmlname Name of field in form
*/ */
function select_type_socialcontrib($selected='',$htmlname='actioncode') function select_type_socialcontrib($selected='',$htmlname='actioncode')
{ {
global $db,$langs,$user; global $db,$langs,$user;
print '<select class="flat" name="'.$htmlname.'">';
$sql = "SELECT c.id, c.libelle as type FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; $sql = "SELECT c.id, c.libelle as type FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
$sql .= " ORDER BY lower(c.libelle) ASC"; $sql .= " ORDER BY lower(c.libelle) ASC";
$resql=$db->query($sql); $resql=$db->query($sql);
@ -597,7 +598,51 @@ class Form
while ($i < $num) while ($i < $num)
{ {
$obj = $db->fetch_object($resql); $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++; $i++;
} }
} }
@ -607,8 +652,8 @@ class Form
/** /**
* \brief Output html form to select a third party * \brief Output html form to select a third party
* \param selected Societe pré-sélectionnée * \param selected Preselected type
* \param htmlname Nom champ formulaire * \param htmlname Name of field in form
* \param filter Criteres optionnels de filtre * \param filter Criteres optionnels de filtre
* \param showempty Add an empty field * \param showempty Add an empty field
*/ */

View File

@ -10,3 +10,6 @@ CompanyVisited=Company/fundation visited
Kilometers=Kilometers Kilometers=Kilometers
DeleteTrip=Delete trip DeleteTrip=Delete trip
ConfirmDeleteTrip=Are you sure you want to delete this 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 Kilometers=Kilomètres
DeleteTrip=Supprimer déplacement DeleteTrip=Supprimer déplacement
ConfirmDeleteTrip=Êtes vous sur de vouloir supprimer ce déplacement ? ConfirmDeleteTrip=Êtes vous sur de vouloir supprimer ce déplacement ?
TF_OTHER=Autre
TF_LUNCH=Repas
TF_TRIP=Déplacement