diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index 5e07fc3eb74..ffc0b8d8264 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -233,11 +233,11 @@ if ($user->comm > 0 && $conf->commercial ) * Factures impayées */ -$sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total_ttc FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1"; -if ($socidp) -{ - $sql .= " AND f.fk_soc = $socidp"; -} +$sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total_ttc, sum(pf.amount) as am"; +//$sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s "; +$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture"; +$sql .= " WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1"; +$sql .= " GROUP BY f.facnumber"; if ( $db->query($sql) ) { @@ -247,7 +247,7 @@ if ( $db->query($sql) ) if ($num) { print ''; - print ''; + print ''; $var = True; $total = 0; while ($i < $num) @@ -257,11 +257,14 @@ if ( $db->query($sql) ) print ''; print ''; - print ''; - $total += $obj->total_ttc; + print ''; + print ''; + $total += $obj->total_ttc; + $totalam += $obj->am; $i++; } - print ''; + $var=!$var; + print ''; print "
Factures impayées
Factures impayéesReçu
'.img_file().''; print ' '.$obj->facnumber.''.$obj->nom.''.price($obj->total_ttc).'
'.price($obj->total_ttc).''.price($obj->am).'
'.price($obj->total_ttc).'
Reste à encaisser : '.price($total-$totalam).''.price($total).''.price($totalam).'

"; } $db->free();