From 411f20c36097b184fc03dad71d7b27c1afff6a18 Mon Sep 17 00:00:00 2001 From: jerash Date: Tue, 31 Dec 2019 01:08:25 +0100 Subject: [PATCH 1/8] add credit notes and discounts to getListOfPayments --- htdocs/core/class/commoninvoice.class.php | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index b6381ccc7ca..fad07e2e7c3 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -336,6 +336,43 @@ 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 + 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'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; + $sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$this->id; + $sql.= ' AND (f.type = 2 OR f.type = 0 OR f.type = 3)'; // Find discount coming from credit note or excess received or credit note + } + elseif ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') + { + $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'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; + $sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$this->id; + $sql.= ' AND (f.type = 2 OR f.type = 0 OR f.type = 3)'; // Find discount coming from credit note or excess received or credit note + } + + $resql=$this->db->query($sql); + if ($resql) + { + $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++; + } + $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; } From 73e0bca359e511d6cae8c1c27b2cef28bdf390e6 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 31 Dec 2019 00:13:42 +0000 Subject: [PATCH 2/8] Fixing style errors. --- htdocs/core/class/commoninvoice.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index fad07e2e7c3..9d3538bc5fe 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -351,7 +351,7 @@ abstract class CommonInvoice extends CommonObject $sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$this->id; $sql.= ' AND (f.type = 2 OR f.type = 0 OR f.type = 3)'; // Find discount coming from credit note or excess received or credit note } - + $resql=$this->db->query($sql); if ($resql) { From c341ad5e8db97457b103d63d76d75719b6b9dab3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 31 Dec 2019 17:03:00 +0100 Subject: [PATCH 3/8] Update commoninvoice.class.php --- htdocs/core/class/commoninvoice.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 9d3538bc5fe..70200c794df 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -342,14 +342,14 @@ abstract class CommonInvoice extends CommonObject $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'; $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; $sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$this->id; - $sql.= ' AND (f.type = 2 OR f.type = 0 OR f.type = 3)'; // Find discount coming from credit note or excess received or credit note + $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) } elseif ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') { $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'; $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; $sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$this->id; - $sql.= ' AND (f.type = 2 OR f.type = 0 OR f.type = 3)'; // Find discount coming from credit note or excess received or credit note + $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); From b3373e8ba5c00aaa1a34215a7234e012adc97cc6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 31 Dec 2019 17:06:30 +0100 Subject: [PATCH 4/8] 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 From d3ec867df557d7a13f837130a724333698d19646 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 31 Dec 2019 16:07:07 +0000 Subject: [PATCH 5/8] Fixing style errors. --- htdocs/core/class/commoninvoice.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 2772330c41c..94efdea4d3e 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -336,7 +336,7 @@ 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 and deposits $sql = 0; if ($this->element == 'facture' || $this->element == 'invoice') @@ -363,11 +363,11 @@ abstract class CommonInvoice extends CommonObject 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); + 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); + else { + $retarray[]=array('amount'=>$obj->amount,'type'=>$obj->type, 'date'=>$obj->date, 'num'=>'', 'ref'=>$obj->ref); } $i++; } @@ -380,7 +380,7 @@ abstract class CommonInvoice extends CommonObject } $this->db->free($resql); } - + return $retarray; } else From a369690e16f1e5edefc4b1dcc208111711b6bce6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 31 Dec 2019 17:07:56 +0100 Subject: [PATCH 6/8] Update commoninvoice.class.php --- htdocs/core/class/commoninvoice.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 94efdea4d3e..531bf1a09ad 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -338,7 +338,7 @@ abstract class CommonInvoice extends CommonObject } //look for credit notes and discounts and deposits - $sql = 0; + $sql = ''; 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'; From 9774b05f524da296c615835790f4a519f828f916 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 31 Dec 2019 17:10:03 +0100 Subject: [PATCH 7/8] Update commoninvoice.class.php --- htdocs/core/class/commoninvoice.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 531bf1a09ad..03d0d25fcd7 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -336,7 +336,8 @@ abstract class CommonInvoice extends CommonObject $retarray[]=array('amount'=>$obj->amount,'type'=>$obj->code, 'date'=>$obj->datep, 'num'=>$obj->num, 'ref'=>$obj->ref); $i++; } - + $this->db->free($resql); + //look for credit notes and discounts and deposits $sql = ''; if ($this->element == 'facture' || $this->element == 'invoice') From 6142e42d83608cfab8c45ca604cd40d7942ca867 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 31 Dec 2019 16:10:36 +0000 Subject: [PATCH 8/8] Fixing style errors. --- htdocs/core/class/commoninvoice.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 03d0d25fcd7..9def117ef21 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -337,7 +337,7 @@ abstract class CommonInvoice extends CommonObject $i++; } $this->db->free($resql); - + //look for credit notes and discounts and deposits $sql = ''; if ($this->element == 'facture' || $this->element == 'invoice')