diff --git a/htdocs/chargesociales.class.php b/htdocs/chargesociales.class.php
index 5e3313fa660..0cb8b5f0d8e 100644
--- a/htdocs/chargesociales.class.php
+++ b/htdocs/chargesociales.class.php
@@ -29,7 +29,7 @@ require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php");
/** \class ChargeSociales
\brief Classe permettant la gestion des paiements des charges
- La tva collectée n'est calculée que sur les factures payées.
+ La tva collect�e n'est calcul�e que sur les factures pay�es.
*/
class ChargeSociales extends CommonObject
{
@@ -37,7 +37,7 @@ class ChargeSociales extends CommonObject
var $error;
var $element='rowid';
var $table_element='chargesociales';
-
+
var $id;
var $date_ech;
var $lib;
@@ -77,6 +77,7 @@ class ChargeSociales extends CommonObject
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
+ $this->ref = $obj->rowid;
$this->date_ech = $obj->date_ech;
$this->lib = $obj->lib;
$this->type = $obj->fk_type;
@@ -102,30 +103,30 @@ class ChargeSociales extends CommonObject
/**
- * \brief Crée une charge sociale
- * \param user Utilisateur qui crée
- * \return int <0 si KO, id charge créée si OK
+ * \brief Create a social contribution in database
+ * \param user User making creation
+ * \return int <0 if KO, id if OK
*/
function create($user)
{
// Nettoyage parametres
$newamount=price2num($this->amount,'MT');
-
+
// Validation parametres
if (! $newamount > 0)
{
$this->error="ErrorBadParameter";
return -2;
}
-
+
$this->db->begin();
-
+
$sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, libelle, date_ech, periode, amount)";
$sql.= " VALUES (".$this->type.",'".addslashes($this->lib)."',";
- $sql.= " '".$this->db->idate($this->date_ech)."','".$this->periode."',";
+ $sql.= " '".$this->db->idate($this->date_ech)."','".$this->db->idate($this->periode)."',";
$sql.= " ".price2num($newamount);
$sql.= ")";
-
+
dol_syslog("ChargesSociales::create sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
@@ -142,12 +143,12 @@ class ChargeSociales extends CommonObject
$this->db->rollback();
return -1;
}
- }
+ }
+
-
/**
* \brief Efface un charge sociale
- * \param user Utilisateur qui crée le paiement
+ * \param user Utilisateur qui cr�e le paiement
* \return int <0 si erreur, >0 si ok
*/
function delete($user)
@@ -166,7 +167,7 @@ class ChargeSociales extends CommonObject
return -1;
}
}
-
+
/**
* \brief Met a jour une charge sociale
@@ -176,13 +177,13 @@ class ChargeSociales extends CommonObject
function update($user)
{
$this->db->begin();
-
+
$sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales";
$sql.= " SET libelle='".addslashes($this->lib)."',";
$sql.= " date_ech='".$this->db->idate($this->date_ech)."',";
- $sql.= " periode='".$this->periode."'";
+ $sql.= " periode='".$this->db->idate($this->periode)."'";
$sql.= " WHERE rowid=".$this->id;
-
+
dol_syslog("ChargesSociales::update sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
@@ -196,9 +197,9 @@ class ChargeSociales extends CommonObject
$this->db->rollback();
return -1;
}
- }
-
-
+ }
+
+
function solde($year = 0)
{
$sql = "SELECT sum(f.amount) as amount";
@@ -227,7 +228,7 @@ class ChargeSociales extends CommonObject
}
/**
- * \brief Tag la charge comme payée complètement
+ * \brief Tag la charge comme pay�e compl�tement
* \param rowid id de la ligne a modifier
*/
function set_payed($rowid)
@@ -237,8 +238,8 @@ class ChargeSociales extends CommonObject
}
/**
- * \brief Retourne le libellé du statut d'une charge (impayé, payée)
- * \param mode 0=libellé long, 1=libellé court, 2=Picto + Libellé court, 3=Picto, 4=Picto + Libellé long
+ * \brief Retourne le libell� du statut d'une charge (impay�, pay�e)
+ * \param mode 0=libell� long, 1=libell� court, 2=Picto + Libell� court, 3=Picto, 4=Picto + Libell� long
* \return string Libelle
*/
function getLibStatut($mode=0)
@@ -247,10 +248,10 @@ class ChargeSociales extends CommonObject
}
/**
- * \brief Renvoi le libellé d'un statut donné
+ * \brief Renvoi le libell� d'un statut donn�
* \param statut Id statut
- * \param mode 0=libellé long, 1=libellé court, 2=Picto + Libellé court, 3=Picto, 4=Picto + Libellé long, 5=Libellé court + Picto
- * \return string Libellé du statut
+ * \param mode 0=libell� long, 1=libell� court, 2=Picto + Libell� court, 3=Picto, 4=Picto + Libell� long, 5=Libell� court + Picto
+ * \return string Libell� du statut
*/
function LibStatut($statut,$mode=0)
{
@@ -301,9 +302,9 @@ class ChargeSociales extends CommonObject
function getNomUrl($withpicto=0,$maxlen=0)
{
global $langs;
-
+
$result='';
-
+
$lien = '';
$lienfin='';
@@ -348,7 +349,7 @@ class ChargeSociales extends CommonObject
class PaiementCharge
{
var $db;
-
+
var $id;
var $chid;
var $paiementtype;
@@ -357,7 +358,7 @@ class PaiementCharge
var $num_paiement;
var $note;
-
+
function PaiementCharge($DB)
{
$this->db = $DB;
@@ -366,8 +367,8 @@ class PaiementCharge
/**
* \brief Creation d'un paiement de charge sociale dans la base
- * \param user Utilisateur qui crée le paiement
- * \return int <0 si KO, id du paiement crée si OK
+ * \param user Utilisateur qui cr�e le paiement
+ * \return int <0 si KO, id du paiement cr�e si OK
*/
function create($user)
{
@@ -380,9 +381,9 @@ class PaiementCharge
$this->error='ErrorBadValueForParameters';
return -1;
}
-
+
$this->db->begin();
-
+
$total=0;
foreach ($this->amounts as $key => $value)
{
@@ -393,7 +394,7 @@ class PaiementCharge
if ($total > 0)
{
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount,";
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount,";
$sql.= " fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
$sql.= " VALUES ($this->chid, ".$this->db->idate(mktime()).", ";
$sql.= $this->db->idate($this->datepaye).", ";
@@ -429,18 +430,18 @@ class PaiementCharge
}
/**
- * \brief Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank générée
+ * \brief Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank g�n�r�e
* \param id_bank Id de la banque
* \return int >0 si OK, <=0 si KO
*/
function update_fk_bank($id_bank)
{
$sql = "UPDATE llx_paiementcharge set fk_bank = ".$id_bank." where rowid = ".$this->id;
-
+
dol_syslog("PaiementCharge::update_fk_bank sql=".$sql);
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result)
+ {
return 1;
}
else
diff --git a/htdocs/compta/charges/index.php b/htdocs/compta/charges/index.php
index eac313ea74c..9e0289a4fa5 100644
--- a/htdocs/compta/charges/index.php
+++ b/htdocs/compta/charges/index.php
@@ -27,6 +27,7 @@
require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php");
+require_once(DOL_DOCUMENT_ROOT."/chargesociales.class.php");
$langs->load("compta");
@@ -48,6 +49,7 @@ llxHeader('',$langs->trans("TaxAndDividendsArea"));
print_fiche_titre($langs->trans("TaxAndDividendsArea"),($year?"".img_previous()." ".$langs->trans("Year")." $year ".img_next()."":""));
+print $langs->trans("DescTaxAndDividendsArea").'
';
print "
";
@@ -56,29 +58,31 @@ print "
";
print_titre($langs->trans("SocialContributions"));
print '
';
print "";
+print '| '.$langs->trans("PeriodEndDate").' | ';
+print ''.$langs->trans("Label").' | ';
print "".$langs->trans("Type")." | ";
-print "".$langs->trans("Nb")." | ";
print "".$langs->trans("Amount")." | ";
+print "".$langs->trans("NbOfPayments")." | ";
print "".$langs->trans("AlreadyPayed")." | ";
print "
\n";
-$sql = "SELECT c.id, c.libelle as lib, s.fk_type as type,";
-$sql.=" count(s.rowid) as nb, sum(s.amount) as total, sum(pc.amount) as totalpaye";
-$sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
-$sql.= ", ".MAIN_DB_PREFIX."chargesociales as s";
+$sql = "SELECT c.id, c.libelle as lib, s.rowid, s.libelle, s.fk_type as type, s.periode, s.date_ech,";
+$sql.= " count(s.rowid) as nb, sum(s.amount) as total, sum(pc.amount) as totalpaye";
+$sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
+$sql.= " ".MAIN_DB_PREFIX."chargesociales as s";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = s.rowid";
$sql.= " WHERE s.fk_type = c.id";
$sql.= " AND s.entity = ".$conf->entity;
if ($year > 0)
{
$sql .= " AND (";
- // Si period renseigné on l'utilise comme critere de date, sinon on prend date échéance,
- // ceci afin d'etre compatible avec les cas ou la période n'etait pas obligatoire
+ // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
+ // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
$sql .= " (s.periode is not null and date_format(s.periode, '%Y') = $year) ";
$sql .= "or (s.periode is null and date_format(s.date_ech, '%Y') = $year)";
$sql .= ")";
}
-$sql.= " GROUP BY c.id, c.libelle, s.fk_type";
+$sql.= " GROUP BY c.id, c.libelle, s.rowid, s.fk_type, s.periode, s.date_ech";
$sql.= " ORDER BY c.libelle ASC";
dol_syslog("compta/charges/index.php: select payment sql=".$sql);
@@ -88,6 +92,7 @@ if ($resql)
$num = $db->num_rows($resql);
$i = 0;
$total = 0;
+ $totalnb = 0;
$totalpaye = 0;
$var=true;
@@ -96,17 +101,28 @@ if ($resql)
$obj = $db->fetch_object($resql);
$var = !$var;
print "";
+ $date=$obj->periode;
+ if (empty($date)) $date=$obj->date_ech;
+ print '| '.dol_print_date($date,'day').' | ';
+ print '';
+ $socialcontrib=new ChargeSociales($db);
+ $socialcontrib->id=$obj->rowid;
+ $socialcontrib->lib=$obj->libelle;
+ print $socialcontrib->getNomUrl(1,'16');
+ print ' | ';
print ''.$obj->lib.' | ';
- print ''.$obj->nb.' | ';
print ''.price($obj->total).' | ';
+ print ''.$obj->nb.' | ';
print ''.price($obj->totalpaye).' | ';
print '
';
$total = $total + $obj->total;
+ $totalnb = $totalnb + $obj->nb;
$totalpaye = $totalpaye + $obj->totalpaye;
$i++;
}
- print '| '.$langs->trans("Total").' | ';
+ print '
| '.$langs->trans("Total").' | ';
print ''.price($total)." | ";
+ print ''.$totalnb.' | ';
print ''.price($totalpaye)." | ";
print "
";
}
@@ -132,8 +148,8 @@ if (empty($_GET["mode"]) || $_GET["mode"] != 'sconly')
$sql.= " WHERE f.entity = ".$conf->entity;
if ($year > 0)
{
- // Si period renseigné on l'utilise comme critere de date, sinon on prend date échéance,
- // ceci afin d'etre compatible avec les cas ou la période n'etait pas obligatoire
+ // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
+ // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
$sql.= " AND date_format(f.datev, '%Y') = ".$year;
}
$sql.= " ORDER BY dm DESC";
@@ -146,9 +162,11 @@ if (empty($_GET["mode"]) || $_GET["mode"] != 'sconly')
$total = 0 ;
print '';
print '';
- print '| '.$langs->trans("Date").' | ';
+ print ''.$langs->trans("PeriodEndDate").' | ';
print "".$langs->trans("Label")." | ";
print ''.$langs->trans("Amount")." | ";
+ print ''.$langs->trans("DatePayment")." | ";
+ print "".$langs->trans("AlreadyPayed")." | ";
print "
\n";
$var=1;
while ($i < $num)
@@ -156,17 +174,22 @@ if (empty($_GET["mode"]) || $_GET["mode"] != 'sconly')
$obj = $db->fetch_object($result);
$var=!$var;
print "";
- print '| '.dol_print_date($obj->dm,'day')." | \n";
+ print ''.dol_print_date($obj->dm,'day').' ? | '."\n";
print "".$obj->label." | \n";
$total = $total + $obj->amount;
+ print "".price($obj->amount)." | ";
+ print ''.dol_print_date($obj->dm,'day')." | \n";
print "".price($obj->amount)." | ";
print "
\n";
$i++;
}
print '| '.$langs->trans("Total").' | ';
- print ''.price($total)." |
";
+ print ''.price($total)." | ";
+ print ' | ';
+ print ''.price($total)." | ";
+ print "";
print "
";
$db->free($result);
diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php
index c286fb36b46..2f1784e83af 100644
--- a/htdocs/compta/sociales/charges.php
+++ b/htdocs/compta/sociales/charges.php
@@ -50,42 +50,28 @@ $result = restrictedArea($user, 'tax', '', '', 'charges');
/*
* Classer paye
*/
-if ($_POST["action"] == 'confirm_payed')
+if ($_REQUEST["action"] == 'confirm_payed' && $_REQUEST["confirm"] == 'yes')
{
- if ($_POST["confirm"] == 'yes')
- {
- $chargesociales = new ChargeSociales($db);
- $result = $chargesociales->set_payed($chid);
- }
- else
- {
- $_GET["action"]='';
- }
+ $chargesociales = new ChargeSociales($db);
+ $result = $chargesociales->set_payed($chid);
}
/*
* Suppression d'une charge sociale
*/
-if ($_POST["action"] == 'confirm_delete')
+if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes')
{
- if ($_POST["confirm"] == 'yes')
+ $chargesociales=new ChargeSociales($db);
+ $chargesociales->id=$_GET["id"];
+ $result=$chargesociales->delete($user);
+ if ($result > 0)
{
- $chargesociales=new ChargeSociales($db);
- $chargesociales->id=$_GET["id"];
- $result=$chargesociales->delete($user);
- if ($result > 0)
- {
- Header("Location: index.php");
- exit;
- }
- else
- {
- $mesg=''.$chargesociales->error.'
';
- }
+ Header("Location: index.php");
+ exit;
}
else
{
- $_GET['action']='';
+ $mesg=''.$chargesociales->error.'
';
}
}
@@ -97,12 +83,13 @@ if ($_POST["action"] == 'confirm_delete')
if ($_POST["action"] == 'add' && $user->rights->tax->charges->creer)
{
$dateech=@dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]);
+ $dateperiod=@dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]);
if (! $dateech)
{
$mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'
';
$_GET["action"] = 'create';
}
- elseif (! $_POST["period"])
+ elseif (! $dateperiod)
{
$mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'
';
$_GET["action"] = 'create';
@@ -119,7 +106,7 @@ if ($_POST["action"] == 'add' && $user->rights->tax->charges->creer)
$chargesociales->type=$_POST["actioncode"];
$chargesociales->lib=$_POST["label"];
$chargesociales->date_ech=$dateech;
- $chargesociales->periode=$_POST["period"];
+ $chargesociales->periode=$dateperiod;
$chargesociales->amount=$_POST["amount"];
$chid=$chargesociales->create($user);
@@ -138,12 +125,13 @@ if ($_POST["action"] == 'add' && $user->rights->tax->charges->creer)
if ($_GET["action"] == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->creer)
{
$dateech=@dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]);
+ $dateperiod=@dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]);
if (! $dateech)
{
$mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'
';
$_GET["action"] = 'edit';
}
- elseif (! $_POST["period"])
+ elseif (! $dateperiod)
{
$mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")).'
';
$_GET["action"] = 'edit';
@@ -155,7 +143,7 @@ if ($_GET["action"] == 'update' && ! $_POST["cancel"] && $user->rights->tax->cha
$chargesociales->lib=$_POST["label"];
$chargesociales->date_ech=$dateech;
- $chargesociales->periode=$_POST["period"];
+ $chargesociales->periode=$dateperiod;
$result=$chargesociales->update($user);
if ($result > 0)
@@ -169,6 +157,12 @@ if ($_GET["action"] == 'update' && ! $_POST["cancel"] && $user->rights->tax->cha
}
}
+
+
+/*
+ * View
+ */
+
llxHeader();
$html = new Form($db);
@@ -186,7 +180,7 @@ if ($_GET["action"] == 'create')
$var=false;
- print '