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 '
| Factures impayées | |||
| Factures impayées | Reçu | ||
| '.img_file().''; print ' '.$obj->facnumber.' | '; print ''.$obj->nom.' | '; - print ''.price($obj->total_ttc).' | '.price($obj->total_ttc).' | '; + print ''.price($obj->am).' | '; + $total += $obj->total_ttc; + $totalam += $obj->am; $i++; } - print '
| '.price($obj->total_ttc).' | |||
| Reste à encaisser : '.price($total-$totalam).' | '.price($total).' | '.price($totalam).' | |