diff --git a/htdocs/compta/bank/treso.php b/htdocs/compta/bank/treso.php index af4010b27cd..d49cfc026a4 100644 --- a/htdocs/compta/bank/treso.php +++ b/htdocs/compta/bank/treso.php @@ -169,6 +169,7 @@ if ($_REQUEST["account"] || $_REQUEST["ref"]) $i = 0; while ($i < $num) { + $paiement = ''; $var=!$var; $obj = $db->fetch_object($result); @@ -181,6 +182,17 @@ if ($_REQUEST["account"] || $_REQUEST["ref"]) $facturefournstatic->id=$obj->facid; $facturefournstatic->type=$obj->type; $facture = $facturefournstatic->getNomUrl(1,''); + + // On recherche les paiements deja effectue pour les deduires + $sqlp = "SELECT sum(amount) as paiement"; + $sqlp.= " FROM ".MAIN_DB_PREFIX.'paiementfourn_facturefourn'; + $sqlp.= " WHERE fk_facturefourn = ".$obj->facid; + $resql = $db->query($sqlp); + if ($resql) + { + $objp = $db->fetch_object($resql); + if ($objp) $paiement = $objp->paiement; + } } else { @@ -188,22 +200,39 @@ if ($_REQUEST["account"] || $_REQUEST["ref"]) $facturestatic->id=$obj->facid; $facturestatic->type=$obj->type; $facture = $facturestatic->getNomUrl(1,''); + + // On recherche les paiements deja effectue pour les deduires + $sqlp = "SELECT sum(amount) as paiement"; + $sqlp.= " FROM ".MAIN_DB_PREFIX.'paiement_facture'; + $sqlp.= " WHERE fk_facture = ".$obj->facid; + $resql = $db->query($sqlp); + if ($resql) + { + $objp = $db->fetch_object($resql); + if ($objp) $paiement = $objp->paiement; + } } - $solde += $obj->total_ttc; + $total_ttc = $obj->total_ttc; + if ($paiement) $total_ttc = $obj->total_ttc - $paiement; + $solde += $total_ttc; print "