## Critical 수정 - Multi-tenancy: WorkOrderItem, BendingDetail, Issue에 BelongsToTenant 적용 - 감사 로그: 상태변경, 품목수정, 이슈 등록/해결 시 로깅 추가 - 상태 전이 규칙: STATUS_TRANSITIONS + canTransitionTo() 구현 ## High 수정 - 다중 담당자: work_order_assignees 피벗 테이블 및 관계 추가 - 부분 수정: 품목 ID 기반 upsert/delete 로직 구현 ## 변경 파일 - Models: WorkOrder, WorkOrderAssignee(신규), 하위 모델들 - Services: WorkOrderService (assign, update 메서드 개선) - Migrations: tenant_id 추가, assignees 테이블 생성 Co-Authored-By: Claude <noreply@anthropic.com>
136 lines
3.5 KiB
PHP
136 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Production;
|
|
|
|
use App\Traits\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* 작업지시 벤딩 상세 모델
|
|
*
|
|
* 벤딩 공정의 세부 작업 항목 완료 상태를 추적
|
|
*/
|
|
class WorkOrderBendingDetail extends Model
|
|
{
|
|
use BelongsToTenant;
|
|
|
|
protected $table = 'work_order_bending_details';
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'work_order_id',
|
|
'shaft_cutting',
|
|
'bearing',
|
|
'shaft_welding',
|
|
'assembly',
|
|
'winder_welding',
|
|
'frame_assembly',
|
|
'bundle_assembly',
|
|
'motor_assembly',
|
|
'bracket_assembly',
|
|
];
|
|
|
|
protected $casts = [
|
|
'shaft_cutting' => 'boolean',
|
|
'bearing' => 'boolean',
|
|
'shaft_welding' => 'boolean',
|
|
'assembly' => 'boolean',
|
|
'winder_welding' => 'boolean',
|
|
'frame_assembly' => 'boolean',
|
|
'bundle_assembly' => 'boolean',
|
|
'motor_assembly' => 'boolean',
|
|
'bracket_assembly' => 'boolean',
|
|
];
|
|
|
|
/**
|
|
* 벤딩 공정 항목 목록
|
|
*/
|
|
public const PROCESS_FIELDS = [
|
|
'shaft_cutting',
|
|
'bearing',
|
|
'shaft_welding',
|
|
'assembly',
|
|
'winder_welding',
|
|
'frame_assembly',
|
|
'bundle_assembly',
|
|
'motor_assembly',
|
|
'bracket_assembly',
|
|
];
|
|
|
|
// ──────────────────────────────────────────────────────────────
|
|
// 관계
|
|
// ──────────────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* 작업지시
|
|
*/
|
|
public function workOrder(): BelongsTo
|
|
{
|
|
return $this->belongsTo(WorkOrder::class);
|
|
}
|
|
|
|
// ──────────────────────────────────────────────────────────────
|
|
// 헬퍼 메서드
|
|
// ──────────────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* 완료된 항목 수
|
|
*/
|
|
public function getCompletedCountAttribute(): int
|
|
{
|
|
$count = 0;
|
|
foreach (self::PROCESS_FIELDS as $field) {
|
|
if ($this->{$field}) {
|
|
$count++;
|
|
}
|
|
}
|
|
|
|
return $count;
|
|
}
|
|
|
|
/**
|
|
* 전체 항목 수
|
|
*/
|
|
public function getTotalCountAttribute(): int
|
|
{
|
|
return count(self::PROCESS_FIELDS);
|
|
}
|
|
|
|
/**
|
|
* 진행률 (%)
|
|
*/
|
|
public function getProgressPercentAttribute(): int
|
|
{
|
|
$total = $this->total_count;
|
|
if ($total === 0) {
|
|
return 0;
|
|
}
|
|
|
|
return (int) round(($this->completed_count / $total) * 100);
|
|
}
|
|
|
|
/**
|
|
* 모든 항목이 완료되었는지 확인
|
|
*/
|
|
public function isAllCompleted(): bool
|
|
{
|
|
return $this->completed_count === $this->total_count;
|
|
}
|
|
|
|
/**
|
|
* 특정 항목 토글
|
|
*/
|
|
public function toggleField(string $field): bool
|
|
{
|
|
if (! in_array($field, self::PROCESS_FIELDS)) {
|
|
return false;
|
|
}
|
|
|
|
$this->{$field} = ! $this->{$field};
|
|
$this->save();
|
|
|
|
return true;
|
|
}
|
|
}
|