fix(salaries): display auto bracket statutory contributions in employee salaries components column
This commit is contained in:
@@ -154,8 +154,10 @@ class EmployeeSalaryController extends Controller
|
||||
|
||||
$employeeSalaries = $query->paginate($request->per_page ?? 10);
|
||||
|
||||
$activeBrackets = \App\Models\StatutoryBracket::where('is_active', true)->get();
|
||||
|
||||
// Load component names and types for each salary record
|
||||
$employeeSalaries->getCollection()->transform(function ($salary) {
|
||||
$employeeSalaries->getCollection()->transform(function ($salary) use ($activeBrackets) {
|
||||
if ($salary->components) {
|
||||
$components = SalaryComponent::whereIn('id', $salary->components)
|
||||
->get(['id', 'name', 'type']);
|
||||
@@ -165,6 +167,48 @@ class EmployeeSalaryController extends Controller
|
||||
$salary->component_names = [];
|
||||
$salary->component_types = [];
|
||||
}
|
||||
|
||||
$grossMonthly = (float) ($salary->basic_salary ?? 0);
|
||||
if ($salary->pay_frequency === 'daily') {
|
||||
$grossMonthly = $grossMonthly * 26;
|
||||
}
|
||||
|
||||
$computeContribution = function ($type, $fixedValue) use ($activeBrackets, $grossMonthly) {
|
||||
if (!is_null($fixedValue)) {
|
||||
return null;
|
||||
}
|
||||
if ($grossMonthly <= 0) {
|
||||
return null;
|
||||
}
|
||||
$bracket = $activeBrackets->where('type', $type)
|
||||
->filter(function ($b) use ($grossMonthly) {
|
||||
$minOk = (float)$b->min_salary <= $grossMonthly;
|
||||
$maxOk = is_null($b->max_salary) || (float)$b->max_salary >= $grossMonthly;
|
||||
return $minOk && $maxOk;
|
||||
})
|
||||
->first();
|
||||
|
||||
if (!$bracket) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ee = !is_null($bracket->employee_share_amount)
|
||||
? (float) $bracket->employee_share_amount
|
||||
: ($grossMonthly * ((float) $bracket->employee_share_percentage / 100));
|
||||
|
||||
if ($type === 'sss' && is_null($bracket->employee_share_amount)) {
|
||||
$msc = min(floor($grossMonthly / 500) * 500, 30000);
|
||||
$msc = max(4000, $msc);
|
||||
$ee = $msc * ((float) $bracket->employee_share_percentage / 100);
|
||||
}
|
||||
|
||||
return round($ee, 2);
|
||||
};
|
||||
|
||||
$salary->sss_computed = $computeContribution('sss', $salary->sss_fixed);
|
||||
$salary->philhealth_computed = $computeContribution('philhealth', $salary->philhealth_fixed);
|
||||
$salary->pagibig_computed = $computeContribution('pagibig', $salary->pagibig_fixed);
|
||||
|
||||
if ($salary->employee) {
|
||||
$rawAvatar = $salary->employee->getRawOriginal('avatar');
|
||||
$salary->employee->avatar = check_file($rawAvatar)
|
||||
|
||||
Reference in New Issue
Block a user