feat: [quote] 견적 API Phase 2-3 완료 (Service + Controller Layer)

Phase 2 - Service Layer:
- QuoteService: 견적 CRUD + 상태관리 (확정/전환)
- QuoteNumberService: 견적번호 채번 (KD-{PREFIX}-YYMMDD-SEQ)
- FormulaEvaluatorService: 수식 평가 엔진 (SUM, IF, ROUND 등)
- QuoteCalculationService: 자동산출 (스크린/철재 제품)
- QuoteDocumentService: PDF 생성 및 이메일/카카오 발송

Phase 3 - Controller Layer:
- QuoteController: 16개 엔드포인트
- FormRequest 7개: Index, Store, Update, BulkDelete, Calculate, SendEmail, SendKakao
- QuoteApi.php: Swagger 문서 (12개 스키마, 16개 엔드포인트)
- routes/api.php: 16개 라우트 등록

i18n 키 추가:
- error.php: quote_not_found, formula_* 등
- message.php: quote.* 성공 메시지
This commit is contained in:
2025-12-04 22:03:40 +09:00
parent d164bb4c4a
commit 40ca8b8697
18 changed files with 3264 additions and 3 deletions

View File

@@ -0,0 +1,196 @@
<?php
namespace App\Http\Controllers\Api\V1;
use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\Quote\QuoteBulkDeleteRequest;
use App\Http\Requests\Quote\QuoteCalculateRequest;
use App\Http\Requests\Quote\QuoteIndexRequest;
use App\Http\Requests\Quote\QuoteSendEmailRequest;
use App\Http\Requests\Quote\QuoteSendKakaoRequest;
use App\Http\Requests\Quote\QuoteStoreRequest;
use App\Http\Requests\Quote\QuoteUpdateRequest;
use App\Services\Quote\QuoteCalculationService;
use App\Services\Quote\QuoteDocumentService;
use App\Services\Quote\QuoteNumberService;
use App\Services\Quote\QuoteService;
class QuoteController extends Controller
{
public function __construct(
private QuoteService $quoteService,
private QuoteNumberService $numberService,
private QuoteCalculationService $calculationService,
private QuoteDocumentService $documentService
) {}
/**
* 견적 목록 조회
*/
public function index(QuoteIndexRequest $request)
{
return ApiResponse::handle(function () use ($request) {
return $this->quoteService->index($request->validated());
}, __('message.quote.fetched'));
}
/**
* 견적 단건 조회
*/
public function show(int $id)
{
return ApiResponse::handle(function () use ($id) {
return $this->quoteService->show($id);
}, __('message.quote.fetched'));
}
/**
* 견적 생성
*/
public function store(QuoteStoreRequest $request)
{
return ApiResponse::handle(function () use ($request) {
return $this->quoteService->store($request->validated());
}, __('message.quote.created'));
}
/**
* 견적 수정
*/
public function update(QuoteUpdateRequest $request, int $id)
{
return ApiResponse::handle(function () use ($request, $id) {
return $this->quoteService->update($id, $request->validated());
}, __('message.quote.updated'));
}
/**
* 견적 삭제
*/
public function destroy(int $id)
{
return ApiResponse::handle(function () use ($id) {
$this->quoteService->destroy($id);
return null;
}, __('message.quote.deleted'));
}
/**
* 견적 일괄 삭제
*/
public function bulkDestroy(QuoteBulkDeleteRequest $request)
{
return ApiResponse::handle(function () use ($request) {
$count = $this->quoteService->bulkDestroy($request->validated()['ids']);
return ['deleted_count' => $count];
}, __('message.quote.bulk_deleted'));
}
/**
* 견적 확정
*/
public function finalize(int $id)
{
return ApiResponse::handle(function () use ($id) {
return $this->quoteService->finalize($id);
}, __('message.quote.finalized'));
}
/**
* 견적 확정 취소
*/
public function cancelFinalize(int $id)
{
return ApiResponse::handle(function () use ($id) {
return $this->quoteService->cancelFinalize($id);
}, __('message.quote.finalize_cancelled'));
}
/**
* 수주 전환
*/
public function convertToOrder(int $id)
{
return ApiResponse::handle(function () use ($id) {
return $this->quoteService->convertToOrder($id);
}, __('message.quote.converted'));
}
/**
* 견적번호 미리보기
*/
public function previewNumber(?string $productCategory = null)
{
return ApiResponse::handle(function () use ($productCategory) {
return $this->numberService->preview($productCategory);
}, __('message.fetched'));
}
/**
* 자동산출 미리보기
*/
public function calculate(QuoteCalculateRequest $request)
{
return ApiResponse::handle(function () use ($request) {
$validated = $request->validated();
return $this->calculationService->calculate(
$validated['inputs'] ?? $validated,
$validated['product_category'] ?? null
);
}, __('message.quote.calculated'));
}
/**
* 자동산출 입력 스키마 조회
*/
public function calculationSchema(?string $productCategory = null)
{
return ApiResponse::handle(function () use ($productCategory) {
return $this->calculationService->getInputSchema($productCategory);
}, __('message.fetched'));
}
/**
* 견적서 PDF 생성
*/
public function generatePdf(int $id)
{
return ApiResponse::handle(function () use ($id) {
return $this->documentService->generatePdf($id);
}, __('message.quote.pdf_generated'));
}
/**
* 견적서 이메일 발송
*/
public function sendEmail(QuoteSendEmailRequest $request, int $id)
{
return ApiResponse::handle(function () use ($request, $id) {
return $this->documentService->sendEmail($id, $request->validated());
}, __('message.quote_email_sent'));
}
/**
* 견적서 카카오톡 발송
*/
public function sendKakao(QuoteSendKakaoRequest $request, int $id)
{
return ApiResponse::handle(function () use ($request, $id) {
return $this->documentService->sendKakao($id, $request->validated());
}, __('message.quote_kakao_sent'));
}
/**
* 발송 이력 조회
*/
public function sendHistory(int $id)
{
return ApiResponse::handle(function () use ($id) {
return $this->documentService->getSendHistory($id);
}, __('message.fetched'));
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Requests\Quote;
use Illuminate\Foundation\Http\FormRequest;
class QuoteBulkDeleteRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'ids' => 'required|array|min:1',
'ids.*' => 'required|integer',
];
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Http\Requests\Quote;
use App\Models\Quote\Quote;
use Illuminate\Foundation\Http\FormRequest;
class QuoteCalculateRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'product_category' => 'nullable|in:'.Quote::CATEGORY_SCREEN.','.Quote::CATEGORY_STEEL,
// 입력값 (직접 또는 inputs 객체로)
'inputs' => 'nullable|array',
// 공통 입력
'W0' => 'nullable|numeric|min:0',
'H0' => 'nullable|numeric|min:0',
'QTY' => 'nullable|integer|min:1',
'inputs.W0' => 'nullable|numeric|min:0',
'inputs.H0' => 'nullable|numeric|min:0',
'inputs.QTY' => 'nullable|integer|min:1',
// 스크린 제품 입력
'INSTALL_TYPE' => 'nullable|in:wall,ceiling,floor',
'MOTOR_TYPE' => 'nullable|in:standard,heavy',
'CONTROL_TYPE' => 'nullable|in:switch,remote,smart',
'CHAIN_SIDE' => 'nullable|in:left,right',
'inputs.INSTALL_TYPE' => 'nullable|in:wall,ceiling,floor',
'inputs.MOTOR_TYPE' => 'nullable|in:standard,heavy',
'inputs.CONTROL_TYPE' => 'nullable|in:switch,remote,smart',
'inputs.CHAIN_SIDE' => 'nullable|in:left,right',
// 철재 제품 입력
'MATERIAL' => 'nullable|in:ss304,ss316,galvanized',
'THICKNESS' => 'nullable|numeric|min:0.1|max:50',
'FINISH' => 'nullable|in:hairline,mirror,matte',
'WELDING' => 'nullable|in:tig,mig,spot',
'inputs.MATERIAL' => 'nullable|in:ss304,ss316,galvanized',
'inputs.THICKNESS' => 'nullable|numeric|min:0.1|max:50',
'inputs.FINISH' => 'nullable|in:hairline,mirror,matte',
'inputs.WELDING' => 'nullable|in:tig,mig,spot',
];
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Http\Requests\Quote;
use App\Models\Quote\Quote;
use Illuminate\Foundation\Http\FormRequest;
class QuoteIndexRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'page' => 'nullable|integer|min:1',
'size' => 'nullable|integer|min:1|max:100',
'q' => 'nullable|string|max:100',
'status' => 'nullable|in:'.implode(',', [
Quote::STATUS_DRAFT,
Quote::STATUS_SENT,
Quote::STATUS_APPROVED,
Quote::STATUS_REJECTED,
Quote::STATUS_FINALIZED,
Quote::STATUS_CONVERTED,
]),
'product_category' => 'nullable|in:'.Quote::CATEGORY_SCREEN.','.Quote::CATEGORY_STEEL,
'client_id' => 'nullable|integer',
'date_from' => 'nullable|date',
'date_to' => 'nullable|date|after_or_equal:date_from',
'sort_by' => 'nullable|in:registration_date,quote_number,client_name,total_amount,status,created_at',
'sort_order' => 'nullable|in:asc,desc',
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Requests\Quote;
use Illuminate\Foundation\Http\FormRequest;
class QuoteSendEmailRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'email' => 'nullable|email|max:100',
'name' => 'nullable|string|max:100',
'subject' => 'nullable|string|max:200',
'message' => 'nullable|string|max:2000',
'cc' => 'nullable|array',
'cc.*' => 'nullable|email|max:100',
'attach_pdf' => 'nullable|boolean',
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Requests\Quote;
use Illuminate\Foundation\Http\FormRequest;
class QuoteSendKakaoRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'phone' => 'nullable|string|max:20',
'name' => 'nullable|string|max:100',
'template_code' => 'nullable|string|max:50',
'view_url' => 'nullable|url|max:500',
];
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace App\Http\Requests\Quote;
use App\Models\Quote\Quote;
use Illuminate\Foundation\Http\FormRequest;
class QuoteStoreRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
// 기본 정보
'quote_number' => 'nullable|string|max:50',
'registration_date' => 'nullable|date',
'receipt_date' => 'nullable|date',
'author' => 'nullable|string|max:50',
// 발주처 정보
'client_id' => 'nullable|integer',
'client_name' => 'nullable|string|max:100',
'manager' => 'nullable|string|max:50',
'contact' => 'nullable|string|max:50',
// 현장 정보
'site_id' => 'nullable|integer',
'site_name' => 'nullable|string|max:100',
'site_code' => 'nullable|string|max:50',
// 제품 정보
'product_category' => 'nullable|in:'.Quote::CATEGORY_SCREEN.','.Quote::CATEGORY_STEEL,
'product_id' => 'nullable|integer',
'product_code' => 'nullable|string|max:50',
'product_name' => 'nullable|string|max:100',
// 규격 정보
'open_size_width' => 'nullable|numeric|min:0',
'open_size_height' => 'nullable|numeric|min:0',
'quantity' => 'nullable|integer|min:1',
'unit_symbol' => 'nullable|string|max:10',
'floors' => 'nullable|string|max:50',
// 금액 정보
'material_cost' => 'nullable|numeric|min:0',
'labor_cost' => 'nullable|numeric|min:0',
'install_cost' => 'nullable|numeric|min:0',
'discount_rate' => 'nullable|numeric|min:0|max:100',
'total_amount' => 'nullable|numeric|min:0',
// 기타 정보
'completion_date' => 'nullable|date',
'remarks' => 'nullable|string|max:500',
'memo' => 'nullable|string',
'notes' => 'nullable|string',
// 자동산출 입력값
'calculation_inputs' => 'nullable|array',
'calculation_inputs.*' => 'nullable',
// 품목 배열
'items' => 'nullable|array',
'items.*.item_id' => 'nullable|integer',
'items.*.item_code' => 'nullable|string|max:50',
'items.*.item_name' => 'nullable|string|max:100',
'items.*.specification' => 'nullable|string|max:200',
'items.*.unit' => 'nullable|string|max:20',
'items.*.base_quantity' => 'nullable|numeric|min:0',
'items.*.calculated_quantity' => 'nullable|numeric|min:0',
'items.*.unit_price' => 'nullable|numeric|min:0',
'items.*.total_price' => 'nullable|numeric|min:0',
'items.*.formula' => 'nullable|string|max:500',
'items.*.formula_result' => 'nullable|string|max:200',
'items.*.formula_source' => 'nullable|string|max:100',
'items.*.formula_category' => 'nullable|string|max:50',
'items.*.data_source' => 'nullable|string|max:100',
'items.*.delivery_date' => 'nullable|date',
'items.*.note' => 'nullable|string|max:500',
'items.*.sort_order' => 'nullable|integer|min:0',
];
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace App\Http\Requests\Quote;
use App\Models\Quote\Quote;
use Illuminate\Foundation\Http\FormRequest;
class QuoteUpdateRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
// 기본 정보
'receipt_date' => 'nullable|date',
'author' => 'nullable|string|max:50',
// 발주처 정보
'client_id' => 'nullable|integer',
'client_name' => 'nullable|string|max:100',
'manager' => 'nullable|string|max:50',
'contact' => 'nullable|string|max:50',
// 현장 정보
'site_id' => 'nullable|integer',
'site_name' => 'nullable|string|max:100',
'site_code' => 'nullable|string|max:50',
// 제품 정보
'product_category' => 'nullable|in:'.Quote::CATEGORY_SCREEN.','.Quote::CATEGORY_STEEL,
'product_id' => 'nullable|integer',
'product_code' => 'nullable|string|max:50',
'product_name' => 'nullable|string|max:100',
// 규격 정보
'open_size_width' => 'nullable|numeric|min:0',
'open_size_height' => 'nullable|numeric|min:0',
'quantity' => 'nullable|integer|min:1',
'unit_symbol' => 'nullable|string|max:10',
'floors' => 'nullable|string|max:50',
// 금액 정보
'material_cost' => 'nullable|numeric|min:0',
'labor_cost' => 'nullable|numeric|min:0',
'install_cost' => 'nullable|numeric|min:0',
'discount_rate' => 'nullable|numeric|min:0|max:100',
'total_amount' => 'nullable|numeric|min:0',
// 기타 정보
'completion_date' => 'nullable|date',
'remarks' => 'nullable|string|max:500',
'memo' => 'nullable|string',
'notes' => 'nullable|string',
// 자동산출 입력값
'calculation_inputs' => 'nullable|array',
'calculation_inputs.*' => 'nullable',
// 품목 배열 (전체 교체)
'items' => 'nullable|array',
'items.*.item_id' => 'nullable|integer',
'items.*.item_code' => 'nullable|string|max:50',
'items.*.item_name' => 'nullable|string|max:100',
'items.*.specification' => 'nullable|string|max:200',
'items.*.unit' => 'nullable|string|max:20',
'items.*.base_quantity' => 'nullable|numeric|min:0',
'items.*.calculated_quantity' => 'nullable|numeric|min:0',
'items.*.unit_price' => 'nullable|numeric|min:0',
'items.*.total_price' => 'nullable|numeric|min:0',
'items.*.formula' => 'nullable|string|max:500',
'items.*.formula_result' => 'nullable|string|max:200',
'items.*.formula_source' => 'nullable|string|max:100',
'items.*.formula_category' => 'nullable|string|max:50',
'items.*.data_source' => 'nullable|string|max:100',
'items.*.delivery_date' => 'nullable|date',
'items.*.note' => 'nullable|string|max:500',
'items.*.sort_order' => 'nullable|integer|min:0',
];
}
}