fix: [payroll] 급여 수정 시 요율 재계산 제거
- updatePayroll()에서 calculateAmounts() 호출 제거 - 저장된 공제 금액을 그대로 유지 (요율 변경 영향 없음) - 수동 수정(deduction_overrides)만 반영 - 총지급액/총공제액/실수령액은 재합산
This commit is contained in:
@@ -176,26 +176,55 @@ public function updatePayroll(int $id, array $data): ?Payroll
|
||||
return null;
|
||||
}
|
||||
|
||||
$mergedData = array_merge($payroll->toArray(), $data);
|
||||
$familyCount = $data['family_count'] ?? $this->resolveFamilyCount($payroll->user_id);
|
||||
$calculated = $this->calculateAmounts($mergedData, null, $familyCount);
|
||||
$this->applyDeductionOverrides($calculated, $data['deduction_overrides'] ?? null);
|
||||
// 지급 항목 (변경된 값 또는 기존값 유지)
|
||||
$baseSalary = (float) ($data['base_salary'] ?? $payroll->base_salary);
|
||||
$overtimePay = (float) ($data['overtime_pay'] ?? $payroll->overtime_pay);
|
||||
$bonus = (float) ($data['bonus'] ?? $payroll->bonus);
|
||||
$allowances = array_key_exists('allowances', $data) ? $data['allowances'] : $payroll->allowances;
|
||||
|
||||
$allowancesTotal = 0;
|
||||
$allowancesArr = is_string($allowances) ? json_decode($allowances, true) : $allowances;
|
||||
foreach ($allowancesArr ?? [] as $allowance) {
|
||||
$allowancesTotal += (float) ($allowance['amount'] ?? 0);
|
||||
}
|
||||
|
||||
$grossSalary = (int) ($baseSalary + $overtimePay + $bonus + $allowancesTotal);
|
||||
|
||||
// 공제 항목 (수동 수정값 우선, 없으면 기존 저장값 유지 — 요율 재계산 안 함)
|
||||
$overrides = $data['deduction_overrides'] ?? [];
|
||||
$incomeTax = isset($overrides['income_tax']) ? (int) $overrides['income_tax'] : $payroll->income_tax;
|
||||
$residentTax = isset($overrides['resident_tax']) ? (int) $overrides['resident_tax'] : $payroll->resident_tax;
|
||||
$healthInsurance = isset($overrides['health_insurance']) ? (int) $overrides['health_insurance'] : $payroll->health_insurance;
|
||||
$longTermCare = isset($overrides['long_term_care']) ? (int) $overrides['long_term_care'] : $payroll->long_term_care;
|
||||
$pension = isset($overrides['pension']) ? (int) $overrides['pension'] : $payroll->pension;
|
||||
$employmentInsurance = isset($overrides['employment_insurance']) ? (int) $overrides['employment_insurance'] : $payroll->employment_insurance;
|
||||
$deductions = array_key_exists('deductions', $data) ? $data['deductions'] : $payroll->deductions;
|
||||
|
||||
// 추가 공제 합계
|
||||
$extraDeductions = 0;
|
||||
$deductionsArr = is_string($deductions) ? json_decode($deductions, true) : $deductions;
|
||||
foreach ($deductionsArr ?? [] as $deduction) {
|
||||
$extraDeductions += (float) ($deduction['amount'] ?? 0);
|
||||
}
|
||||
|
||||
$totalDeductions = (int) ($incomeTax + $residentTax + $healthInsurance + $longTermCare + $pension + $employmentInsurance + $extraDeductions);
|
||||
$netSalary = (int) max(0, $grossSalary - $totalDeductions);
|
||||
|
||||
$payroll->update([
|
||||
'base_salary' => $data['base_salary'] ?? $payroll->base_salary,
|
||||
'overtime_pay' => $data['overtime_pay'] ?? $payroll->overtime_pay,
|
||||
'bonus' => $data['bonus'] ?? $payroll->bonus,
|
||||
'allowances' => array_key_exists('allowances', $data) ? $data['allowances'] : $payroll->allowances,
|
||||
'gross_salary' => $calculated['gross_salary'],
|
||||
'income_tax' => $calculated['income_tax'],
|
||||
'resident_tax' => $calculated['resident_tax'],
|
||||
'health_insurance' => $calculated['health_insurance'],
|
||||
'long_term_care' => $calculated['long_term_care'],
|
||||
'pension' => $calculated['pension'],
|
||||
'employment_insurance' => $calculated['employment_insurance'],
|
||||
'deductions' => array_key_exists('deductions', $data) ? $data['deductions'] : $payroll->deductions,
|
||||
'total_deductions' => $calculated['total_deductions'],
|
||||
'net_salary' => $calculated['net_salary'],
|
||||
'base_salary' => $baseSalary,
|
||||
'overtime_pay' => $overtimePay,
|
||||
'bonus' => $bonus,
|
||||
'allowances' => $allowances,
|
||||
'gross_salary' => $grossSalary,
|
||||
'income_tax' => $incomeTax,
|
||||
'resident_tax' => $residentTax,
|
||||
'health_insurance' => $healthInsurance,
|
||||
'long_term_care' => $longTermCare,
|
||||
'pension' => $pension,
|
||||
'employment_insurance' => $employmentInsurance,
|
||||
'deductions' => $deductions,
|
||||
'total_deductions' => $totalDeductions,
|
||||
'net_salary' => $netSalary,
|
||||
'note' => $data['note'] ?? $payroll->note,
|
||||
'updated_by' => auth()->id(),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user