* Copyright (C) 2004-2005 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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$ * */ require("./pre.inc.php"); require("../../tva.class.php"); require("../../chargesociales.class.php"); $langs->load("bills"); $user->getrights('compta'); if (!$user->rights->compta->resultat->lire) accessforbidden(); llxHeader(); $year=$_GET["year"]; if (! $year) { $year = strftime("%Y", time()); } $modecompta = $conf->compta->mode; if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; print_fiche_titre("Détail recettes-dépenses par client/fournisseur",($year?"  ".img_previous()." Année $year ".img_next()."":"")); print '
'; if ($modecompta=="CREANCES-DETTES") { print 'Il se base sur la date de validation des factures et inclut les factures dues, qu\'elles soient payées ou non'; print ' (Voir le rapport recettes-dépenses pour n\'inclure que les factures effectivement payées).
'; print '
'; } else { print 'Il se base sur la date de validation des factures et n\'inclut que les factures effectivement payées'; print ' (Voir le rapport en créances-dettes pour inclure les factures non encore payée).
'; print '
'; } print ''; print ''; print ''; print ""; print ""; print "\n"; /* * Factures clients */ $sql = "SELECT s.nom, s.idp, sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; $sql .= " WHERE f.fk_soc = s.idp AND f.fk_statut = 1"; if ($year) { $sql .= " AND f.datef between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; } if ($modecompta != 'CREANCES-DETTES') { $sql .= " AND f.paye = 1"; } $sql .= " GROUP BY s.nom ASC"; print ''; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; if ($num > 0) { $var=True; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print ""; print "\n"; print "\n"; print "\n"; $total_ht = $total_ht + $objp->amount_ht; $total_ttc = $total_ttc + $objp->amount_ttc; print "\n"; $i++; } } $db->free(); } else { dolibarr_print_error($db); } print ''; print ''; print ''; print ''; /* * Frais, factures fournisseurs. */ $sql = "SELECT s.nom, s.idp, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f"; $sql .= " WHERE f.fk_soc = s.idp"; if ($year) { $sql .= " AND f.datef between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; } if ($modecompta != 'CREANCES-DETTES') { $sql .= " AND f.paye = 1"; } $sql .= " GROUP BY s.nom ASC, s.idp"; print ''; $subtotal_ht = 0; $subtotal_ttc = 0; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; if ($num > 0) { $var=True; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print ""; print "\n"; print "\n"; print "\n"; $total_ht = $total_ht - $objp->amount_ht; $total_ttc = $total_ttc - $objp->amount_ttc; $subtotal_ht = $subtotal_ht + $objp->amount_ht; $subtotal_ttc = $subtotal_ttc + $objp->amount_ttc; print "\n"; $i++; } } $db->free(); } else { dolibarr_print_error($db); } print ''; print ''; print ''; print ''; /* * Charges sociales */ $subtotal = 0; print ''; $sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s"; $sql .= " WHERE s.fk_type = c.id AND c.deductible=1"; if ($year) { $sql .= " AND s.date_ech between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; } $sql .= " GROUP BY c.libelle DESC"; if ( $db->query($sql) ) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $obj = $db->fetch_object(); $total_ht = $total_ht - $obj->amount; $total_ttc = $total_ttc - $obj->amount; $subtotal_ht = $subtotal_ht + $obj->amount; $subtotal_ttc = $subtotal_ttc + $obj->amount; $var = !$var; print ""; print ''; print ''; print ''; $i++; } } else { dolibarr_print_error($db); } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; /* * Charges sociales non déductibles */ $subtotal = 0; print ''; $sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s"; $sql .= " WHERE s.fk_type = c.id AND c.deductible=0"; if ($year) { $sql .= " AND s.date_ech between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; } $sql .= " GROUP BY c.libelle DESC"; if ( $db->query($sql) ) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $obj = $db->fetch_object(); $total_ht = $total_ht - $obj->amount; $total_ttc = $total_ttc - $obj->amount; $subtotal_ht = $subtotal_ht + $obj->amount; $subtotal_ttc = $subtotal_ttc + $obj->amount; $var = !$var; print ""; print ''; print ''; print ''; print ''; $i++; } } else { dolibarr_print_error($db); } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "
 Elément".$langs->trans("AmountHT")."".$langs->trans("AmountTTC")."
Facturation clients
 ".$langs->trans("Factures")." idp\">$objp->nom".price($objp->amount_ht)."".price($objp->amount_ttc)."
'.price($total_ht).''.price($total_ttc).'
Facturation fournisseurs
 ".$langs->trans("Bills")." idp."\">$objp->nom".price($objp->amount_ht)."".price($objp->amount_ttc)."
'.price($subtotal_ht).''.price($subtotal_ttc).'
Prestations/Charges déductibles
 '.$obj->nom.''.price($obj->amount).'
'.price($subtotal_ht).''.price($subtotal_ttc).'
Résultat'.price($total_ht).''.price($total_ttc).'
Prestations/Charges NON déductibles
 '.$obj->nom.''.price($obj->amount).''.price($obj->amount).'
'.price($subtotal_ht).''.price($subtotal_ttc).'
Résultat'.price($total_ht).''.price($total_ttc).'
"; $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>