* Copyright (C) 2004 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"); /* * */ $user->getrights('compta'); if (!$user->rights->compta->resultat) accessforbidden(); llxHeader(); print_titre("Résultat"); print ""; print ''; print ''; print ""; print "\n"; $sql = "SELECT s.nom,s.idp,sum(f.amount) as amount"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.idp AND f.fk_statut = 1 AND f.fk_user_valid is not NULL"; $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( $i); $var=!$var; print ""; print "\n"; print "\n"; $total = $total + $objp->amount; print "\n"; $i++; } } $db->free(); } else { print $db->error(); } print ''; /* * Frais, factures fournisseurs. * * */ $sql = "SELECT s.nom,s.idp,sum(f.total_ht) as amount"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f WHERE f.fk_soc = s.idp"; $sql .= " GROUP BY s.nom ASC, s.idp"; print ''; $subtotal = 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( $i); $var=!$var; print ""; print "\n"; print "\n"; $total = $total - $objp->amount; $subtotal = $subtotal + $objp->amount; print "\n"; $i++; } } $db->free(); } else { print $db->error(); } 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"; $sql .= " GROUP BY c.libelle DESC"; if ( $db->query($sql) ) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $obj = $db->fetch_object( $i); $total = $total - $obj->amount; $subtotal = $subtotal + $obj->amount; $var = !$var; print ""; print ''; print ''; print ''; $i++; } } else { print $db->error(); } 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"; $sql .= " GROUP BY c.libelle DESC"; if ( $db->query($sql) ) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $obj = $db->fetch_object( $i); $total = $total - $obj->amount; $subtotal = $subtotal + $obj->amount; $var = !$var; print ""; print ''; print ''; print ''; $i++; } } else { print $db->error(); } print ''; print ''; print "
 ElémentMontant
Factures
 Factures idp\">$objp->nom".price($objp->amount)."
'.price($total).'
Frais
 Factures idp."\">$objp->nom".price($objp->amount)."
'.price($subtotal).'
Prestations déductibles
 '.$obj->nom.''.price($obj->amount).'
'.price($subtotal).'
Résultat'.price($total).'
Prestations NON déductibles
 '.$obj->nom.''.price($obj->amount).'
'.price($subtotal).'
Résultat'.price($total).'
"; $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>