Skip to content

Commit

Permalink
fix: min tax
Browse files Browse the repository at this point in the history
  • Loading branch information
itsemon245 committed May 2, 2024
1 parent 8fad33a commit 053deeb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions app/Http/Controllers/Frontend/TaxCalculatorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ public function calculate(Request $request)
$income = (int) $request->yearly_income;
$turnover = (int) $request->yearly_turnover;
$asset = (int) $request->total_asset;
$incomeTax = $this->calcTax($income, $request, 'income');
$turnoverTax = $this->calcTax($turnover, $request, 'turnover');
$incomeTaxAll = $this->calcTax($income, $request, 'income');
$turnoverTaxAll = $this->calcTax($turnover, $request, 'turnover');
$incomeTax = $incomeTaxAll['tax'];
$turnoverTax = $turnoverTaxAll['tax'];
$minTaxApplied = $incomeTax > $turnoverTax ? $incomeTaxAll['min-tax-applied'] : $turnoverTaxAll['min-tax-applied'];
$assetPercentage = $this->calcTax($asset, $request, 'asset');

$assetTax = ($incomeTax > $turnoverTax) ? $incomeTax * ($assetPercentage / 100) : $turnoverTax * ($assetPercentage / 100);
Expand All @@ -61,7 +64,7 @@ public function calculate(Request $request)
'taxes' => [
'a) Tax On Turnover' => currencyFormat($turnoverTax),
'b) Tax On Income' => currencyFormat($incomeTax),
'*Tax Paid a or b which is higher' => currencyFormat($tax),
'*Tax Paid a or b which is higher'.($minTaxApplied && '<br>Min. Tax Applied') => currencyFormat($tax),
],
'add' => [
'WealthTax' => currencyFormat($assetTax),
Expand Down Expand Up @@ -140,7 +143,7 @@ public function result($id)
* @param integer $value
* @param \Illuminate\Http\Request $request
* @param string $type
* @return integer
* @return mixed
*/
public function calcTax(int $value, $request, string $type): int
{
Expand Down Expand Up @@ -177,6 +180,7 @@ public function calcTax(int $value, $request, string $type): int
$slotLimit = $lastValueSlot?->to ?? 0;
$slots = $taxSetting->slots()->where('type', $type)->where('to', '<=', $slotLimit)->get();
$value = $afterFree;
$minTaxApplied = false;
if ($for == 'company') {
$totalTax = $value > $minTax ? $value * $taxSetting[$type.'_percentage'] / 100 : $minTax;
} elseif ($slots->count() > 0) {
Expand All @@ -191,14 +195,18 @@ public function calcTax(int $value, $request, string $type): int
$amountForTax = $slot->difference < $value ? $slot->difference : $value;
$tax = $amountForTax * ($slot->tax_percentage / 100);
$tax = $minTax > $tax ? $minTax : $tax;
$minTaxApplied = $minTax > $tax;
$value -= $amountForTax;
$totalTax += $tax;
if ($value <= 0) {
break;
}
}
}
return $totalTax;
return [
'tax' => $totalTax,
'min-tax-applied' => $minTaxApplied
];
}

public function calcOthers(int $value, $request, string $type)
Expand Down

0 comments on commit 053deeb

Please sign in to comment.