2004-10-19 22:35:36 +02:00
< ? php
2004-03-04 22:26:03 +01:00
/* Copyright ( C ) 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2004-01-30 21:33:34 +01:00
* Copyright ( C ) 2004 Laurent Destailleur < eldy @ users . sourceforge . net >
2002-06-19 00:23:12 +02: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 .
*
2002-06-19 11:20:41 +02:00
* $Id $
* $Source $
*
2002-06-19 00:23:12 +02:00
*/
2003-09-11 22:18:51 +02:00
require ( " ./pre.inc.php " );
2003-11-08 20:05:47 +01:00
2002-06-19 00:23:12 +02:00
/*
*
*/
2003-12-03 12:22:30 +01:00
llxHeader ();
2002-06-19 00:23:12 +02:00
2004-03-04 22:26:03 +01:00
/*
* S<EFBFBD> curit<EFBFBD> acc<EFBFBD> s client
*/
if ( $user -> societe_id > 0 )
{
$socidp = $user -> societe_id ;
}
2005-01-17 20:50:34 +01:00
$year_current = $_GET [ " year " ];
2004-03-04 22:26:03 +01:00
if ( ! $year_current ) { $year_current = strftime ( " %Y " , time ()); }
2005-01-17 20:50:34 +01:00
$modecompta = $conf -> compta -> mode ;
if ( $_GET [ " modecompta " ]) $modecompta = $_GET [ " modecompta " ];
2002-06-19 00:23:12 +02:00
2004-03-04 22:26:03 +01:00
print_titre ( " R<EFBFBD> sultat comptable, r<> sum<75> annuel " );
print '<br>' ;
2003-10-28 17:49:34 +01:00
2005-01-17 20:50:34 +01:00
print " Ce rapport pr<70> sente la balance entre les recettes et les d<> penses factur<75> es aux clients ou fournisseurs. Les d<> penses de charges ne sont pas incluses.<br> \n " ;
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="index.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="index.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>' ;
}
2002-06-20 15:23:17 +02:00
2005-01-17 20:50:34 +01:00
/*
* Factures clients
*/
2005-01-17 21:26:12 +01:00
$sql = " SELECT sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm " ;
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 " ;
if ( $_GET [ " year " ]) {
$sql .= " AND f.datef between ' " . $_GET [ " year " ] . " -01-01 00:00:00' and ' " . $_GET [ " year " ] . " -12-31 23:59:59' " ;
2004-03-04 22:26:03 +01:00
}
if ( $socidp )
{
2005-01-17 20:50:34 +01:00
$sql .= " AND f.fk_soc = $socidp " ;
}
if ( $modecompta != 'CREANCES-DETTES' ) {
$sql .= " AND f.paye = 1 " ;
2004-03-04 22:26:03 +01:00
}
$sql .= " GROUP BY dm DESC " ;
if ( $db -> query ( $sql ))
{
2002-06-19 00:23:12 +02:00
$num = $db -> num_rows ();
2004-03-04 22:26:03 +01:00
$i = 0 ;
while ( $i < $num )
{
2005-01-17 21:26:12 +01:00
$row = $db -> fetch_object ( $i );
$encaiss [ $row -> dm ] = $row -> amount_ht ;
$encaiss_ttc [ $row -> dm ] = $row -> amount_ttc ;
2002-06-19 00:23:12 +02:00
$i ++ ;
}
}
2004-03-04 22:26:03 +01:00
else {
2005-01-17 20:50:34 +01:00
dolibarr_print_error ( $db );
2004-03-04 22:26:03 +01:00
}
2005-01-17 20:50:34 +01:00
/*
* Frais , factures fournisseurs .
*/
2005-01-17 21:26:12 +01:00
$sql = " SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm " ;
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 AND f.fk_statut = 1 " ;
if ( $_GET [ " year " ]) {
$sql .= " AND f.datef between ' " . $_GET [ " year " ] . " -01-01 00:00:00' and ' " . $_GET [ " year " ] . " -12-31 23:59:59' " ;
2004-03-04 22:26:03 +01:00
}
if ( $socidp )
{
$sql .= " AND f.fk_soc = $socidp " ;
}
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 dm DESC " ;
2002-06-20 15:23:17 +02:00
2004-03-04 22:26:03 +01:00
if ( $db -> query ( $sql ))
{
2002-06-20 15:23:17 +02:00
$num = $db -> num_rows ();
2004-03-04 22:26:03 +01:00
$i = 0 ;
while ( $i < $num )
{
2005-01-17 21:26:12 +01:00
$row = $db -> fetch_object ( $i );
$decaiss [ $row -> dm ] = $row -> amount_ht ;
$decaiss_ttc [ $row -> dm ] = $row -> amount_ttc ;
2002-06-20 15:23:17 +02:00
$i ++ ;
}
}
2004-03-04 22:26:03 +01:00
else {
2005-01-17 20:50:34 +01:00
dolibarr_print_error ( $db );
2002-06-19 11:20:41 +02:00
}
2005-01-17 20:50:34 +01:00
/*
* Charges sociales
*/
print '<table class="noborder" width="100%">' ;
2004-07-31 15:46:12 +02:00
print '<tr class="liste_titre"><td rowspan=2>' . $langs -> trans ( " Month " ) . '</td>' ;
2002-06-19 11:20:41 +02:00
2003-10-28 17:49:34 +01:00
2004-03-04 22:26:03 +01:00
if ( $year_current < ( MAIN_START_YEAR + 2 ))
{
$year_start = MAIN_START_YEAR ;
$year_end = ( MAIN_START_YEAR + 2 );
}
else
{
$year_start = $year_current - 2 ;
$year_end = $year_current ;
2002-06-19 00:23:12 +02:00
}
2004-03-04 22:26:03 +01:00
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ )
{
print '<td align="center" width="20%" colspan="2"><a href="clientfourn.php?year=' . $annee . '">' . $annee . '</a></td>' ;
}
print '</tr>' ;
print '<tr class="liste_titre">' ;
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ )
{
print '<td align="right">Recettes</td><td align="right">D<> penses</td>' ;
}
print '</tr>' ;
$var = True ;
for ( $mois = 1 ; $mois < 13 ; $mois ++ )
{
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
print " <td> " . strftime ( " %B " , mktime ( 1 , 1 , 1 , $mois , 1 , $annee )) . " </td> " ;
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ )
{
print '<td align="right" width="10%"> ' ;
$case = strftime ( " %Y-%m " , mktime ( 1 , 1 , 1 , $mois , 1 , $annee ));
if ( $encaiss [ $case ] > 0 )
{
print price ( $encaiss [ $case ]);
$totentrees [ $annee ] += $encaiss [ $case ];
}
print " </td> " ;
print '<td align="right" width="10%"> ' ;
$case = strftime ( " %Y-%m " , mktime ( 1 , 1 , 1 , $mois , 1 , $annee ));
if ( $decaiss [ $case ] > 0 )
{
print price ( $decaiss [ $case ]);
$totsorties [ $annee ] += $decaiss [ $case ];
}
print " </td> " ;
}
2002-06-19 00:23:12 +02:00
2004-03-04 22:26:03 +01:00
print '</tr>' ;
}
2002-06-19 00:23:12 +02:00
2004-03-04 22:26:03 +01:00
$var =! $var ;
print " <tr $bc[$var] ><td><b>Total annuel</b></td> " ;
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ )
{
print '<td align="right">' . price ( $totentrees [ $annee ]) . '</td><td align="right">' . price ( $totsorties [ $annee ]) . '</td>' ;
}
print " </tr> \n " ;
2002-06-19 00:23:12 +02:00
2004-03-04 22:26:03 +01:00
print " </table> " ;
2002-06-19 00:23:12 +02:00
$db -> close ();
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
2004-03-04 22:26:03 +01:00
2002-06-19 00:23:12 +02:00
?>