- WorkOrderItem 모델에 status 컬럼 및 상수 추가 (waiting/in_progress/completed)
- 품목 상태 변경 API 엔드포인트 추가 (PATCH /work-orders/{id}/items/{itemId}/status)
- syncWorkOrderStatusFromItems() 메서드로 품목→작업지시 상태 자동 동기화
- 품목 중 하나라도 in_progress → 작업지시 in_progress
- 모든 품목 completed → 작업지시 completed
- 모든 품목 waiting → 작업지시 waiting
- 감사 로그: item_status_changed, status_synced_from_items 액션 추가
Co-Authored-By: Claude <noreply@anthropic.com>
81 lines
2.2 KiB
PHP
81 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Production;
|
|
|
|
use App\Models\Items\Item;
|
|
use App\Traits\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* 작업지시 품목 모델
|
|
*/
|
|
class WorkOrderItem extends Model
|
|
{
|
|
use BelongsToTenant;
|
|
|
|
protected $table = 'work_order_items';
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'work_order_id',
|
|
'item_id',
|
|
'item_name',
|
|
'specification',
|
|
'quantity',
|
|
'unit',
|
|
'sort_order',
|
|
'status',
|
|
];
|
|
|
|
/**
|
|
* 품목 상태 상수
|
|
*/
|
|
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,
|
|
];
|
|
|
|
protected $casts = [
|
|
'quantity' => 'decimal:2',
|
|
'sort_order' => 'integer',
|
|
];
|
|
|
|
// ──────────────────────────────────────────────────────────────
|
|
// 관계
|
|
// ──────────────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* 작업지시
|
|
*/
|
|
public function workOrder(): BelongsTo
|
|
{
|
|
return $this->belongsTo(WorkOrder::class);
|
|
}
|
|
|
|
/**
|
|
* 품목
|
|
*/
|
|
public function item(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Item::class);
|
|
}
|
|
|
|
// ──────────────────────────────────────────────────────────────
|
|
// 스코프
|
|
// ──────────────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* 정렬 순서
|
|
*/
|
|
public function scopeOrdered($query)
|
|
{
|
|
return $query->orderBy('sort_order');
|
|
}
|
|
}
|