Fix: Add social contributions in budget

This commit is contained in:
Laurent Destailleur 2008-07-31 16:07:40 +00:00
parent 82a3bd3913
commit 5d95afa149
11 changed files with 751 additions and 682 deletions

View File

@ -28,6 +28,7 @@ For users:
- Can attach several files to email when sending an invoice, order or - Can attach several files to email when sending an invoice, order or
proposal by email. proposal by email.
- More informations reported in system information pages. - More informations reported in system information pages.
- Add a budget report.
- New translation: Added spanish language. - New translation: Added spanish language.
- Added a security audit report. - Added a security audit report.
- Other minor changes (features, look, fixes) - Other minor changes (features, look, fixes)

View File

@ -15,15 +15,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/chargesociales.class.php \file htdocs/chargesociales.class.php
\ingroup facture \ingroup facture
\brief Fichier de la classe des charges sociales \brief Fichier de la classe des charges sociales
\version $Revision$ \version $Id$
*/ */
@ -304,11 +302,37 @@ class ChargeSociales
$lien = '<a href="'.DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$this->id.'">'; $lien = '<a href="'.DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$this->id.'">';
$lienfin='</a>'; $lienfin='</a>';
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowBill"),'bill').$lienfin.' '); if ($withpicto) $result.=($lien.img_object($langs->trans("ShowSocialContribution"),'bill').$lienfin.' ');
$result.=$lien.($maxlen?dolibarr_trunc($this->lib,$maxlen):$this->lib).$lienfin; $result.=$lien.($maxlen?dolibarr_trunc($this->lib,$maxlen):$this->lib).$lienfin;
return $result; return $result;
} }
/**
* \brief Return amount aof payments already done
* \return int Amount of payment already done, <0 if KO
*/
function getSommePaiement()
{
$table='paiementcharge';
$field='amount';
$sql = 'SELECT sum(amount) as amount';
$sql.= ' FROM '.MAIN_DB_PREFIX.$table;
$sql.= ' WHERE '.$field.' = '.$this->id;
dolibarr_syslog("ChargeSociales::getSommePaiement sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$obj = $this->db->fetch_object($resql);
$this->db->free($resql);
return $obj->amount;
}
else
{
return -1;
}
}
} }

View File

