'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; } }