43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\Accounting\Services;
|
|
|
|
use Modules\Accounting\Entities\AccountingPayrollTaxBracket;
|
|
|
|
class PayrollTaxTableService
|
|
{
|
|
public function store(array $data, int $businessId): AccountingPayrollTaxBracket
|
|
{
|
|
return AccountingPayrollTaxBracket::create(array_merge($data, [
|
|
'business_id' => $businessId,
|
|
]));
|
|
}
|
|
|
|
public function update(AccountingPayrollTaxBracket $bracket, array $data): AccountingPayrollTaxBracket
|
|
{
|
|
$bracket->update($data);
|
|
|
|
return $bracket;
|
|
}
|
|
|
|
public function calculateTax(int $businessId, float $taxableIncome): float
|
|
{
|
|
$brackets = AccountingPayrollTaxBracket::where('business_id', $businessId)
|
|
->where('is_active', true)
|
|
->orderBy('sort_order')
|
|
->orderBy('min_amount')
|
|
->get();
|
|
|
|
foreach ($brackets as $bracket) {
|
|
$min = (float) $bracket->min_amount;
|
|
$max = $bracket->max_amount !== null ? (float) $bracket->max_amount : PHP_FLOAT_MAX;
|
|
|
|
if ($taxableIncome >= $min && $taxableIncome <= $max) {
|
|
return round(((float) $bracket->fixed_deduction) + ($taxableIncome * ((float) $bracket->rate_percent / 100)), 4);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|