feat: 가지급금 관리 API 구현

- loans 테이블 마이그레이션 추가
- Loan 모델 (인정이자 계산, 세금 계산 로직)
- LoanService (CRUD, 정산, 인정이자 계산/리포트)
- LoanController, FormRequest 5개
- 9개 API 라우트 등록
- i18n 키 추가 (validation)
This commit is contained in:
2025-12-18 14:27:10 +09:00
parent 8b30a555d2
commit af833194ea
11 changed files with 1065 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Http\Requests\Loan;
use Illuminate\Foundation\Http\FormRequest;
class LoanCalculateInterestRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'year' => ['required', 'integer', 'min:2000', 'max:2100'],
'user_id' => ['nullable', 'integer', 'exists:users,id'],
];
}
/**
* Get the validation attribute names.
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'year' => __('validation.attributes.year'),
'user_id' => __('validation.attributes.user_id'),
];
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Http\Requests\Loan;
use App\Models\Tenants\Loan;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class LoanIndexRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'user_id' => ['nullable', 'integer', 'exists:users,id'],
'status' => ['nullable', 'string', Rule::in(Loan::STATUSES)],
'start_date' => ['nullable', 'date', 'date_format:Y-m-d'],
'end_date' => ['nullable', 'date', 'date_format:Y-m-d', 'after_or_equal:start_date'],
'search' => ['nullable', 'string', 'max:100'],
'sort_by' => ['nullable', 'string', Rule::in(['loan_date', 'amount', 'status', 'created_at'])],
'sort_dir' => ['nullable', 'string', Rule::in(['asc', 'desc'])],
'per_page' => ['nullable', 'integer', 'min:1', 'max:100'],
];
}
/**
* Get the validation attribute names.
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'user_id' => __('validation.attributes.user_id'),
'status' => __('validation.attributes.status'),
'start_date' => __('validation.attributes.start_date'),
'end_date' => __('validation.attributes.end_date'),
'search' => __('validation.attributes.search'),
'sort_by' => __('validation.attributes.sort_by'),
'sort_dir' => __('validation.attributes.sort_dir'),
'per_page' => __('validation.attributes.per_page'),
];
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Http\Requests\Loan;
use Illuminate\Foundation\Http\FormRequest;
class LoanSettleRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'settlement_date' => ['required', 'date', 'date_format:Y-m-d'],
'settlement_amount' => ['required', 'numeric', 'min:0.01', 'max:999999999999.99'],
];
}
/**
* Get the validation attribute names.
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'settlement_date' => __('validation.attributes.settlement_date'),
'settlement_amount' => __('validation.attributes.settlement_amount'),
];
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Http\Requests\Loan;
use Illuminate\Foundation\Http\FormRequest;
class LoanStoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'user_id' => ['required', 'integer', 'exists:users,id'],
'loan_date' => ['required', 'date', 'date_format:Y-m-d'],
'amount' => ['required', 'numeric', 'min:0', 'max:999999999999.99'],
'purpose' => ['nullable', 'string', 'max:1000'],
'withdrawal_id' => ['nullable', 'integer', 'exists:withdrawals,id'],
];
}
/**
* Get the validation attribute names.
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'user_id' => __('validation.attributes.user_id'),
'loan_date' => __('validation.attributes.loan_date'),
'amount' => __('validation.attributes.amount'),
'purpose' => __('validation.attributes.purpose'),
'withdrawal_id' => __('validation.attributes.withdrawal_id'),
];
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Http\Requests\Loan;
use Illuminate\Foundation\Http\FormRequest;
class LoanUpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'user_id' => ['sometimes', 'integer', 'exists:users,id'],
'loan_date' => ['sometimes', 'date', 'date_format:Y-m-d'],
'amount' => ['sometimes', 'numeric', 'min:0', 'max:999999999999.99'],
'purpose' => ['nullable', 'string', 'max:1000'],
'withdrawal_id' => ['nullable', 'integer', 'exists:withdrawals,id'],
];
}
/**
* Get the validation attribute names.
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'user_id' => __('validation.attributes.user_id'),
'loan_date' => __('validation.attributes.loan_date'),
'amount' => __('validation.attributes.amount'),
'purpose' => __('validation.attributes.purpose'),
'withdrawal_id' => __('validation.attributes.withdrawal_id'),
];
}
}