2004-10-19 22:35:36 +02:00
< ? php
2005-01-17 22:25:30 +01:00
/* Copyright ( C ) 2002 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2005 Laurent Destailleur < eldy @ users . sourceforge . net >
2004-03-04 22:26:03 +01:00
*
* 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 " );
2005-01-17 22:25:30 +01:00
$langs -> load ( " bills " );
2004-03-04 22:26:03 +01:00
$user -> getrights ( 'compta' );
2004-06-27 19:51:30 +02:00
if ( ! $user -> rights -> compta -> resultat -> lire )
2004-03-04 22:26:03 +01:00
accessforbidden ();
2005-01-17 22:25:30 +01:00
2004-03-04 22:26:03 +01:00
llxHeader ();
$year = $_GET [ " year " ];
if ( ! $year ) { $year = strftime ( " %Y " , time ()); }
2005-01-17 20:50:34 +01:00
$modecompta = $conf -> compta -> mode ;
if ( $_GET [ " modecompta " ]) $modecompta = $_GET [ " modecompta " ];
2004-03-04 22:26:03 +01:00
2004-07-30 12:32:27 +02:00
print_fiche_titre ( " D<EFBFBD> tail recettes-d<> penses par client/fournisseur " ,( $year ? " <a href='clientfourn.php?year= " . ( $year - 1 ) . " '> " . img_previous () . " </a> Ann<6E> e $year <a href='clientfourn.php?year= " . ( $year + 1 ) . " '> " . img_next () . " </a> " : " " ));
2004-03-04 22:26:03 +01:00
print '<br>' ;
2005-01-17 20:50:34 +01:00
if ( $modecompta == " CREANCES-DETTES " )
{
print 'Il se base sur la date de validation des factures et inclut les factures dues, qu\'elles soient pay<61> es ou non' ;
2005-01-17 21:26:12 +01:00
print ' (Voir le rapport <a href="clientfourn.php?year=' . $year . '&modecompta=RECETTES-DEPENSES">recettes-d<> penses</a> pour n\'inclure que les factures effectivement pay<61> es).<br>' ;
2005-01-17 20:50:34 +01:00
print '<br>' ;
}
else {
print 'Il se base sur la date de validation des factures et n\'inclut que les factures effectivement pay<61> es' ;
2005-01-17 21:26:12 +01:00
print ' (Voir le rapport en <a href="clientfourn.php?year=' . $year . '&modecompta=CREANCES-DETTES">cr<63> ances-dettes</a> pour inclure les factures non encore pay<61> e).<br>' ;
2005-01-17 20:50:34 +01:00
print '<br>' ;
}
print '<table class="noborder" width="100%">' ;
2004-03-04 22:26:03 +01:00
print '<tr class="liste_titre">' ;
print '<td width="10%"> </td><td>El<45> ment</td>' ;
2005-01-17 20:50:34 +01:00
print " <td align= \" right \" > " . $langs -> trans ( " AmountHT " ) . " </td> " ;
2005-01-17 21:26:12 +01:00
print " <td align= \" right \" > " . $langs -> trans ( " AmountTTC " ) . " </td> " ;
2004-03-04 22:26:03 +01:00
print " </tr> \n " ;
2004-04-10 21:04:14 +02:00
/*
* Factures clients
*/
2005-01-17 21:26:12 +01:00
$sql = " SELECT s.nom, s.idp, sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc " ;
2005-01-17 20:50:34 +01:00
$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 " ;
2004-03-04 22:26:03 +01:00
if ( $year ) {
$sql .= " AND f.datef between ' $year -01-01 00:00:00' and ' $year -12-31 23:59:59' " ;
}
2005-01-17 20:50:34 +01:00
if ( $modecompta != 'CREANCES-DETTES' ) {
$sql .= " AND f.paye = 1 " ;
}
2004-03-04 22:26:03 +01:00
$sql .= " GROUP BY s.nom ASC " ;
print '<tr><td colspan="4">Facturation clients</td></tr>' ;
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ();
$i = 0 ;
if ( $num > 0 ) {
$var = True ;
while ( $i < $num ) {
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ( $result );
2004-03-04 22:26:03 +01:00
$var =! $var ;
print " <tr $bc[$var] ><td> </td> " ;
2005-01-17 22:25:30 +01:00
print " <td> " . $langs -> trans ( " Factures " ) . " <a href= \" ../facture.php?socidp= $objp->idp\ " > $objp -> nom </ td > \n " ;
2004-03-04 22:26:03 +01:00
2005-01-17 21:26:12 +01:00
print " <td align= \" right \" > " . price ( $objp -> amount_ht ) . " </td> \n " ;
print " <td align= \" right \" > " . price ( $objp -> amount_ttc ) . " </td> \n " ;
2004-03-04 22:26:03 +01:00
2005-01-17 21:26:12 +01:00
$total_ht = $total_ht + $objp -> amount_ht ;
$total_ttc = $total_ttc + $objp -> amount_ttc ;
2004-03-04 22:26:03 +01:00
print " </tr> \n " ;
$i ++ ;
}
}
$db -> free ();
} else {
2005-01-17 20:50:34 +01:00
dolibarr_print_error ( $db );
2004-03-04 22:26:03 +01:00
}
2005-01-17 21:26:12 +01:00
print '<tr>' ;
print '<td colspan="3" align="right">' . price ( $total_ht ) . '</td>' ;
print '<td align="right">' . price ( $total_ttc ) . '</td>' ;
print '</tr>' ;
2004-04-10 21:04:14 +02:00
2004-03-04 22:26:03 +01:00
/*
* Frais , factures fournisseurs .
*/
2004-04-10 21:04:14 +02:00
2005-01-17 21:26:12 +01:00
$sql = " SELECT s.nom, s.idp, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc " ;
2005-01-17 20:50:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture_fourn as f " ;
$sql .= " WHERE f.fk_soc = s.idp " ;
2004-03-04 22:26:03 +01:00
if ( $year ) {
$sql .= " AND f.datef between ' $year -01-01 00:00:00' and ' $year -12-31 23:59:59' " ;
}
2005-01-17 20:50:34 +01:00
if ( $modecompta != 'CREANCES-DETTES' ) {
$sql .= " AND f.paye = 1 " ;
}
2004-03-04 22:26:03 +01:00
$sql .= " GROUP BY s.nom ASC, s.idp " ;
print '<tr><td colspan="4">Facturation fournisseurs</td></tr>' ;
2005-01-17 21:26:12 +01:00
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
2004-03-04 22:26:03 +01:00
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ();
$i = 0 ;
if ( $num > 0 ) {
$var = True ;
while ( $i < $num ) {
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ( $result );
2004-03-04 22:26:03 +01:00
$var =! $var ;
print " <tr $bc[$var] ><td> </td> " ;
2005-01-17 20:50:34 +01:00
print " <td> " . $langs -> trans ( " Bills " ) . " <a href= \" ../../fourn/facture/index.php?socid= " . $objp -> idp . " \" > $objp->nom </a></td> \n " ;
2004-03-04 22:26:03 +01:00
2005-01-17 21:26:12 +01:00
print " <td align= \" right \" > " . price ( $objp -> amount_ht ) . " </td> \n " ;
print " <td align= \" right \" > " . price ( $objp -> amount_ttc ) . " </td> \n " ;
2004-03-04 22:26:03 +01:00
2005-01-17 21:26:12 +01:00
$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 ;
2004-03-04 22:26:03 +01:00
print " </tr> \n " ;
$i ++ ;
}
}
$db -> free ();
} else {
2005-01-17 20:50:34 +01:00
dolibarr_print_error ( $db );
2004-03-04 22:26:03 +01:00
}
2005-01-17 21:26:12 +01:00
print '<tr>' ;
print '<td colspan="3" align="right">' . price ( $subtotal_ht ) . '</td>' ;
print '<td align="right">' . price ( $subtotal_ttc ) . '</td>' ;
print '</tr>' ;
2004-03-04 22:26:03 +01:00
/*
* Charges sociales
*/
2004-04-10 21:04:14 +02:00
2004-03-04 22:26:03 +01:00
$subtotal = 0 ;
print '<tr><td colspan="4">Prestations/Charges d<> ductibles</td></tr>' ;
$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 ) {
2004-10-23 18:55:07 +02:00
$obj = $db -> fetch_object ();
2004-03-04 22:26:03 +01:00
2005-01-17 21:26:12 +01:00
$total_ht = $total_ht - $obj -> amount ;
$total_ttc = $total_ttc - $obj -> amount ;
$subtotal_ht = $subtotal_ht + $obj -> amount ;
$subtotal_ttc = $subtotal_ttc + $obj -> amount ;
2004-03-04 22:26:03 +01:00
$var = ! $var ;
print " <tr $bc[$var] ><td> </td> " ;
print '<td>' . $obj -> nom . '</td>' ;
print '<td align="right">' . price ( $obj -> amount ) . '</td>' ;
print '</tr>' ;
$i ++ ;
}
} else {
2005-01-17 20:50:34 +01:00
dolibarr_print_error ( $db );
2004-03-04 22:26:03 +01:00
}
2005-01-17 21:26:12 +01:00
print '<tr>' ;
print '<td colspan="3" align="right">' . price ( $subtotal_ht ) . '</td>' ;
print '<td colspan="3" align="right">' . price ( $subtotal_ttc ) . '</td>' ;
print '</tr>' ;
2004-03-04 22:26:03 +01:00
2005-01-17 21:26:12 +01:00
print '<tr><td align="right" colspan="2">R<> sultat</td>' ;
print '<td class="border" align="right">' . price ( $total_ht ) . '</td>' ;
print '<td class="border" align="right">' . price ( $total_ttc ) . '</td>' ;
print '</tr>' ;
2004-04-10 21:04:14 +02:00
2004-03-04 22:26:03 +01:00
/*
* Charges sociales non d<EFBFBD> ductibles
*/
2004-04-10 21:04:14 +02:00
2004-03-04 22:26:03 +01:00
$subtotal = 0 ;
print '<tr><td colspan="4">Prestations/Charges NON d<> ductibles</td></tr>' ;
$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 ) {
2004-10-23 18:55:07 +02:00
$obj = $db -> fetch_object ();
2004-03-04 22:26:03 +01:00
2005-01-17 21:26:12 +01:00
$total_ht = $total_ht - $obj -> amount ;
$total_ttc = $total_ttc - $obj -> amount ;
$subtotal_ht = $subtotal_ht + $obj -> amount ;
$subtotal_ttc = $subtotal_ttc + $obj -> amount ;
2004-03-04 22:26:03 +01:00
$var = ! $var ;
print " <tr $bc[$var] ><td> </td> " ;
print '<td>' . $obj -> nom . '</td>' ;
print '<td align="right">' . price ( $obj -> amount ) . '</td>' ;
2005-01-17 21:26:12 +01:00
print '<td align="right">' . price ( $obj -> amount ) . '</td>' ;
2004-03-04 22:26:03 +01:00
print '</tr>' ;
$i ++ ;
}
} else {
2005-01-17 20:50:34 +01:00
dolibarr_print_error ( $db );
2004-03-04 22:26:03 +01:00
}
2005-01-17 21:26:12 +01:00
print '<tr>' ;
print '<td colspan="3" align="right">' . price ( $subtotal_ht ) . '</td>' ;
print '<td colspan="3" align="right">' . price ( $subtotal_ttc ) . '</td>' ;
print '</tr>' ;
2004-03-04 22:26:03 +01:00
2005-01-17 21:26:12 +01:00
print '<tr><td align="right" colspan="2">R<> sultat</td>' ;
print '<td class="border" align="right">' . price ( $total_ht ) . '</td>' ;
print '<td class="border" align="right">' . price ( $total_ttc ) . '</td>' ;
print '</tr>' ;
2004-03-04 22:26:03 +01:00
print " </table> " ;
$db -> close ();
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
?>