2025-12-18 10:56:16 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
|
|
feat: 구독/결제 API 확장 (Plan, Subscription, Payment)
- Plan/Subscription/Payment 모델에 상태 상수, 스코프, 헬퍼 메서드 추가
- PlanService, SubscriptionService, PaymentService 생성
- PlanController, SubscriptionController, PaymentController 생성
- FormRequest 9개 생성 (Plan 3개, Subscription 3개, Payment 3개)
- Swagger 문서 3개 생성 (PlanApi, SubscriptionApi, PaymentApi)
- API 라우트 22개 등록 (Plan 7개, Subscription 8개, Payment 7개)
- Pint 코드 스타일 정리
2025-12-18 16:20:29 +09:00
|
|
|
use App\Helpers\ApiResponse;
|
2025-12-18 10:56:16 +09:00
|
|
|
use App\Http\Controllers\Controller;
|
2026-03-12 15:20:20 +09:00
|
|
|
use App\Http\Requests\V1\Payroll\BulkGeneratePayrollRequest;
|
2025-12-18 10:56:16 +09:00
|
|
|
use App\Http\Requests\V1\Payroll\CalculatePayrollRequest;
|
2026-03-12 15:20:20 +09:00
|
|
|
use App\Http\Requests\V1\Payroll\CopyFromPreviousPayrollRequest;
|
2025-12-18 10:56:16 +09:00
|
|
|
use App\Http\Requests\V1\Payroll\PayPayrollRequest;
|
2026-03-12 15:20:20 +09:00
|
|
|
use App\Http\Requests\V1\Payroll\StorePayrollJournalRequest;
|
2025-12-18 10:56:16 +09:00
|
|
|
use App\Http\Requests\V1\Payroll\StorePayrollRequest;
|
|
|
|
|
use App\Http\Requests\V1\Payroll\UpdatePayrollRequest;
|
|
|
|
|
use App\Http\Requests\V1\Payroll\UpdatePayrollSettingRequest;
|
2026-03-12 15:20:20 +09:00
|
|
|
use App\Services\ExportService;
|
2025-12-18 10:56:16 +09:00
|
|
|
use App\Services\PayrollService;
|
|
|
|
|
use Illuminate\Http\Request;
|
2026-03-12 15:20:20 +09:00
|
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
2025-12-18 10:56:16 +09:00
|
|
|
|
|
|
|
|
class PayrollController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
2026-03-12 15:20:20 +09:00
|
|
|
private readonly PayrollService $service,
|
|
|
|
|
private readonly ExportService $exportService
|
2025-12-18 10:56:16 +09:00
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 급여 목록
|
|
|
|
|
*/
|
|
|
|
|
public function index(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$params = $request->only([
|
|
|
|
|
'year',
|
|
|
|
|
'month',
|
|
|
|
|
'user_id',
|
|
|
|
|
'status',
|
2026-03-12 15:20:20 +09:00
|
|
|
'department_id',
|
2025-12-18 10:56:16 +09:00
|
|
|
'search',
|
|
|
|
|
'sort_by',
|
|
|
|
|
'sort_dir',
|
|
|
|
|
'per_page',
|
|
|
|
|
'page',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$payrolls = $this->service->index($params);
|
|
|
|
|
|
2025-12-18 15:42:46 +09:00
|
|
|
return ApiResponse::success($payrolls, __('message.fetched'));
|
2025-12-18 10:56:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 특정 연월 급여 요약
|
|
|
|
|
*/
|
|
|
|
|
public function summary(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$year = (int) $request->input('year', date('Y'));
|
|
|
|
|
$month = (int) $request->input('month', date('n'));
|
|
|
|
|
|
|
|
|
|
$summary = $this->service->summary($year, $month);
|
|
|
|
|
|
2025-12-18 15:42:46 +09:00
|
|
|
return ApiResponse::success($summary, __('message.fetched'));
|
2025-12-18 10:56:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 급여 등록
|
|
|
|
|
*/
|
|
|
|
|
public function store(StorePayrollRequest $request)
|
|
|
|
|
{
|
|
|
|
|
$payroll = $this->service->store($request->validated());
|
|
|
|
|
|
2025-12-18 15:42:46 +09:00
|
|
|
return ApiResponse::success($payroll, __('message.created'), [], 201);
|
2025-12-18 10:56:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 급여 상세
|
|
|
|
|
*/
|
|
|
|
|
public function show(int $id)
|
|
|
|
|
{
|
|
|
|
|
$payroll = $this->service->show($id);
|
|
|
|
|
|
2025-12-18 15:42:46 +09:00
|
|
|
return ApiResponse::success($payroll, __('message.fetched'));
|
2025-12-18 10:56:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 급여 수정
|
|
|
|
|
*/
|
|
|
|
|
public function update(int $id, UpdatePayrollRequest $request)
|
|
|
|
|
{
|
|
|
|
|
$payroll = $this->service->update($id, $request->validated());
|
|
|
|
|
|
2025-12-18 15:42:46 +09:00
|
|
|
return ApiResponse::success($payroll, __('message.updated'));
|
2025-12-18 10:56:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 급여 삭제
|
|
|
|
|
*/
|
|
|
|
|
public function destroy(int $id)
|
|
|
|
|
{
|
|
|
|
|
$this->service->destroy($id);
|
|
|
|
|
|
2025-12-18 15:42:46 +09:00
|
|
|
return ApiResponse::success(null, __('message.deleted'));
|
2025-12-18 10:56:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 급여 확정
|
|
|
|
|
*/
|
|
|
|
|
public function confirm(int $id)
|
|
|
|
|
{
|
|
|
|
|
$payroll = $this->service->confirm($id);
|
|
|
|
|
|
2025-12-18 15:42:46 +09:00
|
|
|
return ApiResponse::success($payroll, __('message.payroll.confirmed'));
|
2025-12-18 10:56:16 +09:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 15:20:20 +09:00
|
|
|
/**
|
|
|
|
|
* 급여 확정 취소
|
|
|
|
|
*/
|
|
|
|
|
public function unconfirm(int $id)
|
|
|
|
|
{
|
|
|
|
|
$payroll = $this->service->unconfirm($id);
|
|
|
|
|
|
|
|
|
|
return ApiResponse::success($payroll, __('message.payroll.unconfirmed'));
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-18 10:56:16 +09:00
|
|
|
/**
|
|
|
|
|
* 급여 지급 처리
|
|
|
|
|
*/
|
|
|
|
|
public function pay(int $id, PayPayrollRequest $request)
|
|
|
|
|
{
|
|
|
|
|
$payroll = $this->service->pay($id, $request->input('withdrawal_id'));
|
|
|
|
|
|
2025-12-18 15:42:46 +09:00
|
|
|
return ApiResponse::success($payroll, __('message.payroll.paid'));
|
2025-12-18 10:56:16 +09:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 15:20:20 +09:00
|
|
|
/**
|
|
|
|
|
* 급여 지급 취소 (슈퍼관리자)
|
|
|
|
|
*/
|
|
|
|
|
public function unpay(int $id)
|
|
|
|
|
{
|
|
|
|
|
$payroll = $this->service->unpay($id);
|
|
|
|
|
|
|
|
|
|
return ApiResponse::success($payroll, __('message.payroll.unpaid'));
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-18 10:56:16 +09:00
|
|
|
/**
|
|
|
|
|
* 일괄 확정
|
|
|
|
|
*/
|
|
|
|
|
public function bulkConfirm(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$year = (int) $request->input('year', date('Y'));
|
|
|
|
|
$month = (int) $request->input('month', date('n'));
|
|
|
|
|
|
|
|
|
|
$count = $this->service->bulkConfirm($year, $month);
|
|
|
|
|
|
2025-12-18 15:42:46 +09:00
|
|
|
return ApiResponse::success(['count' => $count], __('message.payroll.bulk_confirmed'));
|
2025-12-18 10:56:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-03-12 15:20:20 +09:00
|
|
|
* 재직사원 일괄 생성
|
2025-12-18 10:56:16 +09:00
|
|
|
*/
|
2026-03-12 15:20:20 +09:00
|
|
|
public function bulkGenerate(BulkGeneratePayrollRequest $request)
|
2025-12-18 10:56:16 +09:00
|
|
|
{
|
2026-03-12 15:20:20 +09:00
|
|
|
$year = (int) $request->input('year');
|
|
|
|
|
$month = (int) $request->input('month');
|
2025-12-18 10:56:16 +09:00
|
|
|
|
2026-03-12 15:20:20 +09:00
|
|
|
$result = $this->service->bulkGenerate($year, $month);
|
|
|
|
|
|
|
|
|
|
return ApiResponse::success($result, __('message.payroll.bulk_generated'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 전월 급여 복사
|
|
|
|
|
*/
|
|
|
|
|
public function copyFromPrevious(CopyFromPreviousPayrollRequest $request)
|
|
|
|
|
{
|
|
|
|
|
$year = (int) $request->input('year');
|
|
|
|
|
$month = (int) $request->input('month');
|
|
|
|
|
|
|
|
|
|
$result = $this->service->copyFromPreviousMonth($year, $month);
|
|
|
|
|
|
|
|
|
|
return ApiResponse::success($result, __('message.payroll.copied'));
|
2025-12-18 10:56:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 급여 일괄 계산
|
|
|
|
|
*/
|
|
|
|
|
public function calculate(CalculatePayrollRequest $request)
|
|
|
|
|
{
|
|
|
|
|
$year = (int) $request->input('year');
|
|
|
|
|
$month = (int) $request->input('month');
|
|
|
|
|
$userIds = $request->input('user_ids');
|
|
|
|
|
|
|
|
|
|
$payrolls = $this->service->calculate($year, $month, $userIds);
|
|
|
|
|
|
2025-12-18 15:42:46 +09:00
|
|
|
return ApiResponse::success($payrolls, __('message.payroll.calculated'));
|
2025-12-18 10:56:16 +09:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 15:20:20 +09:00
|
|
|
/**
|
|
|
|
|
* 급여 계산 미리보기
|
|
|
|
|
*/
|
|
|
|
|
public function calculatePreview(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$data = $request->only([
|
|
|
|
|
'user_id',
|
|
|
|
|
'base_salary',
|
|
|
|
|
'overtime_pay',
|
|
|
|
|
'bonus',
|
|
|
|
|
'allowances',
|
|
|
|
|
'deductions',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$result = $this->service->calculatePreview($data);
|
|
|
|
|
|
|
|
|
|
return ApiResponse::success($result, __('message.calculated'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 급여명세서 조회
|
|
|
|
|
*/
|
|
|
|
|
public function payslip(int $id)
|
|
|
|
|
{
|
|
|
|
|
$payslip = $this->service->payslip($id);
|
|
|
|
|
|
|
|
|
|
return ApiResponse::success($payslip, __('message.fetched'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 급여 엑셀 내보내기
|
|
|
|
|
*/
|
|
|
|
|
public function export(Request $request): BinaryFileResponse
|
|
|
|
|
{
|
|
|
|
|
$params = $request->only([
|
|
|
|
|
'year',
|
|
|
|
|
'month',
|
|
|
|
|
'status',
|
|
|
|
|
'user_id',
|
|
|
|
|
'department_id',
|
|
|
|
|
'search',
|
|
|
|
|
'sort_by',
|
|
|
|
|
'sort_dir',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$exportData = $this->service->getExportData($params);
|
|
|
|
|
$filename = '급여현황_'.date('Ymd_His');
|
|
|
|
|
|
|
|
|
|
return $this->exportService->download(
|
|
|
|
|
$exportData['data'],
|
|
|
|
|
$exportData['headings'],
|
|
|
|
|
$filename,
|
|
|
|
|
'급여현황'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 급여 전표 생성
|
|
|
|
|
*/
|
|
|
|
|
public function journalEntries(StorePayrollJournalRequest $request)
|
|
|
|
|
{
|
|
|
|
|
$year = (int) $request->input('year');
|
|
|
|
|
$month = (int) $request->input('month');
|
|
|
|
|
$entryDate = $request->input('entry_date');
|
|
|
|
|
|
|
|
|
|
$entry = $this->service->createJournalEntries($year, $month, $entryDate);
|
|
|
|
|
|
|
|
|
|
return ApiResponse::success($entry, __('message.payroll.journal_created'));
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-18 10:56:16 +09:00
|
|
|
/**
|
|
|
|
|
* 급여 설정 조회
|
|
|
|
|
*/
|
|
|
|
|
public function getSettings()
|
|
|
|
|
{
|
|
|
|
|
$settings = $this->service->getSettings();
|
|
|
|
|
|
2025-12-18 15:42:46 +09:00
|
|
|
return ApiResponse::success($settings, __('message.fetched'));
|
2025-12-18 10:56:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 급여 설정 수정
|
|
|
|
|
*/
|
|
|
|
|
public function updateSettings(UpdatePayrollSettingRequest $request)
|
|
|
|
|
{
|
|
|
|
|
$settings = $this->service->updateSettings($request->validated());
|
|
|
|
|
|
2025-12-18 15:42:46 +09:00
|
|
|
return ApiResponse::success($settings, __('message.updated'));
|
2025-12-18 10:56:16 +09:00
|
|
|
}
|
|
|
|
|
}
|