feat: 매입관리 품의서/지출결의서 연동 기능 추가

- purchases 테이블에 approval_id 컬럼 추가 (마이그레이션)
- Purchase 모델에 approval 관계 정의
- PurchaseService에서 approval 데이터 eager loading 구현
- FormRequest에 approval_id 유효성 검증 추가
- Swagger 문서에 approval 관련 스키마 추가

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-22 22:47:25 +09:00
parent 9197fe66f7
commit 7162fc2b46
6 changed files with 257 additions and 4 deletions

View File

@@ -21,11 +21,22 @@
* @OA\Property(property="description", type="string", example="1월 매입", nullable=true, description="적요"),
* @OA\Property(property="status", type="string", enum={"draft","confirmed"}, example="draft", description="상태"),
* @OA\Property(property="withdrawal_id", type="integer", example=1, nullable=true, description="출금 연결 ID"),
* @OA\Property(property="approval_id", type="integer", example=1, nullable=true, description="연결된 품의서/지출결의서 ID"),
* @OA\Property(property="client", type="object", nullable=true,
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="name", type="string", example="(주)공급사"),
* description="거래처 정보"
* ),
* @OA\Property(property="approval", type="object", nullable=true, description="연결된 품의서/지출결의서 정보",
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="document_number", type="string", example="AP202501150001"),
* @OA\Property(property="title", type="string", example="원자재 구매 품의"),
* @OA\Property(property="form", type="object", nullable=true,
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="name", type="string", example="품의서"),
* @OA\Property(property="category", type="string", example="proposal")
* )
* ),
* @OA\Property(property="created_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")
@@ -43,7 +54,8 @@
* @OA\Property(property="tax_amount", type="number", format="float", example=100000, description="세액"),
* @OA\Property(property="total_amount", type="number", format="float", example=1100000, description="합계"),
* @OA\Property(property="description", type="string", example="1월 매입", maxLength=1000, nullable=true, description="적요"),
* @OA\Property(property="withdrawal_id", type="integer", example=1, nullable=true, description="출금 연결 ID")
* @OA\Property(property="withdrawal_id", type="integer", example=1, nullable=true, description="출금 연결 ID"),
* @OA\Property(property="approval_id", type="integer", example=1, nullable=true, description="연결할 품의서/지출결의서 ID")
* )
*
* @OA\Schema(
@@ -57,7 +69,8 @@
* @OA\Property(property="tax_amount", type="number", format="float", example=100000, description="세액"),
* @OA\Property(property="total_amount", type="number", format="float", example=1100000, description="합계"),
* @OA\Property(property="description", type="string", example="1월 매입", maxLength=1000, nullable=true, description="적요"),
* @OA\Property(property="withdrawal_id", type="integer", example=1, nullable=true, description="출금 연결 ID")
* @OA\Property(property="withdrawal_id", type="integer", example=1, nullable=true, description="출금 연결 ID"),
* @OA\Property(property="approval_id", type="integer", example=1, nullable=true, description="연결할 품의서/지출결의서 ID")
* )
*
* @OA\Schema(
@@ -80,6 +93,49 @@
* )
* )
* )
*
* @OA\Schema(
* schema="PurchaseDashboardDetail",
* type="object",
* description="매입 대시보드 상세 (CEO 대시보드 모달용)",
*
* @OA\Property(property="summary", type="object", description="요약 정보",
* @OA\Property(property="current_month_total", type="number", format="float", example=305000000, description="당월 매입 합계"),
* @OA\Property(property="previous_month_total", type="number", format="float", example=276000000, description="전월 매입 합계"),
* @OA\Property(property="change_rate", type="number", format="float", example=10.5, description="전월 대비 변화율 (%)"),
* @OA\Property(property="count", type="integer", example=45, description="당월 매입 건수")
* ),
* @OA\Property(property="monthly_trend", type="array", description="월별 추이 (최근 7개월)",
*
* @OA\Items(type="object",
*
* @OA\Property(property="month", type="string", example="2026-01", description="월"),
* @OA\Property(property="amount", type="number", format="float", example=280000000, description="매입 합계")
* )
* ),
* @OA\Property(property="by_type", type="array", description="유형별 분포",
*
* @OA\Items(type="object",
*
* @OA\Property(property="type", type="string", example="raw_material", description="유형 코드"),
* @OA\Property(property="label", type="string", example="원재료매입", description="유형 라벨"),
* @OA\Property(property="amount", type="number", format="float", example=180000000, description="합계"),
* @OA\Property(property="ratio", type="number", format="float", example=59.0, description="비율 (%)")
* )
* ),
* @OA\Property(property="items", type="array", description="일별 매입 내역",
*
* @OA\Items(type="object",
*
* @OA\Property(property="id", type="integer", example=1, description="매입 ID"),
* @OA\Property(property="date", type="string", format="date", example="2026-01-15", description="매입일"),
* @OA\Property(property="vendor_name", type="string", example="대한철강", description="거래처명"),
* @OA\Property(property="amount", type="number", format="float", example=15000000, description="매입금액"),
* @OA\Property(property="type", type="string", example="raw_material", description="매입유형 코드"),
* @OA\Property(property="type_label", type="string", example="원재료매입", description="매입유형 라벨")
* )
* )
* )
*/
class PurchaseApi
{
@@ -202,6 +258,36 @@ public function store() {}
*/
public function summary() {}
/**
* @OA\Get(
* path="/api/v1/purchases/dashboard-detail",
* tags={"Purchases"},
* summary="매입 대시보드 상세 조회",
* description="CEO 대시보드 모달용 매입 상세 데이터를 조회합니다. 당월 요약, 월별 추이, 유형별 분포, 일별 내역을 반환합니다.",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
*
* @OA\Response(
* response=200,
* description="조회 성공",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
*
* @OA\Property(property="data", ref="#/components/schemas/PurchaseDashboardDetail")
* )
* }
* )
* ),
*
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function dashboardDetail() {}
/**
* @OA\Get(
* path="/api/v1/purchases/{id}",