diff --git a/app/Enums/BusinessStatus.php b/app/Enums/BusinessStatus.php new file mode 100644 index 0000000..d057b53 --- /dev/null +++ b/app/Enums/BusinessStatus.php @@ -0,0 +1,57 @@ + '임시저장', + self::Submitted => '제출/확정', + self::Approved => '승인', + self::Rejected => '반려', + self::Cancelled => '취소', + }; + } +} + +/** + * 주문 상태 코드 Enum + */ +enum OrderStatus: string +{ + case Created = 'created'; + case Confirmed = 'confirmed'; + case InProgress = 'in_progress'; + case Completed = 'completed'; + case Cancelled = 'cancelled'; + + // 한글라벨 등 커스텀 메서드 + public function label(): string + { + return match($this) { + self::Created => '등록', + self::Confirmed => '승인', + self::InProgress => '진행중', + self::Completed => '완료', + self::Cancelled => '취소', + }; + } +} + +// 사용 +/*foreach (EstimateStatus::cases() as $status) { + echo $status->name; + echo $status->value; + echo $status->label(); +}*/ diff --git a/app/Models/MainRequest.php b/app/Models/MainRequest.php new file mode 100644 index 0000000..bb83d92 --- /dev/null +++ b/app/Models/MainRequest.php @@ -0,0 +1,50 @@ +hasMany(MainRequestFlow::class, 'main_request_id'); + } + + /** + * 견적/수주/발주 등 파생 업무별 관계 (예시) + */ + public function estimates() + { + //return $this->hasMany(MainRequestEstimate::class, 'main_request_id'); + } + + public function orders() + { + //return $this->hasMany(MainRequestOrder::class, 'main_request_id'); + } + + // ... 필요에 따라 파생 업무별 hasMany 관계 추가 +} diff --git a/app/Models/MainRequestFlow.php b/app/Models/MainRequestFlow.php new file mode 100644 index 0000000..23acb43 --- /dev/null +++ b/app/Models/MainRequestFlow.php @@ -0,0 +1,41 @@ +belongsTo(MainRequest::class, 'main_request_id'); + } + + /** + * 폴리모픽 관계(견적, 주문, 발주 등) + */ + public function flowable() + { + return $this->morphTo(); + } +} diff --git a/app/Repositories/MainRequestRepository.php b/app/Repositories/MainRequestRepository.php new file mode 100644 index 0000000..63328fb --- /dev/null +++ b/app/Repositories/MainRequestRepository.php @@ -0,0 +1,44 @@ +find($id); + } + + // 견적 생성 + public function createEstimate($mainRequestId, array $data) + { + $data['main_request_id'] = $mainRequestId; + return MainRequestEstimate::create($data); + } + + // 주문 생성 + public function createOrder($mainRequestId, array $data) + { + $data['main_request_id'] = $mainRequestId; + return MainRequestOrder::create($data); + } + + // 이력(Flow) 기록 + public function addFlow($mainRequestId, $flowableType, $flowableId, $status, $action, $actorId, $content = null) + { + return MainRequestFlow::create([ + 'main_request_id' => $mainRequestId, + 'flowable_type' => $flowableType, + 'flowable_id' => $flowableId, + 'status_code' => $status, + 'action' => $action, + 'actor_id' => $actorId, + 'content' => $content, + ]); + } +} diff --git a/app/Services/EstimateService.php b/app/Services/EstimateService.php new file mode 100644 index 0000000..941a6ad --- /dev/null +++ b/app/Services/EstimateService.php @@ -0,0 +1,59 @@ +mainRequestRepo = $mainRequestRepo; + } + + /** + * 견적 신규 등록 + */ + public function createEstimate($mainRequestId, array $data, $actorId): MainRequestEstimate + { + $estimate = $this->mainRequestRepo->createEstimate($mainRequestId, $data); + + // 상태 이력 기록 (draft) + $this->mainRequestRepo->addFlow( + $mainRequestId, + get_class($estimate), + $estimate->id, + EstimateStatus::Draft->value, + '등록', + $actorId, + '견적서 임시 등록' + ); + + return $estimate; + } + + /** + * 견적 상태 변경 + */ + public function changeEstimateStatus(MainRequestEstimate $estimate, EstimateStatus $newStatus, $actorId, $memo = null) + { + $estimate->status_code = $newStatus; + $estimate->save(); + + // 이력 기록 + $this->mainRequestRepo->addFlow( + $estimate->main_request_id, + get_class($estimate), + $estimate->id, + $newStatus->value, + '상태변경', + $actorId, + $memo + ); + } + + // ... 기타 견적 비즈니스 로직도 여기에! +}