feat : Main Request 모델 추가, Enum 클래스 추가
- Main Request가 모든 공정을 관리하는 형태
This commit is contained in:
57
app/Enums/BusinessStatus.php
Normal file
57
app/Enums/BusinessStatus.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 견적 상태 코드 Enum
|
||||||
|
*/
|
||||||
|
enum EstimateStatus: string
|
||||||
|
{
|
||||||
|
case Draft = 'draft'; // 임시저장
|
||||||
|
case Submitted = 'submitted'; // 제출/확정
|
||||||
|
case Approved = 'approved'; // 승인
|
||||||
|
case Rejected = 'rejected'; // 반려
|
||||||
|
case Cancelled = 'cancelled'; // 취소
|
||||||
|
|
||||||
|
// 한글라벨 등 커스텀 메서드
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match($this) {
|
||||||
|
self::Draft => '임시저장',
|
||||||
|
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();
|
||||||
|
}*/
|
||||||
50
app/Models/MainRequest.php
Normal file
50
app/Models/MainRequest.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class MainRequest extends Model
|
||||||
|
{
|
||||||
|
use SoftDeletes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 통합 업무 마스터(견적/수주/발주/작업 등)
|
||||||
|
*/
|
||||||
|
protected $table = 'main_requests';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'tenant_id',
|
||||||
|
'status_code',
|
||||||
|
'description',
|
||||||
|
'created_by',
|
||||||
|
'updated_by',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
'deleted_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 전체 이력(흐름) 리스트
|
||||||
|
*/
|
||||||
|
public function flows()
|
||||||
|
{
|
||||||
|
return $this->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 관계 추가
|
||||||
|
}
|
||||||
41
app/Models/MainRequestFlow.php
Normal file
41
app/Models/MainRequestFlow.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class MainRequestFlow extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 업무 전체/상세 흐름 이력(폴리모픽)
|
||||||
|
*/
|
||||||
|
protected $table = 'main_request_flows';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'main_request_id',
|
||||||
|
'flowable_type', // 폴리모픽 타입(모델명)
|
||||||
|
'flowable_id', // 폴리모픽 PK
|
||||||
|
'status_code',
|
||||||
|
'action',
|
||||||
|
'content',
|
||||||
|
'actor_id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 메인 업무 엔터티
|
||||||
|
*/
|
||||||
|
public function mainRequest()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(MainRequest::class, 'main_request_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 폴리모픽 관계(견적, 주문, 발주 등)
|
||||||
|
*/
|
||||||
|
public function flowable()
|
||||||
|
{
|
||||||
|
return $this->morphTo();
|
||||||
|
}
|
||||||
|
}
|
||||||
44
app/Repositories/MainRequestRepository.php
Normal file
44
app/Repositories/MainRequestRepository.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Repositories;
|
||||||
|
|
||||||
|
use App\Models\MainRequest;
|
||||||
|
use App\Models\MainRequestEstimate;
|
||||||
|
use App\Models\MainRequestOrder;
|
||||||
|
use App\Models\MainRequestFlow;
|
||||||
|
|
||||||
|
class MainRequestRepository
|
||||||
|
{
|
||||||
|
// 메인 업무 단건 조회
|
||||||
|
public function find($id)
|
||||||
|
{
|
||||||
|
return MainRequest::with(['flows', 'estimates', 'orders'])->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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
59
app/Services/EstimateService.php
Normal file
59
app/Services/EstimateService.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Enums\EstimateStatus;
|
||||||
|
use App\Repositories\MainRequestRepository;
|
||||||
|
use App\Models\MainRequestEstimate;
|
||||||
|
|
||||||
|
class EstimateService
|
||||||
|
{
|
||||||
|
protected $mainRequestRepo;
|
||||||
|
|
||||||
|
public function __construct(MainRequestRepository $mainRequestRepo)
|
||||||
|
{
|
||||||
|
$this->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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ... 기타 견적 비즈니스 로직도 여기에!
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user