- 매출(Sale) 및 매입(Purchase) CRUD API 구현
- 문서번호 자동 생성 (SL/PU + YYYYMMDD + 시퀀스)
- 상태 관리 (draft → confirmed → invoiced)
- 확정(confirm) 및 요약(summary) 기능 추가
- BelongsToTenant, SoftDeletes 적용
- Swagger API 문서 작성 완료
추가된 파일:
- 마이그레이션: sales, purchases 테이블
- 모델: Sale, Purchase
- 서비스: SaleService, PurchaseService
- 컨트롤러: SaleController, PurchaseController
- FormRequest: Store/Update 4개
- Swagger: SaleApi.php, PurchaseApi.php
API 엔드포인트 (14개):
- GET/POST /v1/sales, /v1/purchases
- GET/PUT/DELETE /v1/{sales,purchases}/{id}
- POST /v1/{sales,purchases}/{id}/confirm
- GET /v1/{sales,purchases}/summary
337 lines
16 KiB
PHP
337 lines
16 KiB
PHP
<?php
|
|
|
|
namespace App\Swagger\v1;
|
|
|
|
/**
|
|
* @OA\Tag(name="Purchases", description="매입 관리")
|
|
*
|
|
* @OA\Schema(
|
|
* schema="Purchase",
|
|
* 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="purchase_number", type="string", example="PU202501150001", description="매입번호"),
|
|
* @OA\Property(property="purchase_date", type="string", format="date", example="2025-01-15", description="매입일"),
|
|
* @OA\Property(property="client_id", type="integer", example=1, description="거래처 ID"),
|
|
* @OA\Property(property="supply_amount", type="number", format="float", example=1000000, description="공급가액"),
|
|
* @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월 매입", 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="client", 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="created_at", type="string", format="date-time"),
|
|
* @OA\Property(property="updated_at", type="string", format="date-time")
|
|
* )
|
|
*
|
|
* @OA\Schema(
|
|
* schema="PurchaseCreateRequest",
|
|
* type="object",
|
|
* required={"purchase_date","client_id","supply_amount","tax_amount","total_amount"},
|
|
* description="매입 등록 요청",
|
|
*
|
|
* @OA\Property(property="purchase_date", type="string", format="date", example="2025-01-15", description="매입일"),
|
|
* @OA\Property(property="client_id", type="integer", example=1, description="거래처 ID"),
|
|
* @OA\Property(property="supply_amount", type="number", format="float", example=1000000, description="공급가액"),
|
|
* @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\Schema(
|
|
* schema="PurchaseUpdateRequest",
|
|
* type="object",
|
|
* description="매입 수정 요청",
|
|
*
|
|
* @OA\Property(property="purchase_date", type="string", format="date", example="2025-01-15", description="매입일"),
|
|
* @OA\Property(property="client_id", type="integer", example=1, description="거래처 ID"),
|
|
* @OA\Property(property="supply_amount", type="number", format="float", example=1000000, description="공급가액"),
|
|
* @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\Schema(
|
|
* schema="PurchaseSummary",
|
|
* type="object",
|
|
* description="매입 요약",
|
|
*
|
|
* @OA\Property(property="total_supply_amount", type="number", format="float", example=10000000, description="총 공급가액"),
|
|
* @OA\Property(property="total_tax_amount", type="number", format="float", example=1000000, description="총 세액"),
|
|
* @OA\Property(property="total_amount", type="number", format="float", example=11000000, description="총 합계"),
|
|
* @OA\Property(property="total_count", type="integer", example=10, description="총 건수"),
|
|
* @OA\Property(property="by_status", type="object", description="상태별 합계",
|
|
* @OA\Property(property="draft", type="object",
|
|
* @OA\Property(property="total", type="number", example=5500000),
|
|
* @OA\Property(property="count", type="integer", example=5)
|
|
* ),
|
|
* @OA\Property(property="confirmed", type="object",
|
|
* @OA\Property(property="total", type="number", example=5500000),
|
|
* @OA\Property(property="count", type="integer", example=5)
|
|
* )
|
|
* )
|
|
* )
|
|
*/
|
|
class PurchaseApi
|
|
{
|
|
/**
|
|
* @OA\Get(
|
|
* path="/api/v1/purchases",
|
|
* tags={"Purchases"},
|
|
* summary="매입 목록 조회",
|
|
* description="매입 목록을 조회합니다.",
|
|
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
|
*
|
|
* @OA\Parameter(name="search", in="query", description="검색어 (매입번호, 거래처명, 적요)", @OA\Schema(type="string")),
|
|
* @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="client_id", in="query", description="거래처 ID", @OA\Schema(type="integer")),
|
|
* @OA\Parameter(name="status", in="query", description="상태", @OA\Schema(type="string", enum={"draft","confirmed"})),
|
|
* @OA\Parameter(name="sort_by", in="query", description="정렬 기준", @OA\Schema(type="string", enum={"purchase_date","total_amount","created_at"}, default="purchase_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/Purchase")),
|
|
* @OA\Property(property="per_page", type="integer", example=20),
|
|
* @OA\Property(property="total", type="integer", example=50)
|
|
* )
|
|
* )
|
|
* }
|
|
* )
|
|
* ),
|
|
*
|
|
* @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/purchases",
|
|
* tags={"Purchases"},
|
|
* summary="매입 등록",
|
|
* description="새로운 매입을 등록합니다. 매입번호는 자동 생성됩니다.",
|
|
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
|
*
|
|
* @OA\RequestBody(
|
|
* required=true,
|
|
*
|
|
* @OA\JsonContent(ref="#/components/schemas/PurchaseCreateRequest")
|
|
* ),
|
|
*
|
|
* @OA\Response(
|
|
* response=201,
|
|
* description="등록 성공",
|
|
*
|
|
* @OA\JsonContent(
|
|
* allOf={
|
|
*
|
|
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
|
* @OA\Schema(
|
|
*
|
|
* @OA\Property(property="data", ref="#/components/schemas/Purchase")
|
|
* )
|
|
* }
|
|
* )
|
|
* ),
|
|
*
|
|
* @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/purchases/summary",
|
|
* tags={"Purchases"},
|
|
* summary="매입 요약 조회",
|
|
* description="기간별 매입 요약을 조회합니다.",
|
|
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
|
*
|
|
* @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="client_id", in="query", description="거래처 ID", @OA\Schema(type="integer")),
|
|
* @OA\Parameter(name="status", in="query", description="상태", @OA\Schema(type="string", enum={"draft","confirmed"})),
|
|
*
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="조회 성공",
|
|
*
|
|
* @OA\JsonContent(
|
|
* allOf={
|
|
*
|
|
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
|
* @OA\Schema(
|
|
*
|
|
* @OA\Property(property="data", ref="#/components/schemas/PurchaseSummary")
|
|
* )
|
|
* }
|
|
* )
|
|
* ),
|
|
*
|
|
* @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\Get(
|
|
* path="/api/v1/purchases/{id}",
|
|
* tags={"Purchases"},
|
|
* 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/Purchase")
|
|
* )
|
|
* }
|
|
* )
|
|
* ),
|
|
*
|
|
* @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/purchases/{id}",
|
|
* tags={"Purchases"},
|
|
* summary="매입 수정",
|
|
* description="매입 정보를 수정합니다. 임시저장(draft) 상태에서만 수정 가능합니다.",
|
|
* 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/PurchaseUpdateRequest")
|
|
* ),
|
|
*
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="수정 성공",
|
|
*
|
|
* @OA\JsonContent(
|
|
* allOf={
|
|
*
|
|
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
|
* @OA\Schema(
|
|
*
|
|
* @OA\Property(property="data", ref="#/components/schemas/Purchase")
|
|
* )
|
|
* }
|
|
* )
|
|
* ),
|
|
*
|
|
* @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/purchases/{id}",
|
|
* tags={"Purchases"},
|
|
* summary="매입 삭제",
|
|
* description="매입을 삭제합니다. 임시저장(draft) 상태에서만 삭제 가능합니다. (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/purchases/{id}/confirm",
|
|
* tags={"Purchases"},
|
|
* summary="매입 확정",
|
|
* description="매입을 확정합니다. 임시저장(draft) 상태에서만 확정 가능합니다.",
|
|
* 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/Purchase")
|
|
* )
|
|
* }
|
|
* )
|
|
* ),
|
|
*
|
|
* @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 confirm() {}
|
|
}
|