$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; } }