@ -20,18 +20,18 @@
*/ */
/** /**
\file htdocs/compta/bank/account.class.php * \file htdocs/compta/bank/account.class.php
\ingroup banque * \ingroup banque
\brief Fichier de la classe des comptes bancaires * \brief Fichier de la classe des comptes bancaires
\version $Id$ * \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php");
/** /**
\class Account * \class Account
\brief Classe permettant la gestion des comptes bancaires * \brief Class to manage bank accounts
*/ */
class Account extends CommonObject class Account extends CommonObject
{ {
@ -610,13 +610,16 @@ class Account extends CommonObject
return $this->error; return $this->error;
} }
/* /**
* * \brief Return current sold
* \param option 1=Exclude future operation date (this is to exclude input made in advance and have real account sold)
* \return int Current sold (value date <= today)
*/ */
function solde() function solde($option=0)
{ {
$sql = "SELECT sum(amount) as amount FROM ".MAIN_DB_PREFIX."bank"; $sql = "SELECT sum(amount) as amount FROM ".MAIN_DB_PREFIX."bank";
$sql.= " WHERE fk_account=".$this->id." AND dateo <= ".$this->db->idate(time()); $sql.= " WHERE fk_account=".$this->id;
if ($option == 1) $sql.= " AND dateo <= ".$this->db->idate(time());
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)

View File

@ -94,7 +94,7 @@ foreach ($accounts as $key=>$type)
$acc->fetch($key); $acc->fetch($key);
$var = !$var; $var = !$var;
$solde = $acc->solde(); $solde = $acc->solde(1);
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td width="30%">'.$acc->getNomUrl(1).'</td>'; print '<td width="30%">'.$acc->getNomUrl(1).'</td>';
@ -148,7 +148,7 @@ foreach ($accounts as $key=>$type)
$acc->fetch($key); $acc->fetch($key);
$var = !$var; $var = !$var;
$solde = $acc->solde(); $solde = $acc->solde(1);
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
print '<td width="30%">'.$acc->getNomUrl(1).'</td>'; print '<td width="30%">'.$acc->getNomUrl(1).'</td>';
@ -200,7 +200,7 @@ foreach ($accounts as $key=>$type)
$acc->fetch($key); $acc->fetch($key);
$var = !$var; $var = !$var;
$solde = $acc->solde(); $solde = $acc->solde(1);
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
print '<td width="30%">'.$acc->getNomUrl(1).'</td>'; print '<td width="30%">'.$acc->getNomUrl(1).'</td>';

View File

@ -27,9 +27,10 @@
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/bank.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/bank.lib.php");
require_once(DOL_DOCUMENT_ROOT."/societe.class.php");
require_once(DOL_DOCUMENT_ROOT.'/facture.class.php'); require_once(DOL_DOCUMENT_ROOT.'/facture.class.php');
require_once(DOL_DOCUMENT_ROOT.'/fourn/fournisseur.facture.class.php'); require_once(DOL_DOCUMENT_ROOT.'/fourn/fournisseur.facture.class.php');
require_once(DOL_DOCUMENT_ROOT."/societe.class.php"); require_once(DOL_DOCUMENT_ROOT.'/chargesociales.class.php');
$langs->load("banks"); $langs->load("banks");
$langs->load("bills"); $langs->load("bills");
@ -37,7 +38,6 @@ $langs->load("bills");
if (!$user->admin && !$user->rights->banque) if (!$user->admin && !$user->rights->banque)
accessforbidden(); accessforbidden();
$account=isset($_GET["account"])?$_GET["account"]:$_POST["account"];
$vline=isset($_GET["vline"])?$_GET["vline"]:$_POST["vline"]; $vline=isset($_GET["vline"])?$_GET["vline"]:$_POST["vline"];
$page=isset($_GET["page"])?$_GET["page"]:0; $page=isset($_GET["page"])?$_GET["page"]:0;
@ -46,7 +46,7 @@ $mesg='';
/* /*
* Affichage page * View
*/ */
llxHeader(); llxHeader();
@ -54,6 +54,7 @@ llxHeader();
$societestatic = new Societe($db); $societestatic = new Societe($db);
$facturestatic=new Facture($db); $facturestatic=new Facture($db);
$facturefournstatic=new FactureFournisseur($db); $facturefournstatic=new FactureFournisseur($db);
$socialcontribstatic=new ChargeSociales($db);
$html = new Form($db); $html = new Form($db);
@ -108,70 +109,77 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
if ($mesg) print '<div class="error">'.$mesg.'</div>'; if ($mesg) print '<div class="error">'.$mesg.'</div>';
/* $solde = $acct->solde(0);
* Calcul du solde du compte bancaire
*/
$sql = "SELECT sum( amount ) AS solde";
$sql.= " FROM ".MAIN_DB_PREFIX."bank";
$sql.= " WHERE fk_account =".$account;
$result = $db->query($sql);
if ($result)
{
$obj = $db->fetch_object($result);
if ($obj) $solde = $obj->solde;
}
/* /*
* Affiche tableau des echeances à venir * Affiche tableau des echeances à venir
*
*/ */
print '<table class="notopnoleftnoright" width="100% border="1">'; print '<table class="notopnoleftnoright" width="100% border="1">';
// Ligne de titre tableau des ecritures // Ligne de titre tableau des ecritures
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Invoices").'</td>'; print '<td>'.$langs->trans("Invoices").'</td>';
print '<td>'.$langs->trans("ThirdParty").'</td>'; print '<td>'.$langs->trans("ThirdParty").'</td>';
print '<td>'.$langs->trans("DateEcheance").'</td>'; print '<td align="center">'.$langs->trans("DateEcheance").'</td>';
print '<td align="right">'.$langs->trans("Debit").'</td>'; print '<td align="right">'.$langs->trans("Debit").'</td>';
print '<td align="right">'.$langs->trans("Credit").'</td>'; print '<td align="right">'.$langs->trans("Credit").'</td>';
print '<td align="right" width="80">'.$langs->trans("BankBalance").'</td>'; print '<td align="right" width="80">'.$langs->trans("BankBalance").'</td>';
print '</tr>'; print '</tr>';
// Solde initial $var=true;
print '<tr class="liste_total"><td align="left" colspan="5">'.$langs->trans("CurrentBalance").'</td>';
// Solde actuel
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td align="left" colspan="5">'.$langs->trans("CurrentBalance").'</td>';
print '<td align="right" nowrap>&nbsp;</td>';
print '</tr>';
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td align="left" colspan="5">&nbsp;</td>';
print '<td align="right" nowrap>'.price($solde).'</td>'; print '<td align="right" nowrap>'.price($solde).'</td>';
print '</tr>'; print '</tr>';
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td align="left" colspan="5">'.$langs->trans("RemainderToPay").'</td>';
print '<td align="right" nowrap>&nbsp;</td>';
print '</tr>';
// Recuperation des factures clients et fournisseurs impayes // Remainder to pay in future
$sql = "SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.type, ".$db->pdate("f.date_lim_reglement")." as dlr,";
// Customer invoices
$sql = "SELECT 'invoice' as family, f.rowid as objid, f.facnumber as ref, f.total_ttc, f.type, ".$db->pdate("f.date_lim_reglement")." as dlr,";
$sql.= " s.rowid as socid, s.nom, s.fournisseur"; $sql.= " s.rowid as socid, s.nom, s.fournisseur";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
$sql.= " WHERE f.paye = 0 AND fk_statut = 1"; $sql.= " WHERE f.paye = 0 AND fk_statut = 1"; // Not payed
$sql.= " ORDER BY dlr ASC"; $sql.= " ORDER BY dlr ASC";
//$sql.= " UNION DISTINCT";
$sql2= " SELECT ff.rowid as facid, ff.facnumber, (-1*ff.total_ttc) as total_ttc, ff.type, ".$db->pdate("ff.date_lim_reglement")." as dlr,"; // Supplier invoices
$sql2= " SELECT 'supplier_invoice' as family, ff.rowid as objid, ff.facnumber as ref, (-1*ff.total_ttc) as total_ttc, ff.type, ".$db->pdate("ff.date_lim_reglement")." as dlr,";
$sql2.= " s.rowid as socid, s.nom, s.fournisseur"; $sql2.= " s.rowid as socid, s.nom, s.fournisseur";
$sql2.= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff"; $sql2.= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
$sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ff.fk_soc = s.rowid"; $sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ff.fk_soc = s.rowid";
$sql2.= " WHERE ff.paye = 0 AND fk_statut = 1"; $sql2.= " WHERE ff.paye = 0 AND fk_statut = 1"; // Not payed
$sql2.= " ORDER BY dlr ASC"; $sql2.= " ORDER BY dlr ASC";
// Social contributions
$sql3= " SELECT 'social_contribution' as family, cs.rowid as objid, cs.libelle as ref, (-1*cs.amount) as total_ttc, ccs.libelle as type, ".$db->pdate("cs.date_ech")." as dlr";
$sql3.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs";
$sql3.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as ccs ON cs.fk_type = ccs.id";
$sql3.= " WHERE cs.paye = 0"; // Not payed
$sql3.= " ORDER BY dlr ASC";
$result = $db->query($sql); $error=0;
$result2=false;
if ($result)
{
$result2=$db->query($sql2);
}
if ($result2)
{
$tab_sqlobj=array(); $tab_sqlobj=array();
// List customer invoices
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result); $num = $db->num_rows($result);
for ($i = 0;$i < $num;$i++) for ($i = 0;$i < $num;$i++)
{ {
@ -180,7 +188,13 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
$tab_sqlobjOrder[]= $sqlobj->dlr; $tab_sqlobjOrder[]= $sqlobj->dlr;
} }
$db->free($result); $db->free($result);
}
else $error++;
// List supplier invoices
$result2=$db->query($sql2);
if ($result2)
{
$num = $db->num_rows($result2); $num = $db->num_rows($result2);
for ($i = 0;$i < $num;$i++) for ($i = 0;$i < $num;$i++)
{ {
@ -189,7 +203,29 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
$tab_sqlobjOrder[]= $sqlobj->dlr; $tab_sqlobjOrder[]= $sqlobj->dlr;
} }
$db->free($result2); $db->free($result2);
}
else $error++;
// List social contributions
$result3=$db->query($sql3);
if ($result3)
{
$num = $db->num_rows($result3);
for ($i = 0;$i < $num;$i++)
{
$sqlobj = $db->fetch_object($result3);
$tab_sqlobj[] = $sqlobj;
$tab_sqlobjOrder[]= $sqlobj->dlr;
}
$db->free($result3);
}
else $error++;
// Sort array
if (! $error)
{
array_multisort ($tab_sqlobjOrder,$tab_sqlobj); array_multisort ($tab_sqlobjOrder,$tab_sqlobj);
//Apply distinct filter //Apply distinct filter
@ -209,49 +245,53 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
while ($i < $num) while ($i < $num)
{ {
$paiement = ''; $paiement = '';
$ref = '';
$refcomp = '';
$var=!$var; $var=!$var;
//$obj = $db->fetch_object($result); //$obj = $db->fetch_object($result);
$obj = array_shift($tab_sqlobj); $obj = array_shift($tab_sqlobj);
if ($obj->family == 'supplier_invoice')
{
// \TODO This code is to avoid to count suppliers credit note (ff.type = 2)
// Ajouter gestion des avoirs fournisseurs, champ
if (($obj->total_ttc < 0 && $obj->type != 2)
|| ($obj->total_ttc > 0 && $obj->type == 2))
{
$facturefournstatic->ref=$obj->ref;
$facturefournstatic->id=$obj->objid;
$facturefournstatic->type=$obj->type;
$ref = $facturefournstatic->getNomUrl(1,'');
$societestatic->id = $obj->socid; $societestatic->id = $obj->socid;
$societestatic->nom = $obj->nom; $societestatic->nom = $obj->nom;
$refcomp=$societestatic->getNomUrl(0,'',24);
// Todo: Ajouter gestion des avoirs fournisseurs, champ ff.type = 2 $paiement = -1*$facturefournstatic->getSommePaiement(); // Payment already done
if ($obj->fournisseur == 1 && ($obj->total_ttc < 0 && $obj->type != 2) || ($obj->total_ttc > 0 && $obj->type == 2))
{
$facturefournstatic->ref=$obj->facnumber;
$facturefournstatic->id=$obj->facid;
$facturefournstatic->type=$obj->type;
$facture = $facturefournstatic->getNomUrl(1,'');
// On recherche les paiements deja effectue pour les deduires
$sqlp = "SELECT sum(-1*amount) as paiement";
$sqlp.= " FROM ".MAIN_DB_PREFIX.'paiementfourn_facturefourn';
$sqlp.= " WHERE fk_facturefourn = ".$obj->facid;
$resql = $db->query($sqlp);
if ($resql)
{
$objp = $db->fetch_object($resql);
if ($objp) $paiement = $objp->paiement;
} }
} }
else if ($obj->family == 'invoice')
{ {
$facturestatic->ref=$obj->facnumber; $facturestatic->ref=$obj->ref;
$facturestatic->id=$obj->facid; $facturestatic->id=$obj->objid;
$facturestatic->type=$obj->type; $facturestatic->type=$obj->type;
$facture = $facturestatic->getNomUrl(1,''); $ref = $facturestatic->getNomUrl(1,'');
// On recherche les paiements deja effectue pour les deduires $societestatic->id = $obj->socid;
$sqlp = "SELECT sum(amount) as paiement"; $societestatic->nom = $obj->nom;
$sqlp.= " FROM ".MAIN_DB_PREFIX.'paiement_facture'; $refcomp=$societestatic->getNomUrl(0,'',24);
$sqlp.= " WHERE fk_facture = ".$obj->facid;
$resql = $db->query($sqlp); $paiement = $facturestatic->getSommePaiement(); // Payment already done
if ($resql)
{
$objp = $db->fetch_object($resql);
if ($objp) $paiement = $objp->paiement;
} }
if ($obj->family == 'social_contribution')
{
$socialcontribstatic->ref=$obj->ref;
$socialcontribstatic->id=$obj->objid;
$socialcontribstatic->lib=$obj->type;
$ref = $socialcontribstatic->getNomUrl(1,24);
$paiement = $socialcontribstatic->getSommePaiement(); // Payment already done
} }
$total_ttc = $obj->total_ttc; $total_ttc = $obj->total_ttc;
@ -259,17 +299,15 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
$solde += $total_ttc; $solde += $total_ttc;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print "<td>".$facture."</td>"; print "<td>".$ref."</td>";
print "<td>".$societestatic->getNomUrl(0,'',16)."</td>"; print "<td>".$refcomp."</td>";
print "<td>".dolibarr_print_date($obj->dlr,"day")."</td>"; print '<td align="center">'.dolibarr_print_date($obj->dlr,"day")."</td>";
if ($obj->total_ttc < 0) { print "<td align=\"right\">".price($total_ttc)."</td><td>&nbsp;</td>"; }; if ($obj->total_ttc < 0) { print "<td align=\"right\">".price($total_ttc)."</td><td>&nbsp;</td>"; };
if ($obj->total_ttc >= 0) { print "<td>&nbsp;</td><td align=\"right\">".price($total_ttc)."</td>"; }; if ($obj->total_ttc >= 0) { print "<td>&nbsp;</td><td align=\"right\">".price($total_ttc)."</td>"; };
print "<td align=\"right\">".price($solde)."</td>"; print "<td align=\"right\">".price($solde)."</td>";
print "</tr>"; print "</tr>";
$i++; $i++;
} }
//$db->free($result);
} }
else else
{ {

View File

@ -35,10 +35,9 @@ require_once(DOL_DOCUMENT_ROOT ."/product.class.php");
require_once(DOL_DOCUMENT_ROOT ."/client.class.php"); require_once(DOL_DOCUMENT_ROOT ."/client.class.php");
/** /**
\class Facture * \class Facture
\brief Classe permettant la gestion des factures clients * \brief Classe permettant la gestion des factures clients
*/ */
class Facture extends CommonObject class Facture extends CommonObject
{ {
var $db; var $db;
@ -1639,8 +1638,8 @@ class Facture extends CommonObject
/** /**
* \brief Renvoie la sommes des paiements deja effectués * \brief Return amount aof payments already done
* \return Montant deja versé, <0 si ko * \return int Amount of payment already done, <0 if KO
*/ */
function getSommePaiement() function getSommePaiement()
{ {
@ -1661,6 +1660,7 @@ class Facture extends CommonObject
if ($resql) if ($resql)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->db->free($resql);
return $obj->amount; return $obj->amount;
} }
else else

View File

@ -92,7 +92,7 @@ class box_comptes extends ModeleBoxes {
$objp = $db->fetch_object($result); $objp = $db->fetch_object($result);
$account_static->id = $objp->rowid; $account_static->id = $objp->rowid;
$solde=$account_static->solde(); $solde=$account_static->solde(0);
$solde_total += $solde; $solde_total += $solde;

View File

@ -152,6 +152,7 @@ ConfirmCustomerPayment=Do you confirm this paiement input for <b>%s</b> %s ?
ValidateBill=Validate invoice ValidateBill=Validate invoice
NumberOfBills=Nb of invoices NumberOfBills=Nb of invoices
NumberOfBillsByMonth=Nb of invoices by month NumberOfBillsByMonth=Nb of invoices by month
ShowSocialContribution=Show social contribution
ShowBill=Show invoice ShowBill=Show invoice
ShowInvoice=Show invoice ShowInvoice=Show invoice
ShowInvoiceReplace=Show replacing invoice ShowInvoiceReplace=Show replacing invoice

View File

@ -122,6 +122,7 @@ ConfirmClassifyPayedPartiallyAbandon=Ce choix sera celui dans le cas d'un mauvai
ValidateBill=Valider facture ValidateBill=Valider facture
NumberOfBills=Nb de factures NumberOfBills=Nb de factures
NumberOfBillsByMonth=Nb de factures par mois NumberOfBillsByMonth=Nb de factures par mois
ShowSocialContribution=Afficher charge sociale
ShowBill=Afficher facture ShowBill=Afficher facture
ShowInvoice=Afficher la facture ShowInvoice=Afficher la facture
ShowInvoiceReplace=Afficher la facture de remplacement ShowInvoiceReplace=Afficher la facture de remplacement

View File

@ -152,6 +152,7 @@ ConfirmCustomerPayment=Confirmez-vous la saisie de ce r
ValidateBill=Valider facture ValidateBill=Valider facture
NumberOfBills=Nb de factures NumberOfBills=Nb de factures
NumberOfBillsByMonth=Nb de factures par mois NumberOfBillsByMonth=Nb de factures par mois
ShowSocialContribution=Afficher charge sociale
ShowBill=Afficher facture ShowBill=Afficher facture
ShowInvoice=Afficher facture ShowInvoice=Afficher facture
ShowInvoiceReplace=Afficher facture de remplacement ShowInvoiceReplace=Afficher facture de remplacement