docs: 가지급금 관리 Swagger 문서 추가 (LoanApi.php)

- 스키마 7개: Loan, CreateRequest, UpdateRequest, SettleRequest, Summary, InterestCalculation, InterestReport
- 엔드포인트 9개: CRUD, 요약, 정산, 인정이자 계산/리포트
- 인정이자율 4.6%, 법인세/소득세/지방소득세 자동 계산
This commit is contained in:
2025-12-18 14:40:57 +09:00
parent acb7a45a31
commit 9b3dd2f4b8

504
app/Swagger/v1/LoanApi.php Normal file
View File

@@ -0,0 +1,504 @@
<?php
namespace App\Swagger\v1;
/**
* @OA\Tag(name="Loans", description="가지급금 관리")
*
* @OA\Schema(
* schema="Loan",
* type="object",
* description="가지급금 정보",
*
* @OA\Property(property="id", type="integer", example=1, description="가지급금 ID"),
* @OA\Property(property="tenant_id", type="integer", example=1, description="테넌트 ID"),
* @OA\Property(property="user_id", type="integer", example=1, description="수령자 ID"),
* @OA\Property(property="loan_date", type="string", format="date", example="2025-01-15", description="지급일"),
* @OA\Property(property="amount", type="number", format="float", example=5000000, description="가지급금액"),
* @OA\Property(property="purpose", type="string", example="출장 경비", nullable=true, description="사용 목적"),
* @OA\Property(property="settlement_date", type="string", format="date", example="2025-02-15", nullable=true, description="정산일"),
* @OA\Property(property="settlement_amount", type="number", format="float", example=5000000, nullable=true, description="정산금액"),
* @OA\Property(property="status", type="string", enum={"outstanding","settled","partial"}, example="outstanding", description="상태 (미정산/정산완료/부분정산)"),
* @OA\Property(property="status_label", type="string", example="미정산", description="상태 레이블"),
* @OA\Property(property="outstanding_amount", type="number", format="float", example=5000000, description="미정산 잔액"),
* @OA\Property(property="elapsed_days", type="integer", example=30, description="경과일수"),
* @OA\Property(property="withdrawal_id", type="integer", example=1, nullable=true, description="연결된 출금 ID"),
* @OA\Property(property="user", type="object", nullable=true,
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="name", type="string", example="홍길동"),
* @OA\Property(property="email", type="string", example="hong@example.com"),
* description="수령자 정보"
* ),
* @OA\Property(property="withdrawal", type="object", nullable=true,
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="withdrawal_date", type="string", format="date"),
* @OA\Property(property="amount", type="number", format="float"),
* description="연결된 출금 정보"
* ),
* @OA\Property(property="creator", type="object", nullable=true,
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="name", type="string", example="관리자"),
* description="생성자 정보"
* ),
* @OA\Property(property="created_by", type="integer", example=1, nullable=true, description="생성자 ID"),
* @OA\Property(property="updated_by", type="integer", example=1, nullable=true, description="수정자 ID"),
* @OA\Property(property="created_at", type="string", format="date-time"),
* @OA\Property(property="updated_at", type="string", format="date-time")
* )
*
* @OA\Schema(
* schema="LoanCreateRequest",
* type="object",
* required={"user_id","loan_date","amount"},
* description="가지급금 등록 요청",
*
* @OA\Property(property="user_id", type="integer", example=1, description="수령자 ID"),
* @OA\Property(property="loan_date", type="string", format="date", example="2025-01-15", description="지급일"),
* @OA\Property(property="amount", type="number", format="float", example=5000000, description="가지급금액"),
* @OA\Property(property="purpose", type="string", example="출장 경비", maxLength=1000, nullable=true, description="사용 목적"),
* @OA\Property(property="withdrawal_id", type="integer", example=1, nullable=true, description="연결할 출금 ID")
* )
*
* @OA\Schema(
* schema="LoanUpdateRequest",
* type="object",
* description="가지급금 수정 요청 (미정산 상태만 수정 가능)",
*
* @OA\Property(property="user_id", type="integer", example=1, description="수령자 ID"),
* @OA\Property(property="loan_date", type="string", format="date", example="2025-01-15", description="지급일"),
* @OA\Property(property="amount", type="number", format="float", example=5000000, description="가지급금액"),
* @OA\Property(property="purpose", type="string", example="출장 경비", maxLength=1000, nullable=true, description="사용 목적"),
* @OA\Property(property="withdrawal_id", type="integer", example=1, nullable=true, description="연결할 출금 ID")
* )
*
* @OA\Schema(
* schema="LoanSettleRequest",
* type="object",
* required={"settlement_date","settlement_amount"},
* description="가지급금 정산 요청",
*
* @OA\Property(property="settlement_date", type="string", format="date", example="2025-02-15", description="정산일"),
* @OA\Property(property="settlement_amount", type="number", format="float", example=5000000, minimum=0.01, description="정산금액")
* )
*
* @OA\Schema(
* schema="LoanSummary",
* type="object",
* description="가지급금 요약",
*
* @OA\Property(property="total_count", type="integer", example=10, description="전체 건수"),
* @OA\Property(property="outstanding_count", type="integer", example=5, description="미정산 건수"),
* @OA\Property(property="settled_count", type="integer", example=3, description="정산완료 건수"),
* @OA\Property(property="partial_count", type="integer", example=2, description="부분정산 건수"),
* @OA\Property(property="total_amount", type="number", format="float", example=50000000, description="총 가지급금액"),
* @OA\Property(property="total_settled", type="number", format="float", example=30000000, description="총 정산금액"),
* @OA\Property(property="total_outstanding", type="number", format="float", example=20000000, description="총 미정산액")
* )
*
* @OA\Schema(
* schema="LoanInterestCalculation",
* type="object",
* description="인정이자 계산 결과",
*
* @OA\Property(property="year", type="integer", example=2025, description="계산 연도"),
* @OA\Property(property="interest_rate", type="number", format="float", example=4.6, description="인정이자율 (%)"),
* @OA\Property(property="base_date", type="string", format="date", example="2025-12-31", description="기준일"),
* @OA\Property(property="summary", type="object",
* @OA\Property(property="total_balance", type="number", format="float", example=50000000, description="총 미정산 잔액"),
* @OA\Property(property="total_recognized_interest", type="number", format="float", example=2300000, description="총 인정이자"),
* @OA\Property(property="total_corporate_tax", type="number", format="float", example=437000, description="법인세 추가 (19%)"),
* @OA\Property(property="total_income_tax", type="number", format="float", example=805000, description="소득세 추가 (35%)"),
* @OA\Property(property="total_local_tax", type="number", format="float", example=80500, description="지방소득세 (10%)"),
* @OA\Property(property="total_tax", type="number", format="float", example=1322500, description="총 세금"),
* description="요약"
* ),
* @OA\Property(property="details", type="array",
*
* @OA\Items(
*
* @OA\Property(property="loan_id", type="integer", example=1),
* @OA\Property(property="user", type="object",
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="name", type="string", example="홍길동"),
* @OA\Property(property="email", type="string", example="hong@example.com")
* ),
* @OA\Property(property="loan_date", type="string", format="date", example="2025-01-15"),
* @OA\Property(property="amount", type="number", format="float", example=5000000),
* @OA\Property(property="settlement_amount", type="number", format="float", example=0),
* @OA\Property(property="outstanding_amount", type="number", format="float", example=5000000),
* @OA\Property(property="elapsed_days", type="integer", example=350),
* @OA\Property(property="interest_rate", type="number", format="float", example=4.6),
* @OA\Property(property="recognized_interest", type="number", format="float", example=220548),
* @OA\Property(property="corporate_tax", type="number", format="float", example=41904),
* @OA\Property(property="income_tax", type="number", format="float", example=77192),
* @OA\Property(property="local_tax", type="number", format="float", example=7719),
* @OA\Property(property="total_tax", type="number", format="float", example=126815)
* ),
* description="상세 내역"
* )
* )
*
* @OA\Schema(
* schema="LoanInterestReport",
* type="object",
* description="연간 인정이자 리포트",
*
* @OA\Property(property="year", type="integer", example=2025, description="연도"),
* @OA\Property(property="interest_rate", type="number", format="float", example=4.6, description="인정이자율 (%)"),
* @OA\Property(property="users", type="array",
*
* @OA\Items(
*
* @OA\Property(property="user", type="object",
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="name", type="string", example="홍길동"),
* @OA\Property(property="email", type="string", example="hong@example.com")
* ),
* @OA\Property(property="loan_count", type="integer", example=3, description="가지급금 건수"),
* @OA\Property(property="total_amount", type="number", format="float", example=15000000, description="총 가지급금액"),
* @OA\Property(property="total_settled", type="number", format="float", example=5000000, description="총 정산금액"),
* @OA\Property(property="total_outstanding", type="number", format="float", example=10000000, description="총 미정산액"),
* @OA\Property(property="recognized_interest", type="number", format="float", example=460000, description="인정이자"),
* @OA\Property(property="total_tax", type="number", format="float", example=265000, description="총 세금")
* ),
* description="사용자별 내역"
* ),
* @OA\Property(property="grand_total", type="object",
* @OA\Property(property="total_amount", type="number", format="float", example=50000000),
* @OA\Property(property="total_outstanding", type="number", format="float", example=30000000),
* @OA\Property(property="recognized_interest", type="number", format="float", example=1380000),
* @OA\Property(property="total_tax", type="number", format="float", example=795000),
* description="전체 합계"
* )
* )
*/
class LoanApi
{
/**
* @OA\Get(
* path="/api/v1/loans",
* tags={"Loans"},
* summary="가지급금 목록 조회",
* description="가지급금 목록을 조회합니다.",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
*
* @OA\Parameter(name="user_id", in="query", description="수령자 ID", @OA\Schema(type="integer")),
* @OA\Parameter(name="status", in="query", description="상태", @OA\Schema(type="string", enum={"outstanding","settled","partial"})),
* @OA\Parameter(name="start_date", in="query", description="시작일 (지급일 기준)", @OA\Schema(type="string", format="date")),
* @OA\Parameter(name="end_date", in="query", description="종료일 (지급일 기준)", @OA\Schema(type="string", format="date")),
* @OA\Parameter(name="search", in="query", description="검색어 (수령자명, 목적)", @OA\Schema(type="string", maxLength=100)),
* @OA\Parameter(name="sort_by", in="query", description="정렬 기준", @OA\Schema(type="string", enum={"loan_date","amount","status","created_at"}, default="loan_date")),
* @OA\Parameter(name="sort_dir", in="query", description="정렬 방향", @OA\Schema(type="string", enum={"asc","desc"}, default="desc")),
* @OA\Parameter(ref="#/components/parameters/Page"),
* @OA\Parameter(ref="#/components/parameters/Size"),
*
* @OA\Response(
* response=200,
* description="조회 성공",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
*
* @OA\Property(
* property="data",
* type="object",
* @OA\Property(property="current_page", type="integer", example=1),
* @OA\Property(property="data", type="array", @OA\Items(ref="#/components/schemas/Loan")),
* @OA\Property(property="per_page", type="integer", example=20),
* @OA\Property(property="total", type="integer", example=30)
* )
* )
* }
* )
* ),
*
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function index() {}
/**
* @OA\Post(
* path="/api/v1/loans",
* tags={"Loans"},
* summary="가지급금 등록",
* description="새로운 가지급금을 등록합니다.",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(ref="#/components/schemas/LoanCreateRequest")
* ),
*
* @OA\Response(
* response=201,
* description="등록 성공",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
*
* @OA\Property(property="data", ref="#/components/schemas/Loan")
* )
* }
* )
* ),
*
* @OA\Response(response=400, description="잘못된 요청", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function store() {}
/**
* @OA\Get(
* path="/api/v1/loans/summary",
* tags={"Loans"},
* summary="가지급금 요약 조회",
* description="가지급금 요약 정보를 조회합니다. 특정 사용자 지정 시 해당 사용자만 집계합니다.",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
*
* @OA\Parameter(name="user_id", in="query", description="수령자 ID (미지정 시 전체)", @OA\Schema(type="integer")),
*
* @OA\Response(
* response=200,
* description="조회 성공",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
*
* @OA\Property(property="data", ref="#/components/schemas/LoanSummary")
* )
* }
* )
* ),
*
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function summary() {}
/**
* @OA\Post(
* path="/api/v1/loans/calculate-interest",
* tags={"Loans"},
* summary="인정이자 계산",
* description="미정산 가지급금에 대한 인정이자를 계산합니다. 법인세/소득세/지방소득세가 자동 계산됩니다.",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(
* required={"year"},
*
* @OA\Property(property="year", type="integer", example=2025, minimum=2000, maximum=2100, description="계산 연도"),
* @OA\Property(property="user_id", type="integer", example=1, nullable=true, description="특정 사용자 ID (미지정 시 전체)")
* )
* ),
*
* @OA\Response(
* response=200,
* description="계산 성공",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
*
* @OA\Property(property="data", ref="#/components/schemas/LoanInterestCalculation")
* )
* }
* )
* ),
*
* @OA\Response(response=400, description="잘못된 요청", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function calculateInterest() {}
/**
* @OA\Get(
* path="/api/v1/loans/interest-report/{year}",
* tags={"Loans"},
* summary="인정이자 연간 리포트",
* description="특정 연도의 인정이자 리포트를 사용자별로 조회합니다.",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
*
* @OA\Parameter(name="year", in="path", required=true, description="연도", @OA\Schema(type="integer", example=2025)),
*
* @OA\Response(
* response=200,
* description="조회 성공",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
*
* @OA\Property(property="data", ref="#/components/schemas/LoanInterestReport")
* )
* }
* )
* ),
*
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function interestReport() {}
/**
* @OA\Get(
* path="/api/v1/loans/{id}",
* tags={"Loans"},
* summary="가지급금 상세 조회",
* description="가지급금 상세 정보를 조회합니다.",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
*
* @OA\Parameter(name="id", in="path", required=true, description="가지급금 ID", @OA\Schema(type="integer")),
*
* @OA\Response(
* response=200,
* description="조회 성공",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
*
* @OA\Property(property="data", ref="#/components/schemas/Loan")
* )
* }
* )
* ),
*
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="가지급금 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function show() {}
/**
* @OA\Put(
* path="/api/v1/loans/{id}",
* tags={"Loans"},
* summary="가지급금 수정",
* description="가지급금 정보를 수정합니다. 미정산(outstanding) 상태에서만 수정 가능합니다.",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
*
* @OA\Parameter(name="id", in="path", required=true, description="가지급금 ID", @OA\Schema(type="integer")),
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(ref="#/components/schemas/LoanUpdateRequest")
* ),
*
* @OA\Response(
* response=200,
* description="수정 성공",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
*
* @OA\Property(property="data", ref="#/components/schemas/Loan")
* )
* }
* )
* ),
*
* @OA\Response(response=400, description="잘못된 요청 (정산됨/부분정산 상태)", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="가지급금 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function update() {}
/**
* @OA\Delete(
* path="/api/v1/loans/{id}",
* tags={"Loans"},
* summary="가지급금 삭제",
* description="가지급금을 삭제합니다. 미정산(outstanding) 상태에서만 삭제 가능합니다. (Soft Delete)",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
*
* @OA\Parameter(name="id", in="path", required=true, description="가지급금 ID", @OA\Schema(type="integer")),
*
* @OA\Response(
* response=200,
* description="삭제 성공",
*
* @OA\JsonContent(ref="#/components/schemas/ApiResponse")
* ),
*
* @OA\Response(response=400, description="잘못된 요청 (정산됨/부분정산 상태)", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="가지급금 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function destroy() {}
/**
* @OA\Post(
* path="/api/v1/loans/{id}/settle",
* tags={"Loans"},
* summary="가지급금 정산",
* description="가지급금을 정산합니다. 미정산(outstanding) 또는 부분정산(partial) 상태에서만 가능합니다. 부분 정산 시 누적됩니다.",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
*
* @OA\Parameter(name="id", in="path", required=true, description="가지급금 ID", @OA\Schema(type="integer")),
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(ref="#/components/schemas/LoanSettleRequest")
* ),
*
* @OA\Response(
* response=200,
* description="정산 성공",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
*
* @OA\Property(property="data", ref="#/components/schemas/Loan")
* )
* }
* )
* ),
*
* @OA\Response(response=400, description="잘못된 요청 (이미 정산 완료 또는 정산금액 초과)", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="가지급금 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function settle() {}
}