feat: 견적확정 밸리데이션, 작업지시 통계 공정별 카운트, 입고/재고 개선
- 견적확정 시 업체명/현장명/담당자/연락처 필수 검증 추가 (QuoteService) - 작업지시 stats API에 by_process 공정별 카운트 반환 추가 - 작업지시 목록/상세 쿼리에 수주 개소(rootNodes) 연관 로딩 - 작업지시 품목에 sourceOrderItem.node 관계 추가 - 입고관리 완료건 수정 허용 및 재고 차이 조정 - work_order_step_progress 테이블 마이그레이션 - receivings 테이블 options 컬럼 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -195,6 +195,14 @@ public function issues(): HasMany
|
||||
return $this->hasMany(WorkOrderIssue::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 공정 단계 진행 추적
|
||||
*/
|
||||
public function stepProgress(): HasMany
|
||||
{
|
||||
return $this->hasMany(WorkOrderStepProgress::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 출하 목록
|
||||
*/
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models\Production;
|
||||
|
||||
use App\Models\Items\Item;
|
||||
use App\Models\Orders\OrderItem;
|
||||
use App\Traits\Auditable;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -72,6 +73,14 @@ public function item(): BelongsTo
|
||||
return $this->belongsTo(Item::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 원본 수주 품목
|
||||
*/
|
||||
public function sourceOrderItem(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(OrderItem::class, 'source_order_item_id');
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
// 스코프
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
|
||||
148
app/Models/Production/WorkOrderStepProgress.php
Normal file
148
app/Models/Production/WorkOrderStepProgress.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Production;
|
||||
|
||||
use App\Models\Members\User;
|
||||
use App\Models\ProcessStep;
|
||||
use App\Traits\Auditable;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* 작업지시 공정 단계 진행 추적 모델
|
||||
*
|
||||
* 각 작업지시별 공정 단계의 완료 상태를 추적
|
||||
*/
|
||||
class WorkOrderStepProgress extends Model
|
||||
{
|
||||
use Auditable, BelongsToTenant;
|
||||
|
||||
protected $table = 'work_order_step_progress';
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id',
|
||||
'work_order_id',
|
||||
'process_step_id',
|
||||
'work_order_item_id',
|
||||
'status',
|
||||
'completed_at',
|
||||
'completed_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'completed_at' => 'datetime',
|
||||
];
|
||||
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
// 상수
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
|
||||
public const STATUS_WAITING = 'waiting';
|
||||
|
||||
public const STATUS_IN_PROGRESS = 'in_progress';
|
||||
|
||||
public const STATUS_COMPLETED = 'completed';
|
||||
|
||||
public const STATUSES = [
|
||||
self::STATUS_WAITING,
|
||||
self::STATUS_IN_PROGRESS,
|
||||
self::STATUS_COMPLETED,
|
||||
];
|
||||
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
// 관계
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 작업지시
|
||||
*/
|
||||
public function workOrder(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WorkOrder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 공정 단계
|
||||
*/
|
||||
public function processStep(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ProcessStep::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 작업지시 품목 (선택적)
|
||||
*/
|
||||
public function workOrderItem(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WorkOrderItem::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 완료 처리자
|
||||
*/
|
||||
public function completedByUser(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'completed_by');
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
// 스코프
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
|
||||
public function scopeCompleted($query)
|
||||
{
|
||||
return $query->where('status', self::STATUS_COMPLETED);
|
||||
}
|
||||
|
||||
public function scopeWaiting($query)
|
||||
{
|
||||
return $query->where('status', self::STATUS_WAITING);
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
// 헬퍼 메서드
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 완료 처리
|
||||
*/
|
||||
public function markCompleted(?int $userId = null): void
|
||||
{
|
||||
$this->status = self::STATUS_COMPLETED;
|
||||
$this->completed_at = now();
|
||||
$this->completed_by = $userId;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 대기 상태로 되돌리기
|
||||
*/
|
||||
public function markWaiting(): void
|
||||
{
|
||||
$this->status = self::STATUS_WAITING;
|
||||
$this->completed_at = null;
|
||||
$this->completed_by = null;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 완료 여부
|
||||
*/
|
||||
public function isCompleted(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 완료 토글
|
||||
*/
|
||||
public function toggle(?int $userId = null): void
|
||||
{
|
||||
if ($this->isCompleted()) {
|
||||
$this->markWaiting();
|
||||
} else {
|
||||
$this->markCompleted($userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ class Receiving extends Model
|
||||
'receiving_manager',
|
||||
'status',
|
||||
'remark',
|
||||
'options',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
@@ -45,8 +46,33 @@ class Receiving extends Model
|
||||
'order_qty' => 'decimal:2',
|
||||
'receiving_qty' => 'decimal:2',
|
||||
'item_id' => 'integer',
|
||||
'options' => 'array',
|
||||
];
|
||||
|
||||
/**
|
||||
* JSON 직렬화 시 자동 포함되는 접근자
|
||||
*/
|
||||
protected $appends = [
|
||||
'manufacturer',
|
||||
'material_no',
|
||||
'inspection_status',
|
||||
'inspection_date',
|
||||
'inspection_result',
|
||||
];
|
||||
|
||||
/**
|
||||
* Options 키 상수 (확장 필드)
|
||||
*/
|
||||
public const OPTION_MANUFACTURER = 'manufacturer'; // 제조사
|
||||
|
||||
public const OPTION_MATERIAL_NO = 'material_no'; // 거래처 자재번호
|
||||
|
||||
public const OPTION_INSPECTION_STATUS = 'inspection_status'; // 수입검사 (적/부적/-)
|
||||
|
||||
public const OPTION_INSPECTION_DATE = 'inspection_date'; // 검사일
|
||||
|
||||
public const OPTION_INSPECTION_RESULT = 'inspection_result'; // 검사결과 (합격/불합격)
|
||||
|
||||
/**
|
||||
* 상태 목록
|
||||
*/
|
||||
@@ -82,12 +108,72 @@ public function getStatusLabelAttribute(): string
|
||||
return self::STATUSES[$this->status] ?? $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options에서 값 가져오기
|
||||
*/
|
||||
public function getOption(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return $this->options[$key] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options에 값 설정
|
||||
*/
|
||||
public function setOption(string $key, mixed $value): self
|
||||
{
|
||||
$options = $this->options ?? [];
|
||||
$options[$key] = $value;
|
||||
$this->options = $options;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 제조사 접근자
|
||||
*/
|
||||
public function getManufacturerAttribute(): ?string
|
||||
{
|
||||
return $this->getOption(self::OPTION_MANUFACTURER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 거래처 자재번호 접근자
|
||||
*/
|
||||
public function getMaterialNoAttribute(): ?string
|
||||
{
|
||||
return $this->getOption(self::OPTION_MATERIAL_NO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 수입검사 상태 접근자
|
||||
*/
|
||||
public function getInspectionStatusAttribute(): ?string
|
||||
{
|
||||
return $this->getOption(self::OPTION_INSPECTION_STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 검사일 접근자
|
||||
*/
|
||||
public function getInspectionDateAttribute(): ?string
|
||||
{
|
||||
return $this->getOption(self::OPTION_INSPECTION_DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 검사결과 접근자
|
||||
*/
|
||||
public function getInspectionResultAttribute(): ?string
|
||||
{
|
||||
return $this->getOption(self::OPTION_INSPECTION_RESULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 수정 가능 여부
|
||||
*/
|
||||
public function canEdit(): bool
|
||||
{
|
||||
return $this->status !== 'completed';
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user