2004-10-19 22:35:36 +02:00
< ? php
2006-12-23 16:40:17 +01:00
/* Copyright ( C ) 2002 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2009-02-11 22:15:47 +01:00
* Copyright ( C ) 2004 - 2009 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 .
*/
2005-05-03 02:41:51 +02:00
/**
2006-12-23 16:40:17 +01:00
\file htdocs / compta / resultat / clientfourn . php
\brief Page reporting resultat
2008-04-03 21:35:46 +02:00
\version $Id $
2005-05-03 02:41:51 +02:00
*/
2004-03-04 22:26:03 +01:00
require ( " ./pre.inc.php " );
2008-04-03 21:35:46 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /compta/tva/tva.class.php " );
2008-01-10 18:12:07 +01:00
require_once ( DOL_DOCUMENT_ROOT . " /chargesociales.class.php " );
2008-04-20 06:24:00 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /lib/report.lib.php " );
2008-01-10 18:12:07 +01:00
2004-03-04 22:26:03 +01:00
2005-01-17 22:25:30 +01:00
$langs -> load ( " bills " );
2006-07-27 13:01:44 +02:00
if ( ! $user -> rights -> facture -> lire )
2004-03-04 22:26:03 +01:00
accessforbidden ();
$year = $_GET [ " year " ];
if ( ! $year ) { $year = strftime ( " %Y " , time ()); }
2008-02-16 18:50:25 +01:00
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
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
2005-05-03 02:41:51 +02:00
llxHeader ();
$html = new Form ( $db );
2008-02-20 01:39:33 +01:00
// Affiche en-t<> te de rapport
2005-01-17 20:50:34 +01:00
if ( $modecompta == " CREANCES-DETTES " )
{
2007-11-11 19:05:08 +01:00
$nom = $langs -> trans ( " AnnualByCompaniesDueDebtMode " );
$nom .= '<br>(' . $langs -> trans ( " SeeReportInInputOutputMode " , '<a href="' . $_SERVER [ " PHP_SELF " ] . '?year=' . $year . '&modecompta=RECETTES-DEPENSES">' , '</a>' ) . ')' ;
2005-06-11 13:58:06 +02:00
$period = $langs -> trans ( " Year " ) . " " . $year ;
2007-11-11 19:05:08 +01:00
$periodlink = '<a href="' . $_SERVER [ " PHP_SELF " ] . '?year=' . ( $year - 1 ) . '&modecompta=' . $modecompta . '">' . img_previous () . '</a> <a href="' . $_SERVER [ " PHP_SELF " ] . '?year=' . ( $year + 1 ) . '&modecompta=' . $modecompta . '">' . img_next () . '</a>' ;
2005-05-03 02:41:51 +02:00
$description = $langs -> trans ( " RulesResultDue " );
$builddate = time ();
$exportlink = $langs -> trans ( " NotYetAvailable " );
2005-01-17 20:50:34 +01:00
}
else {
2007-11-11 19:05:08 +01:00
$nom = $langs -> trans ( " AnnualByCompaniesInputOutputMode " );
$nom .= '<br>(' . $langs -> trans ( " SeeReportInDueDebtMode " , '<a href="' . $_SERVER [ " PHP_SELF " ] . '?year=' . $year . '&modecompta=CREANCES-DETTES">' , '</a>' ) . ')' ;
2005-06-11 13:58:06 +02:00
$period = $langs -> trans ( " Year " ) . " " . $year ;
2007-11-11 19:05:08 +01:00
$periodlink = '<a href="' . $_SERVER [ " PHP_SELF " ] . '?year=' . ( $year - 1 ) . '&modecompta=' . $modecompta . '">' . img_previous () . '</a> <a href="' . $_SERVER [ " PHP_SELF " ] . '?year=' . ( $year + 1 ) . '&modecompta=' . $modecompta . '">' . img_next () . '</a>' ;
2005-05-03 02:41:51 +02:00
$description = $langs -> trans ( " RulesResultInOut " );
$builddate = time ();
$exportlink = $langs -> trans ( " NotYetAvailable " );
2005-01-17 20:50:34 +01:00
}
2008-01-10 18:12:07 +01:00
report_header ( $nom , $nomlink , $period , $periodlink , $description , $builddate , $exportlink );
2005-01-17 20:50:34 +01:00
2005-05-03 02:41:51 +02:00
// Affiche rapport
2005-01-17 20:50:34 +01:00
print '<table class="noborder" width="100%">' ;
2004-03-04 22:26:03 +01:00
print '<tr class="liste_titre">' ;
2005-04-07 23:21:44 +02:00
print '<td width="10%"> </td><td>' . $langs -> trans ( " Element " ) . '</td>' ;
2005-04-08 01:39:47 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) 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 " ;
2005-05-03 02:41:51 +02:00
print '<tr><td colspan="4"> </td></tr>' ;
2004-04-10 21:04:14 +02:00
/*
* Factures clients
*/
2005-05-06 02:21:33 +02:00
print '<tr><td colspan="4">Facturation clients</td></tr>' ;
2009-02-11 22:15:47 +01:00
if ( $modecompta == 'CREANCES-DETTES' ) {
2007-06-12 00:51:47 +02:00
$sql = " SELECT s.nom, s.rowid as socid, sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc " ;
2005-04-08 01:39:47 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture as f " ;
2007-06-12 00:51:47 +02:00
$sql .= " WHERE f.fk_soc = s.rowid AND f.fk_statut in (1,2) " ;
2005-05-06 02:21:33 +02:00
if ( $year ) $sql .= " AND f.datef between ' " . $year . " -01-01 00:00:00' and ' " . $year . " -12-31 23:59:59' " ;
2005-04-07 23:21:44 +02:00
} else {
2005-04-08 01:39:47 +02:00
/*
2005-05-06 02:21:33 +02:00
* Liste des paiements ( les anciens paiements ne sont pas vus par cette requete car , sur les
2008-11-15 22:35:01 +01:00
* vieilles versions , ils n ' etaient pas lies via paiement_facture . On les ajoute plus loin )
2005-04-08 01:39:47 +02:00
*/
2007-06-12 00:51:47 +02:00
$sql = " SELECT s.nom as nom, s.rowid as socid, sum(pf.amount) as amount_ttc " ;
2005-04-08 01:39:47 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture as f, " . MAIN_DB_PREFIX . " paiement_facture as pf, " . MAIN_DB_PREFIX . " paiement as p " ;
2007-06-12 00:51:47 +02:00
$sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_soc = s.rowid " ;
2005-05-06 02:21:33 +02:00
if ( $year ) $sql .= " AND p.datep between ' " . $year . " -01-01 00:00:00' and ' " . $year . " -12-31 23:59:59' " ;
2009-02-11 22:15:47 +01:00
}
2007-02-28 11:23:03 +01:00
if ( $socid ) $sql .= " AND f.fk_soc = $socid " ;
2005-04-08 01:39:47 +02:00
$sql .= " GROUP BY nom " ;
$sql .= " ORDER BY nom " ;
2004-03-04 22:26:03 +01:00
$result = $db -> query ( $sql );
if ( $result ) {
2005-04-07 23:21:44 +02:00
$num = $db -> num_rows ( $result );
$i = 0 ;
$var = true ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $result );
$var =! $var ;
2009-02-11 22:15:47 +01:00
2006-12-23 16:40:17 +01:00
print " <tr $bc[$var] ><td> </td> " ;
2007-06-12 00:51:47 +02:00
print " <td> " . $langs -> trans ( " Bills " ) . " <a href= \" ../facture.php?socid= " . $objp -> socid . " \" > $objp->nom </td> \n " ;
2009-02-11 22:15:47 +01:00
2005-04-08 01:39:47 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) print " <td align= \" right \" > " . price ( $objp -> amount_ht ) . " </td> \n " ;
2005-04-07 23:21:44 +02:00
print " <td align= \" right \" > " . price ( $objp -> amount_ttc ) . " </td> \n " ;
2009-02-11 22:15:47 +01:00
2005-04-07 23:21:44 +02:00
$total_ht = $total_ht + $objp -> amount_ht ;
$total_ttc = $total_ttc + $objp -> amount_ttc ;
print " </tr> \n " ;
$i ++ ;
2004-03-04 22:26:03 +01:00
}
2005-04-07 23:21:44 +02:00
$db -> free ( $result );
2004-03-04 22:26:03 +01:00
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2004-03-04 22:26:03 +01:00
}
2005-05-03 02:57:27 +02:00
2009-02-11 22:15:47 +01:00
// On ajoute les paiements clients anciennes version, non lie par paiement_facture
2007-02-28 10:06:11 +01:00
if ( $modecompta != 'CREANCES-DETTES' )
2009-02-11 22:15:47 +01:00
{
2005-05-06 02:21:33 +02:00
$sql = " SELECT 'Autres' as nom, '0' as idp, sum(p.amount) as amount_ttc " ;
2005-04-08 01:39:47 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " paiement as p " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " paiement_facture as pf ON p.rowid = pf.fk_paiement " ;
$sql .= " WHERE pf.rowid IS NULL " ;
2005-05-06 02:21:33 +02:00
if ( $year ) $sql .= " AND p.datep between ' " . $year . " -01-01 00:00:00' and ' " . $year . " -12-31 23:59:59' " ;
2005-04-08 01:39:47 +02:00
$sql .= " GROUP BY nom " ;
$sql .= " ORDER BY nom " ;
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
2005-05-03 02:41:51 +02:00
if ( $num ) {
while ( $i < $num )
{
$objp = $db -> fetch_object ( $result );
$var =! $var ;
2009-02-11 22:15:47 +01:00
2006-12-23 16:40:17 +01:00
print " <tr $bc[$var] ><td> </td> " ;
2008-11-15 22:35:01 +01:00
print " <td> " . $langs -> trans ( " Bills " ) . " " . $langs -> trans ( " Other " ) . " ( " . $langs -> trans ( " PaymentsNotLinkedToInvoice " ) . " ) \n " ;
2009-02-11 22:15:47 +01:00
2005-05-03 02:41:51 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) print " <td align= \" right \" > " . price ( $objp -> amount_ht ) . " </td> \n " ;
print " <td align= \" right \" > " . price ( $objp -> amount_ttc ) . " </td> \n " ;
2009-02-11 22:15:47 +01:00
2005-05-03 02:41:51 +02:00
$total_ht = $total_ht + $objp -> amount_ht ;
$total_ttc = $total_ttc + $objp -> amount_ttc ;
print " </tr> \n " ;
$i ++ ;
}
}
2005-04-08 01:39:47 +02:00
$db -> free ( $result );
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2005-04-08 01:39:47 +02:00
}
}
2005-05-07 18:02:22 +02:00
if ( $total_ttc == 0 )
{
$var =! $var ;
2006-12-23 16:40:17 +01:00
print " <tr $bc[$var] ><td> </td> " ;
2005-05-07 18:02:22 +02:00
print '<td colspan="3">' . $langs -> trans ( " None " ) . '</td>' ;
print '</tr>' ;
}
2005-05-03 02:41:51 +02:00
print '<tr class="liste_total">' ;
2005-04-08 01:39:47 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) print '<td colspan="3" align="right">' . price ( $total_ht ) . '</td>' ;
print '<td colspan="3" align="right">' . price ( $total_ttc ) . '</td>' ;
2005-01-17 21:26:12 +01:00
print '</tr>' ;
2004-04-10 21:04:14 +02:00
2005-05-11 03:23:52 +02:00
2004-03-04 22:26:03 +01:00
/*
* Frais , factures fournisseurs .
*/
2007-02-28 10:06:11 +01:00
if ( $modecompta == 'CREANCES-DETTES' )
2009-02-11 22:15:47 +01:00
{
2007-06-12 00:51:47 +02:00
$sql = " SELECT s.nom, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm " ;
2005-04-07 23:21:44 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture_fourn as f " ;
2007-06-12 00:51:47 +02:00
$sql .= " WHERE f.fk_soc = s.rowid AND f.fk_statut in (1,2) " ;
2005-04-08 01:39:47 +02:00
if ( $year ) {
$sql .= " AND f.datef between ' " . $year . " -01-01 00:00:00' and ' " . $year . " -12-31 23:59:59' " ;
2005-04-07 23:21:44 +02:00
}
} else {
2007-06-12 00:51:47 +02:00
$sql = " SELECT s.nom, s.rowid as socid, date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc " ;
2005-12-17 01:26:35 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " paiementfourn as p, " . MAIN_DB_PREFIX . " paiementfourn_facturefourn as pf " ;
2005-04-08 01:39:47 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " facture_fourn as f " ;
2006-03-23 15:24:26 +01:00
$sql .= " ON pf.fk_facturefourn = f.rowid " ;
2005-04-08 01:39:47 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s " ;
2007-06-12 00:51:47 +02:00
$sql .= " ON f.fk_soc = s.rowid " ;
2005-12-17 01:26:35 +01:00
$sql .= " WHERE p.rowid = pf.fk_paiementfourn " ;
2005-04-08 01:39:47 +02:00
if ( $year ) {
$sql .= " AND p.datep between ' " . $year . " -01-01 00:00:00' and ' " . $year . " -12-31 23:59:59' " ;
2005-04-07 23:21:44 +02:00
}
2005-01-17 20:50:34 +01:00
}
2007-02-28 11:23:03 +01:00
if ( $socid )
{
2007-06-12 00:51:47 +02:00
$sql .= " AND f.fk_soc = " . $socid ;
2007-02-28 11:23:03 +01:00
}
2007-06-12 00:51:47 +02:00
$sql .= " GROUP BY nom, s.rowid " ;
$sql .= " ORDER BY nom, s.rowid " ;
2004-03-04 22:26:03 +01:00
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 ) {
2005-04-07 23:21:44 +02:00
$num = $db -> num_rows ( $result );
2004-03-04 22:26:03 +01:00
$i = 0 ;
2005-05-03 02:41:51 +02:00
$var = true ;
2004-03-04 22:26:03 +01:00
if ( $num > 0 ) {
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 ;
2009-02-11 22:15:47 +01:00
2006-12-23 16:40:17 +01:00
print " <tr $bc[$var] ><td> </td> " ;
2007-06-12 00:51:47 +02:00
print " <td> " . $langs -> trans ( " Bills " ) . " <a href= \" " . DOL_URL_ROOT . " /fourn/facture/index.php?socid= " . $objp -> socid . " \" > " . $objp -> nom . " </a></td> \n " ;
2009-02-11 22:15:47 +01:00
2005-05-11 03:23:52 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) print " <td align= \" right \" > " . price ( - $objp -> amount_ht ) . " </td> \n " ;
print " <td align= \" right \" > " . price ( - $objp -> amount_ttc ) . " </td> \n " ;
2009-02-11 22:15:47 +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 ++ ;
}
}
2005-05-03 02:41:51 +02:00
else {
$var =! $var ;
2006-12-23 16:40:17 +01:00
print " <tr $bc[$var] ><td> </td> " ;
2005-05-03 02:41:51 +02:00
print '<td colspan="3">' . $langs -> trans ( " None " ) . '</td>' ;
print '</tr>' ;
}
2005-04-07 23:21:44 +02:00
$db -> free ( $result );
2004-03-04 22:26:03 +01:00
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2004-03-04 22:26:03 +01:00
}
2005-05-03 02:52:13 +02:00
print '<tr class="liste_total">' ;
2005-05-11 03:23:52 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) print '<td colspan="3" align="right">' . price ( - $subtotal_ht ) . '</td>' ;
print '<td colspan="3" align="right">' . price ( - $subtotal_ttc ) . '</td>' ;
print '</tr>' ;
2009-02-11 22:15:47 +01:00
2005-05-11 03:23:52 +02:00
/*
2009-02-11 22:15:47 +01:00
* Charges sociales non deductibles
*/
print '<tr><td colspan="4">Prestations/Charges NON deductibles</td></tr>' ;
if ( $modecompta == 'CREANCES-DETTES' ) {
$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 " ;
}
else {
$sql = " SELECT c.libelle as nom, sum(p.amount) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_chargesociales as c, " . MAIN_DB_PREFIX . " chargesociales as s, " . MAIN_DB_PREFIX . " paiementcharge as p " ;
$sql .= " WHERE p.fk_charge = s.rowid AND s.fk_type = c.id AND c.deductible=0 " ;
if ( $year ) {
$sql .= " AND p.datep between ' $year -01-01 00:00:00' and ' $year -12-31 23:59:59' " ;
}
$sql .= " GROUP BY c.libelle " ;
}
$result = $db -> query ( $sql );
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
if ( $result ) {
$num = $db -> num_rows ( $result );
$var = true ;
$i = 0 ;
if ( $num ) {
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
$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 " <tr $bc[$var] ><td> </td> " ;
print '<td>' . $obj -> nom . '</td>' ;
if ( $modecompta == 'CREANCES-DETTES' ) print '<td align="right">' . price ( - $obj -> amount ) . '</td>' ;
print '<td align="right">' . price ( - $obj -> amount ) . '</td>' ;
print '</tr>' ;
$i ++ ;
}
}
else {
$var = ! $var ;
print " <tr $bc[$var] ><td> </td> " ;
print '<td colspan="3">' . $langs -> trans ( " None " ) . '</td>' ;
print '</tr>' ;
}
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2009-02-11 22:15:47 +01:00
}
print '<tr class="liste_total">' ;
if ( $modecompta == 'CREANCES-DETTES' ) print '<td colspan="3" align="right">' . price ( - $subtotal_ht ) . '</td>' ;
print '<td colspan="3" align="right">' . price ( - $subtotal_ttc ) . '</td>' ;
print '</tr>' ;
/*
* Charges sociales deductibles
*/
print '<tr><td colspan="4">Prestations/Charges deductibles</td></tr>' ;
if ( $modecompta == 'CREANCES-DETTES' ) {
$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 " ;
}
else {
$sql = " SELECT c.libelle as nom, sum(p.amount) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_chargesociales as c, " . MAIN_DB_PREFIX . " chargesociales as s, " . MAIN_DB_PREFIX . " paiementcharge as p " ;
$sql .= " WHERE p.fk_charge = s.rowid AND s.fk_type = c.id AND c.deductible=1 " ;
if ( $year ) {
$sql .= " AND p.datep between ' $year -01-01 00:00:00' and ' $year -12-31 23:59:59' " ;
}
$sql .= " GROUP BY c.libelle " ;
}
$result = $db -> query ( $sql );
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
if ( $result ) {
$num = $db -> num_rows ( $result );
$var = true ;
$i = 0 ;
if ( $num ) {
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
$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 " <tr $bc[$var] ><td> </td> " ;
print '<td>' . $obj -> nom . '</td>' ;
if ( $modecompta == 'CREANCES-DETTES' ) print '<td align="right">' . price ( - $obj -> amount ) . '</td>' ;
print '<td align="right">' . price ( - $obj -> amount ) . '</td>' ;
print '</tr>' ;
$i ++ ;
}
}
else {
$var = ! $var ;
print " <tr $bc[$var] ><td> </td> " ;
print '<td colspan="3">' . $langs -> trans ( " None " ) . '</td>' ;
print '</tr>' ;
}
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2009-02-11 22:15:47 +01:00
}
print '<tr class="liste_total">' ;
if ( $modecompta == 'CREANCES-DETTES' ) print '<td colspan="3" align="right">' . price ( - $subtotal_ht ) . '</td>' ;
print '<td colspan="3" align="right">' . price ( - $subtotal_ttc ) . '</td>' ;
print '</tr>' ;
if ( $mysoc -> tva_assuj == 'franchise' ) // Non assujeti
{
// Total
print '<tr>' ;
print '<td colspan="4"> </td>' ;
print '</tr>' ;
print '<tr class="liste_total"><td align="left" colspan="2">' . $langs -> trans ( " Profit " ) . '</td>' ;
if ( $modecompta == 'CREANCES-DETTES' ) print '<td class="border" align="right">' . price ( $total_ht ) . '</td>' ;
print '<td class="border" align="right">' . price ( $total_ttc ) . '</td>' ;
print '</tr>' ;
print '<tr>' ;
print '<td colspan="4"> </td>' ;
print '</tr>' ;
}
/*
* VAT
2005-05-11 03:23:52 +02:00
*/
print '<tr><td colspan="4">' . $langs -> trans ( " VAT " ) . '</td></tr>' ;
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
2005-08-16 01:39:04 +02:00
if ( $modecompta == 'CREANCES-DETTES' )
{
2009-02-11 22:15:47 +01:00
// TVA a payer
2005-08-16 01:01:42 +02:00
$amount = 0 ;
2009-02-11 22:15:47 +01:00
$sql = " SELECT sum(f.tva) as amount, date_format(f.datef,'%Y-%m') as dm " ;
2005-05-11 03:23:52 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f " ;
2007-02-28 10:06:11 +01:00
$sql .= " WHERE f.fk_statut in (1,2) " ;
2005-05-11 03:23:52 +02:00
if ( $year ) {
$sql .= " AND f.datef between ' " . $year . " -01-01 00:00:00' and ' " . $year . " -12-31 23:59:59' " ;
}
2005-08-16 01:01:42 +02:00
$sql .= " GROUP BY dm " ;
$sql .= " ORDER BY dm DESC " ;
2005-05-11 03:23:52 +02:00
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$var = false ;
$i = 0 ;
2009-02-11 22:15:47 +01:00
if ( $num ) {
2005-05-11 03:23:52 +02:00
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
2009-02-11 22:15:47 +01:00
2005-08-16 01:01:42 +02:00
$amount = $amount - $obj -> amount ;
2005-05-11 03:23:52 +02: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 ;
$i ++ ;
}
}
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2005-05-11 03:23:52 +02:00
}
2006-12-23 16:40:17 +01:00
print " <tr $bc[$var] ><td> </td> " ;
2005-05-11 03:23:52 +02:00
print " <td> " . $langs -> trans ( " VATToPay " ) . " </td> \n " ;
2005-08-16 01:01:42 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
2005-05-11 03:23:52 +02:00
print " </tr> \n " ;
2005-10-30 15:34:51 +01:00
2009-02-11 22:15:47 +01:00
// TVA a recuperer
2005-08-16 01:01:42 +02:00
$amount = 0 ;
2009-02-11 22:15:47 +01:00
$sql = " SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm " ;
2005-05-11 03:23:52 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture_fourn as f " ;
2007-02-28 10:06:11 +01:00
$sql .= " WHERE f.fk_statut in (1,2) " ;
2005-05-11 03:23:52 +02:00
if ( $year ) {
$sql .= " AND f.datef between ' " . $year . " -01-01 00:00:00' and ' " . $year . " -12-31 23:59:59' " ;
}
2005-08-16 01:01:42 +02:00
$sql .= " GROUP BY dm " ;
$sql .= " ORDER BY dm DESC " ;
2005-08-16 01:39:04 +02:00
2005-05-11 03:23:52 +02:00
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$var = true ;
$i = 0 ;
2009-02-11 22:15:47 +01:00
if ( $num ) {
2005-05-11 03:23:52 +02:00
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
2009-02-11 22:15:47 +01:00
2005-08-16 01:01:42 +02:00
$amount = $amount + $obj -> amount ;
2005-05-11 03:23:52 +02: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 ;
2009-02-11 22:15:47 +01:00
2005-05-11 03:23:52 +02:00
$i ++ ;
}
}
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2005-05-11 03:23:52 +02:00
}
2006-12-23 16:40:17 +01:00
print " <tr $bc[$var] ><td> </td> " ;
2005-05-11 03:23:52 +02:00
print " <td> " . $langs -> trans ( " VATToCollect " ) . " </td> \n " ;
2005-08-16 01:01:42 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
2005-05-11 03:23:52 +02:00
print " </tr> \n " ;
}
2005-08-16 01:39:04 +02:00
else
{
2009-02-11 22:15:47 +01:00
// TVA reellement deja payee
2005-08-16 01:01:42 +02:00
$amount = 0 ;
2009-02-11 22:15:47 +01:00
$sql = " SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm " ;
2005-05-11 03:23:52 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " tva as t " ;
$sql .= " WHERE amount > 0 " ;
if ( $year ) {
$sql .= " AND t.datev between ' " . $year . " -01-01 00:00:00' and ' " . $year . " -12-31 23:59:59' " ;
}
2005-08-16 01:01:42 +02:00
$sql .= " GROUP BY dm " ;
$sql .= " ORDER BY dm DESC " ;
2005-05-11 03:23:52 +02:00
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$var = false ;
$i = 0 ;
2009-02-11 22:15:47 +01:00
if ( $num ) {
2005-05-11 03:23:52 +02:00
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
2009-02-11 22:15:47 +01:00
2005-08-16 01:01:42 +02:00
$amount = $amount - $obj -> amount ;
2005-05-11 03:23:52 +02: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 ;
2009-02-11 22:15:47 +01:00
2005-05-11 03:23:52 +02:00
$i ++ ;
}
}
2005-10-30 15:34:51 +01:00
$db -> free ( $result );
2005-05-11 03:23:52 +02:00
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2005-05-11 03:23:52 +02:00
}
2006-12-23 16:40:17 +01:00
print " <tr $bc[$var] ><td> </td> " ;
2005-08-16 01:39:04 +02:00
print " <td> " . $langs -> trans ( " VATPayed " ) . " </td> \n " ;
2005-08-16 01:01:42 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
2005-05-11 03:23:52 +02:00
print " </tr> \n " ;
2005-10-30 15:34:51 +01:00
2009-02-11 22:15:47 +01:00
// TVA recuperee
2005-08-16 01:01:42 +02:00
$amount = 0 ;
2009-02-11 22:15:47 +01:00
$sql = " SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm " ;
2005-05-11 03:23:52 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " tva as t " ;
$sql .= " WHERE amount < 0 " ;
if ( $year ) {
$sql .= " AND t.datev between ' " . $year . " -01-01 00:00:00' and ' " . $year . " -12-31 23:59:59' " ;
}
2005-08-16 01:01:42 +02:00
$sql .= " GROUP BY dm " ;
$sql .= " ORDER BY dm DESC " ;
2005-05-11 03:23:52 +02:00
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$var = true ;
$i = 0 ;
2009-02-11 22:15:47 +01:00
if ( $num ) {
2005-05-11 03:23:52 +02:00
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
2009-02-11 22:15:47 +01:00
2005-08-16 01:01:42 +02:00
$amount = $amount + $obj -> amount ;
2005-05-11 03:23:52 +02: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 ;
2009-02-11 22:15:47 +01:00
2005-05-11 03:23:52 +02:00
$i ++ ;
}
}
2005-10-30 15:34:51 +01:00
$db -> free ( $result );
2005-05-11 03:23:52 +02:00
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2005-05-11 03:23:52 +02:00
}
2006-12-23 16:40:17 +01:00
print " <tr $bc[$var] ><td> </td> " ;
2005-08-16 01:39:04 +02:00
print " <td> " . $langs -> trans ( " VATCollected " ) . " </td> \n " ;
2005-10-30 15:34:51 +01:00
if ( $modecompta == 'CREANCES-DETTES' ) print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
2005-05-11 03:23:52 +02:00
print " </tr> \n " ;
}
2004-04-10 21:04:14 +02:00
2004-03-04 22:26:03 +01:00
2009-02-11 22:15:47 +01:00
if ( $mysoc -> tva_assuj != 'franchise' ) // Assujeti
{
print '<tr class="liste_total">' ;
if ( $modecompta == 'CREANCES-DETTES' ) 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
2004-03-04 22:26:03 +01:00
2009-02-11 22:15:47 +01:00
if ( $mysoc -> tva_assuj != 'franchise' ) // Assujeti
{
2005-04-08 01:39:47 +02:00
// Total
2009-02-11 22:15:47 +01:00
print '<tr>' ;
print '<td colspan="4"> </td>' ;
print '</tr>' ;
print '<tr class="liste_total"><td align="left" colspan="2">' . $langs -> trans ( " Profit " ) . '</td>' ;
if ( $modecompta == 'CREANCES-DETTES' ) 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> " ;
2005-04-08 01:39:47 +02:00
print '<br>' ;
2004-03-04 22:26:03 +01:00
$db -> close ();
2005-05-03 02:52:13 +02:00
llxFooter ( '$Date$ - $Revision$' );
2004-03-04 22:26:03 +01:00
?>