From 9f1deb47b246a9d6f05b4116d250fb90dd5cc483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 21 Dec 2020 11:49:45 +0300 Subject: [PATCH] item autocomplete tax calculate issue solved. --- app/Http/Controllers/Common/Items.php | 33 ++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Common/Items.php b/app/Http/Controllers/Common/Items.php index fbbc72ef6..6024f1cbc 100644 --- a/app/Http/Controllers/Common/Items.php +++ b/app/Http/Controllers/Common/Items.php @@ -254,11 +254,42 @@ class Items extends Controller if ($items) { foreach ($items as $item) { + $item_price = ($type == 'bill') ? $item->purchase_price : $item->sale_price; $item_tax_price = 0; if ($item->taxes->count()) { + $inclusives = $compounds = []; + foreach($item->taxes as $item_tax) { - $item_tax_price += ($item->sale_price / 100) * $item_tax->tax->rate; + $tax = $item_tax->tax; + + switch ($tax->type) { + case 'inclusive': + $inclusives[] = $tax; + break; + case 'compound': + $compounds[] = $tax; + break; + case 'fixed': + $item_tax_price += $tax->rate; + break; + default: + $item_tax_amount = ($item_price / 100) * $tax->rate; + + $item_tax_price += $item_tax_amount; + break; + } + } + + if ($inclusives) { + $item_base_rate = $item_price / (1 + collect($inclusives)->sum('rate') / 100); + $item_tax_price = $item_price - $item_base_rate; + } + + if ($compounds) { + foreach ($compounds as $compound) { + $item_tax_price += ($item_tax_price / 100) * $compound->rate; + } } }