From ec50e6f64bc1334cecb6f7a380e0a5012bc716fb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 5 Jul 2024 14:37:21 +1000 Subject: [PATCH] Adjustments for inclusive taxes --- app/Helpers/Invoice/InvoiceSumInclusive.php | 44 ++++++++++----------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/app/Helpers/Invoice/InvoiceSumInclusive.php b/app/Helpers/Invoice/InvoiceSumInclusive.php index 35464bd22e..6df714231f 100644 --- a/app/Helpers/Invoice/InvoiceSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceSumInclusive.php @@ -74,8 +74,8 @@ class InvoiceSumInclusive { $this->calculateLineItems() ->calculateDiscount() - ->calculateCustomValues() //06-07-2024 - ->calculateInvoiceTaxes() //shuffle order of invoicetaxes/custom values to include the surcharge taxes in the tax map + ->calculateInvoiceTaxes() + ->calculateCustomValues() ->setTaxMap() ->calculateTotals() //just don't add the taxes!! ->calculateBalance() @@ -107,25 +107,26 @@ class InvoiceSumInclusive private function calculateCustomValues() { - $this->total_taxes += $this->multiInclusiveTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_tax1); + // $this->total_taxes += $this->multiInclusiveTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_tax1); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1); - $this->total_taxes += $this->multiInclusiveTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_tax2); + // $this->total_taxes += $this->multiInclusiveTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_tax2); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge2); - $this->total_taxes += $this->multiInclusiveTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_tax3); + // $this->total_taxes += $this->multiInclusiveTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_tax3); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge3); - $this->total_taxes += $this->multiInclusiveTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_tax4); + // $this->total_taxes += $this->multiInclusiveTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_tax4); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge4); + $this->total += $this->total_custom_values; + return $this; } private function calculateInvoiceTaxes() { $amount = $this->total; - nlog("taxing this amount {$amount}"); if ($this->invoice->discount > 0 && $this->invoice->is_amount_discount) { $amount = $this->formatValue(($this->sub_total - $this->invoice->discount), 2); @@ -135,24 +136,22 @@ class InvoiceSumInclusive $amount = $this->formatValue(($this->sub_total - ($this->sub_total * ($this->invoice->discount / 100))), 2); } - $amount += $this->total_custom_values; - //Handles cases where the surcharge is not taxed - // if(is_numeric($this->invoice->custom_surcharge1) && $this->invoice->custom_surcharge1 > 0 && !$this->invoice->custom_surcharge_tax1) { - // $amount += $this->invoice->custom_surcharge1; - // } + if(is_numeric($this->invoice->custom_surcharge1) && $this->invoice->custom_surcharge1 > 0 && $this->invoice->custom_surcharge_tax1) { + $amount += $this->invoice->custom_surcharge1; + } - // if(is_numeric($this->invoice->custom_surcharge2) && $this->invoice->custom_surcharge2 > 0 && !$this->invoice->custom_surcharge_tax2) { - // $amount += $this->invoice->custom_surcharge2; - // } + if(is_numeric($this->invoice->custom_surcharge2) && $this->invoice->custom_surcharge2 > 0 && $this->invoice->custom_surcharge_tax2) { + $amount += $this->invoice->custom_surcharge2; + } - // if(is_numeric($this->invoice->custom_surcharge3) && $this->invoice->custom_surcharge3 > 0 && !$this->invoice->custom_surcharge_tax3) { - // $amount += $this->invoice->custom_surcharge3; - // } + if(is_numeric($this->invoice->custom_surcharge3) && $this->invoice->custom_surcharge3 > 0 && $this->invoice->custom_surcharge_tax3) { + $amount += $this->invoice->custom_surcharge3; + } - // if(is_numeric($this->invoice->custom_surcharge4) && $this->invoice->custom_surcharge4 > 0 && !$this->invoice->custom_surcharge_tax4) { - // $amount += $this->invoice->custom_surcharge4; - // } + if(is_numeric($this->invoice->custom_surcharge4) && $this->invoice->custom_surcharge4 > 0 && $this->invoice->custom_surcharge_tax4) { + $amount += $this->invoice->custom_surcharge4; + } if (is_string($this->invoice->tax_name1) && strlen($this->invoice->tax_name1) > 1) { $tax = $this->calcInclusiveLineTax($this->invoice->tax_rate1, $amount); @@ -173,8 +172,6 @@ class InvoiceSumInclusive $this->total_tax_map[] = ['name' => $this->invoice->tax_name3.' '.floatval($this->invoice->tax_rate3).'%', 'total' => $tax]; } - $this->total += $this->total_custom_values; //06-07-2024 add the custom surcharge totals here after the tax calculations. - return $this; } @@ -398,5 +395,4 @@ class InvoiceSumInclusive { return $this; } - }