feat: [payroll] 전월 급여 복사 등록 기능 추가
- PayrollService에 copyFromPreviousMonth() 메서드 추가 - PayrollController에 copyFromPrevious() 액션 추가 - 전월 지급/공제 금액을 그대로 복사 (요율 재계산 없음) - 이미 존재하는 사원/연월은 스킵 처리
This commit is contained in:
@@ -271,6 +271,45 @@ public function pay(Request $request, int $id): JsonResponse
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 전월 급여 복사 등록
|
||||
*/
|
||||
public function copyFromPrevious(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'pay_year' => 'required|integer|min:2020|max:2100',
|
||||
'pay_month' => 'required|integer|min:1|max:12',
|
||||
]);
|
||||
|
||||
try {
|
||||
$result = $this->payrollService->copyFromPreviousMonth($validated['pay_year'], $validated['pay_month']);
|
||||
|
||||
if (! empty($result['no_previous'])) {
|
||||
$prevYear = $validated['pay_month'] === 1 ? $validated['pay_year'] - 1 : $validated['pay_year'];
|
||||
$prevMonth = $validated['pay_month'] === 1 ? 12 : $validated['pay_month'] - 1;
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "{$prevYear}년 {$prevMonth}월 급여 데이터가 없습니다.",
|
||||
], 422);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "전월 복사 완료: {$result['created']}건 생성, {$result['skipped']}건 건너뜀 (이미 존재).",
|
||||
'data' => $result,
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '전월 복사 중 오류가 발생했습니다.',
|
||||
'error' => config('app.debug') ? $e->getMessage() : null,
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 일괄 생성
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user