From deface29da4c29127560ee00b8645575e1ea146a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 5 Apr 2019 15:52:30 +1100 Subject: [PATCH] , --- app/Helpers/Invoice/InvoiceCalc.php | 53 +++++++++++++++++++++++++ app/Helpers/Invoice/InvoiceItemCalc.php | 22 +++++----- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/app/Helpers/Invoice/InvoiceCalc.php b/app/Helpers/Invoice/InvoiceCalc.php index 39f287c474ef..6bf87dbb4c8c 100644 --- a/app/Helpers/Invoice/InvoiceCalc.php +++ b/app/Helpers/Invoice/InvoiceCalc.php @@ -25,6 +25,11 @@ class InvoiceCalc protected $invoice_total; + protected $tax_map; + + protected $total_taxes; + + protected $total_discount; public function __construct(Invoice $invoice, int $precision = 2) { @@ -52,7 +57,13 @@ class InvoiceCalc $new_line_items[] = $item_calc->getLineItem(); //set collection of itemised taxes + $this->setTaxMap($this->getTaxMap()->merge($item_calc->getGroupedTaxes())); + //set running total of taxes + $this->setTotalTaxes($this->getTotalTaxes() + $item_calc->getTotalTaxes()); + + //set running total of discounts + $this->setTotalDiscount($this->getTotalDiscount() + $item_calc->getTotalDiscounts()); } @@ -60,6 +71,48 @@ class InvoiceCalc } + + + + /** + * Getters and Setters + */ + + private function getTaxMap() + { + return $this->tax_map; + } + + private function setTaxMap($value) + { + $htis->tax_map = $value; + + return $this; + } + + private function getTotalDiscount() + { + return $this->total_discount; + } + + private function setTotalDiscount($value) + { + $this->total_discount = $value; + + return $this; + } + + private function getTotalTaxes() + { + return $this->total_taxes; + } + + private function setTotalTaxes($value) + { + $this->total_taxes = $value; + + return $this; + } /* private function setDiscount($amount, $discount, $is_amount_discount) { diff --git a/app/Helpers/Invoice/InvoiceItemCalc.php b/app/Helpers/Invoice/InvoiceItemCalc.php index a590829e7d0a..d17c6e10254f 100644 --- a/app/Helpers/Invoice/InvoiceItemCalc.php +++ b/app/Helpers/Invoice/InvoiceItemCalc.php @@ -109,18 +109,10 @@ class InvoiceItemCalc $group_tax[$key] = ['total' => $tax_total, 'tax_name' => $tax_name . ' ' . $tax_rate]; - $this->groupTaxes($group_tax); + $this->setGroupedTaxes($group_tax); } - private function groupTaxes($group_tax) - { - - $this->tax_collection->merge(collect($group_tax)); - - return $this; - } - /**************** * * Getters and Setters @@ -170,5 +162,17 @@ class InvoiceItemCalc return $this; } + public function getGroupedTaxes() + { + return $this->tax_collection; + } + + public function setGroupedTaxes($group_tax) + { + $this->tax_collection->merge(collect($group_tax)); + + return $this; + } + } \ No newline at end of file