From b3373e8ba5c00aaa1a34215a7234e012adc97cc6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 31 Dec 2019 17:06:30 +0100 Subject: [PATCH] Update commoninvoice.class.php --- htdocs/core/class/commoninvoice.class.php | 45 +++++++++++++---------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 70200c794df..2772330c41c 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -336,7 +336,9 @@ abstract class CommonInvoice extends CommonObject $retarray[]=array('amount'=>$obj->amount,'type'=>$obj->code, 'date'=>$obj->datep, 'num'=>$obj->num, 'ref'=>$obj->ref); $i++; } - //look for credit notes and discounts + + //look for credit notes and discounts and deposits + $sql = 0; if ($this->element == 'facture' || $this->element == 'invoice') { $sql = 'SELECT rc.amount_ttc as amount, rc.multicurrency_amount_ttc as multicurrency_amount, rc.datec as date, f.ref as ref, rc.description as type'; @@ -352,28 +354,33 @@ abstract class CommonInvoice extends CommonObject $sql.= ' AND (f.type = 2 OR f.type = 0 OR f.type = 3)'; // Find discount coming from credit note or excess received or deposits (payments from deposits are always null except if FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is set) } - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i=0; - while ($i < $num) + if ($sql) { + $resql=$this->db->query($sql); + if ($resql) { - $obj = $this->db->fetch_object($resql); - if ($multicurrency) { $retarray[]=array('amount'=>$obj->multicurrency_amount,'type'=>$obj->type, 'date'=>$obj->date, 'num'=>'0', 'ref'=>$obj->ref); } - else { $retarray[]=array('amount'=>$obj->amount,'type'=>$obj->type, 'date'=>$obj->date, 'num'=>'', 'ref'=>$obj->ref); } - $i++; + $num = $this->db->num_rows($resql); + $i=0; + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + if ($multicurrency) { + $retarray[]=array('amount'=>$obj->multicurrency_amount,'type'=>$obj->type, 'date'=>$obj->date, 'num'=>'0', 'ref'=>$obj->ref); + } + else { + $retarray[]=array('amount'=>$obj->amount,'type'=>$obj->type, 'date'=>$obj->date, 'num'=>'', 'ref'=>$obj->ref); + } + $i++; + } + } + else + { + $this->error = $this->db->lasterror(); + dol_print_error($this->db); + return array(); } $this->db->free($resql); - return $retarray; } - else - { - $this->error = $this->db->lasterror(); - dol_print_error($this->db); - return array(); - } - $this->db->free($resql); + return $retarray; } else