Fix : customer outstanding was not calculated properly

This commit is contained in:
Maxime Kohlhaas 2015-04-18 18:06:27 +02:00
parent e0af2feced
commit 8b307aac56

View File

@ -3091,7 +3091,7 @@ class Societe extends CommonObject
$alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
$remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
*/
$sql = "SELECT sum(total) as amount FROM ".MAIN_DB_PREFIX."facture as f";
$sql = "SELECT rowid, total_ttc FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= " WHERE fk_soc = ". $this->id;
$sql .= " AND paye = 0";
$sql .= " AND fk_statut <> 0"; // Not a draft
@ -3102,8 +3102,17 @@ class Societe extends CommonObject
$resql=$this->db->query($sql);
if ($resql)
{
$obj=$this->db->fetch_object($resql);
return ($obj->amount);
$outstandingBill = 0;
$facturestatic=new Facture($this->db);
while($obj=$this->db->fetch_object($resql)) {
$facturestatic->id=$obj->rowid;
$paiement = $facturestatic->getSommePaiement();
$creditnotes = $facturestatic->getSumCreditNotesUsed();
$deposits = $facturestatic->getSumDepositsUsed();
$outstandingBill+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
}
return $outstandingBill;
}
else
return 0;