Files
sam-api/app/Models/Production/WorkOrderBendingDetail.php
kent 05a53cdc8e feat: G-1 작업지시 관리 API 구현
- 작업지시 테이블 마이그레이션 (work_orders, work_order_items, work_order_bending_details, work_order_issues)
- 작업지시 모델 4개 (WorkOrder, WorkOrderItem, WorkOrderBendingDetail, WorkOrderIssue)
- WorkOrderService 비즈니스 로직 구현
- WorkOrderController REST API 엔드포인트 11개
- FormRequest 검증 클래스 5개
- Swagger API 문서화 완료

API Endpoints:
- GET /work-orders (목록)
- GET /work-orders/stats (통계)
- POST /work-orders (등록)
- GET /work-orders/{id} (상세)
- PUT /work-orders/{id} (수정)
- DELETE /work-orders/{id} (삭제)
- PATCH /work-orders/{id}/status (상태변경)
- PATCH /work-orders/{id}/assign (담당자배정)
- PATCH /work-orders/{id}/bending/toggle (벤딩토글)
- POST /work-orders/{id}/issues (이슈등록)
- PATCH /work-orders/{id}/issues/{issueId}/resolve (이슈해결)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-26 13:57:42 +09:00

132 lines
3.4 KiB
PHP

<?php
namespace App\Models\Production;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 작업지시 벤딩 상세 모델
*
* 벤딩 공정의 세부 작업 항목 완료 상태를 추적
*/
class WorkOrderBendingDetail extends Model
{
protected $table = 'work_order_bending_details';
protected $fillable = [
'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;
}
}