mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-04 08:02:22 +01:00
Fix: Add social contributions in budget
This commit is contained in:
@@ -28,6 +28,7 @@ For users:
|
||||
- Can attach several files to email when sending an invoice, order or
|
||||
proposal by email.
|
||||
- More informations reported in system information pages.
|
||||
- Add a budget report.
|
||||
- New translation: Added spanish language.
|
||||
- Added a security audit report.
|
||||
- Other minor changes (features, look, fixes)
|
||||
|
||||
@@ -15,15 +15,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/chargesociales.class.php
|
||||
\ingroup facture
|
||||
\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.'">';
|
||||
$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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,18 +20,18 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/compta/bank/account.class.php
|
||||
\ingroup banque
|
||||
\brief Fichier de la classe des comptes bancaires
|
||||
\version $Id$
|
||||
* \file htdocs/compta/bank/account.class.php
|
||||
* \ingroup banque
|
||||
* \brief Fichier de la classe des comptes bancaires
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php");
|
||||
|
||||
|
||||
/**
|
||||
\class Account
|
||||
\brief Classe permettant la gestion des comptes bancaires
|
||||
* \class Account
|
||||
* \brief Class to manage bank accounts
|
||||
*/
|
||||
class Account extends CommonObject
|
||||
{
|
||||
@@ -610,13 +610,16 @@ class Account extends CommonObject
|
||||
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.= " 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);
|
||||
if ($resql)
|
||||
|
||||
@@ -94,7 +94,7 @@ foreach ($accounts as $key=>$type)
|
||||
$acc->fetch($key);
|
||||
|
||||
$var = !$var;
|
||||
$solde = $acc->solde();
|
||||
$solde = $acc->solde(1);
|
||||
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td width="30%">'.$acc->getNomUrl(1).'</td>';
|
||||
@@ -148,7 +148,7 @@ foreach ($accounts as $key=>$type)
|
||||
$acc->fetch($key);
|
||||
|
||||
$var = !$var;
|
||||
$solde = $acc->solde();
|
||||
$solde = $acc->solde(1);
|
||||
|
||||
print "<tr ".$bc[$var].">";
|
||||
print '<td width="30%">'.$acc->getNomUrl(1).'</td>';
|
||||
@@ -200,7 +200,7 @@ foreach ($accounts as $key=>$type)
|
||||
$acc->fetch($key);
|
||||
|
||||
$var = !$var;
|
||||
$solde = $acc->solde();
|
||||
$solde = $acc->solde(1);
|
||||
|
||||
print "<tr ".$bc[$var].">";
|
||||
print '<td width="30%">'.$acc->getNomUrl(1).'</td>';
|
||||
|
||||
@@ -27,9 +27,10 @@
|
||||
|
||||
require("./pre.inc.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.'/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("bills");
|
||||
@@ -37,7 +38,6 @@ $langs->load("bills");
|
||||
if (!$user->admin && !$user->rights->banque)
|
||||
accessforbidden();
|
||||
|
||||
$account=isset($_GET["account"])?$_GET["account"]:$_POST["account"];
|
||||
$vline=isset($_GET["vline"])?$_GET["vline"]:$_POST["vline"];
|
||||
$page=isset($_GET["page"])?$_GET["page"]:0;
|
||||
|
||||
@@ -46,7 +46,7 @@ $mesg='';
|
||||
|
||||
|
||||
/*
|
||||
* Affichage page
|
||||
* View
|
||||
*/
|
||||
|
||||
llxHeader();
|
||||
@@ -54,6 +54,7 @@ llxHeader();
|
||||
$societestatic = new Societe($db);
|
||||
$facturestatic=new Facture($db);
|
||||
$facturefournstatic=new FactureFournisseur($db);
|
||||
$socialcontribstatic=new ChargeSociales($db);
|
||||
|
||||
$html = new Form($db);
|
||||
|
||||
@@ -108,70 +109,77 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
|
||||
if ($mesg) print '<div class="error">'.$mesg.'</div>';
|
||||
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
$solde = $acct->solde(0);
|
||||
|
||||
/*
|
||||
* Affiche tableau des echeances <20> venir
|
||||
*
|
||||
*/
|
||||
|
||||
print '<table class="notopnoleftnoright" width="100% border="1">';
|
||||
|
||||
// Ligne de titre tableau des ecritures
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Invoices").'</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("Credit").'</td>';
|
||||
print '<td align="right" width="80">'.$langs->trans("BankBalance").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Solde initial
|
||||
print '<tr class="liste_total"><td align="left" colspan="5">'.$langs->trans("CurrentBalance").'</td>';
|
||||
$var=true;
|
||||
|
||||
// Solde actuel
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td align="left" colspan="5">'.$langs->trans("CurrentBalance").'</td>';
|
||||
print '<td align="right" nowrap> </td>';
|
||||
print '</tr>';
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td align="left" colspan="5"> </td>';
|
||||
print '<td align="right" nowrap>'.price($solde).'</td>';
|
||||
print '</tr>';
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td align="left" colspan="5">'.$langs->trans("RemainderToPay").'</td>';
|
||||
print '<td align="right" nowrap> </td>';
|
||||
print '</tr>';
|
||||
|
||||
|
||||
// Recuperation des factures clients et fournisseurs impayes
|
||||
$sql = "SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.type, ".$db->pdate("f.date_lim_reglement")." as dlr,";
|
||||
// Remainder to pay in future
|
||||
|
||||
// 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.= " FROM ".MAIN_DB_PREFIX."facture as f";
|
||||
$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.= " 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.= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
|
||||
$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";
|
||||
|
||||
// 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);
|
||||
$result2=false;
|
||||
if ($result)
|
||||
{
|
||||
$result2=$db->query($sql2);
|
||||
}
|
||||
if ($result2)
|
||||
{
|
||||
$error=0;
|
||||
$tab_sqlobj=array();
|
||||
|
||||
// List customer invoices
|
||||
$result = $db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $db->num_rows($result);
|
||||
for ($i = 0;$i < $num;$i++)
|
||||
{
|
||||
@@ -180,7 +188,13 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
|
||||
$tab_sqlobjOrder[]= $sqlobj->dlr;
|
||||
}
|
||||
$db->free($result);
|
||||
}
|
||||
else $error++;
|
||||
|
||||
// List supplier invoices
|
||||
$result2=$db->query($sql2);
|
||||
if ($result2)
|
||||
{
|
||||
$num = $db->num_rows($result2);
|
||||
for ($i = 0;$i < $num;$i++)
|
||||
{
|
||||
@@ -189,7 +203,29 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
|
||||
$tab_sqlobjOrder[]= $sqlobj->dlr;
|
||||
}
|
||||
$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);
|
||||
|
||||
//Apply distinct filter
|
||||
@@ -209,49 +245,53 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
|
||||
while ($i < $num)
|
||||
{
|
||||
$paiement = '';
|
||||
$ref = '';
|
||||
$refcomp = '';
|
||||
|
||||
$var=!$var;
|
||||
//$obj = $db->fetch_object($result);
|
||||
$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->nom = $obj->nom;
|
||||
$refcomp=$societestatic->getNomUrl(0,'',24);
|
||||
|
||||
// Todo: Ajouter gestion des avoirs fournisseurs, champ ff.type = 2
|
||||
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;
|
||||
$paiement = -1*$facturefournstatic->getSommePaiement(); // Payment already done
|
||||
}
|
||||
}
|
||||
else
|
||||
if ($obj->family == 'invoice')
|
||||
{
|
||||
$facturestatic->ref=$obj->facnumber;
|
||||
$facturestatic->id=$obj->facid;
|
||||
$facturestatic->ref=$obj->ref;
|
||||
$facturestatic->id=$obj->objid;
|
||||
$facturestatic->type=$obj->type;
|
||||
$facture = $facturestatic->getNomUrl(1,'');
|
||||
$ref = $facturestatic->getNomUrl(1,'');
|
||||
|
||||
// On recherche les paiements deja effectue pour les deduires
|
||||
$sqlp = "SELECT sum(amount) as paiement";
|
||||
$sqlp.= " FROM ".MAIN_DB_PREFIX.'paiement_facture';
|
||||
$sqlp.= " WHERE fk_facture = ".$obj->facid;
|
||||
$resql = $db->query($sqlp);
|
||||
if ($resql)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
if ($objp) $paiement = $objp->paiement;
|
||||
$societestatic->id = $obj->socid;
|
||||
$societestatic->nom = $obj->nom;
|
||||
$refcomp=$societestatic->getNomUrl(0,'',24);
|
||||
|
||||
$paiement = $facturestatic->getSommePaiement(); // Payment already done
|
||||
}
|
||||
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;
|
||||
@@ -259,17 +299,15 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
|
||||
$solde += $total_ttc;
|
||||
|
||||
print "<tr $bc[$var]>";
|
||||
print "<td>".$facture."</td>";
|
||||
print "<td>".$societestatic->getNomUrl(0,'',16)."</td>";
|
||||
print "<td>".dolibarr_print_date($obj->dlr,"day")."</td>";
|
||||
|
||||
print "<td>".$ref."</td>";
|
||||
print "<td>".$refcomp."</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> </td>"; };
|
||||
if ($obj->total_ttc >= 0) { print "<td> </td><td align=\"right\">".price($total_ttc)."</td>"; };
|
||||
print "<td align=\"right\">".price($solde)."</td>";
|
||||
print "</tr>";
|
||||
$i++;
|
||||
}
|
||||
//$db->free($result);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -35,10 +35,9 @@ require_once(DOL_DOCUMENT_ROOT ."/product.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT ."/client.class.php");
|
||||
|
||||
/**
|
||||
\class Facture
|
||||
\brief Classe permettant la gestion des factures clients
|
||||
* \class Facture
|
||||
* \brief Classe permettant la gestion des factures clients
|
||||
*/
|
||||
|
||||
class Facture extends CommonObject
|
||||
{
|
||||
var $db;
|
||||
@@ -1639,8 +1638,8 @@ class Facture extends CommonObject
|
||||
|
||||
|
||||
/**
|
||||
* \brief Renvoie la sommes des paiements deja effectu<74>s
|
||||
* \return Montant deja vers<72>, <0 si ko
|
||||
* \brief Return amount aof payments already done
|
||||
* \return int Amount of payment already done, <0 if KO
|
||||
*/
|
||||
function getSommePaiement()
|
||||
{
|
||||
@@ -1661,6 +1660,7 @@ class Facture extends CommonObject
|
||||
if ($resql)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
$this->db->free($resql);
|
||||
return $obj->amount;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -92,7 +92,7 @@ class box_comptes extends ModeleBoxes {
|
||||
$objp = $db->fetch_object($result);
|
||||
|
||||
$account_static->id = $objp->rowid;
|
||||
$solde=$account_static->solde();
|
||||
$solde=$account_static->solde(0);
|
||||
|
||||
$solde_total += $solde;
|
||||
|
||||
|
||||
@@ -152,6 +152,7 @@ ConfirmCustomerPayment=Do you confirm this paiement input for <b>%s</b> %s ?
|
||||
ValidateBill=Validate invoice
|
||||
NumberOfBills=Nb of invoices
|
||||
NumberOfBillsByMonth=Nb of invoices by month
|
||||
ShowSocialContribution=Show social contribution
|
||||
ShowBill=Show invoice
|
||||
ShowInvoice=Show invoice
|
||||
ShowInvoiceReplace=Show replacing invoice
|
||||
|
||||
@@ -122,6 +122,7 @@ ConfirmClassifyPayedPartiallyAbandon=Ce choix sera celui dans le cas d'un mauvai
|
||||
ValidateBill=Valider facture
|
||||
NumberOfBills=Nb de factures
|
||||
NumberOfBillsByMonth=Nb de factures par mois
|
||||
ShowSocialContribution=Afficher charge sociale
|
||||
ShowBill=Afficher facture
|
||||
ShowInvoice=Afficher la facture
|
||||
ShowInvoiceReplace=Afficher la facture de remplacement
|
||||
|
||||
@@ -152,6 +152,7 @@ ConfirmCustomerPayment=Confirmez-vous la saisie de ce r
|
||||
ValidateBill=Valider facture
|
||||
NumberOfBills=Nb de factures
|
||||
NumberOfBillsByMonth=Nb de factures par mois
|
||||
ShowSocialContribution=Afficher charge sociale
|
||||
ShowBill=Afficher facture
|
||||
ShowInvoice=Afficher facture
|
||||
ShowInvoiceReplace=Afficher facture de remplacement
|
||||
|
||||
Reference in New Issue
Block a user