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>
This commit is contained in:
294
app/Models/Production/WorkOrder.php
Normal file
294
app/Models/Production/WorkOrder.php
Normal file
@@ -0,0 +1,294 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Production;
|
||||
|
||||
use App\Models\Members\User;
|
||||
use App\Models\Orders\Order;
|
||||
use App\Models\Tenants\Department;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use App\Traits\ModelTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* 작업지시 모델
|
||||
*
|
||||
* 생산 관리의 핵심 엔티티로 수주(SalesOrder)를 기반으로 생산 작업을 지시하고 추적
|
||||
*/
|
||||
class WorkOrder extends Model
|
||||
{
|
||||
use BelongsToTenant, ModelTrait, SoftDeletes;
|
||||
|
||||
protected $table = 'work_orders';
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id',
|
||||
'work_order_no',
|
||||
'sales_order_id',
|
||||
'project_name',
|
||||
'process_type',
|
||||
'status',
|
||||
'assignee_id',
|
||||
'team_id',
|
||||
'scheduled_date',
|
||||
'started_at',
|
||||
'completed_at',
|
||||
'shipped_at',
|
||||
'memo',
|
||||
'is_active',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'scheduled_date' => 'date',
|
||||
'started_at' => 'datetime',
|
||||
'completed_at' => 'datetime',
|
||||
'shipped_at' => 'datetime',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
// 상수
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 공정 유형
|
||||
*/
|
||||
public const PROCESS_SCREEN = 'screen';
|
||||
|
||||
public const PROCESS_SLAT = 'slat';
|
||||
|
||||
public const PROCESS_BENDING = 'bending';
|
||||
|
||||
public const PROCESS_TYPES = [
|
||||
self::PROCESS_SCREEN,
|
||||
self::PROCESS_SLAT,
|
||||
self::PROCESS_BENDING,
|
||||
];
|
||||
|
||||
/**
|
||||
* 상태
|
||||
*/
|
||||
public const STATUS_UNASSIGNED = 'unassigned'; // 미배정
|
||||
|
||||
public const STATUS_PENDING = 'pending'; // 대기
|
||||
|
||||
public const STATUS_WAITING = 'waiting'; // 준비중
|
||||
|
||||
public const STATUS_IN_PROGRESS = 'in_progress'; // 진행중
|
||||
|
||||
public const STATUS_COMPLETED = 'completed'; // 완료
|
||||
|
||||
public const STATUS_SHIPPED = 'shipped'; // 출하
|
||||
|
||||
public const STATUSES = [
|
||||
self::STATUS_UNASSIGNED,
|
||||
self::STATUS_PENDING,
|
||||
self::STATUS_WAITING,
|
||||
self::STATUS_IN_PROGRESS,
|
||||
self::STATUS_COMPLETED,
|
||||
self::STATUS_SHIPPED,
|
||||
];
|
||||
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
// 관계
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 수주
|
||||
*/
|
||||
public function salesOrder(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Order::class, 'sales_order_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 담당자
|
||||
*/
|
||||
public function assignee(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'assignee_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 팀
|
||||
*/
|
||||
public function team(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'team_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 작업지시 품목들
|
||||
*/
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(WorkOrderItem::class)->orderBy('sort_order');
|
||||
}
|
||||
|
||||
/**
|
||||
* 벤딩 상세 (1:1)
|
||||
*/
|
||||
public function bendingDetail(): HasOne
|
||||
{
|
||||
return $this->hasOne(WorkOrderBendingDetail::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 이슈들
|
||||
*/
|
||||
public function issues(): HasMany
|
||||
{
|
||||
return $this->hasMany(WorkOrderIssue::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 생성자
|
||||
*/
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* 수정자
|
||||
*/
|
||||
public function updater(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'updated_by');
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
// 스코프
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 상태별 필터
|
||||
*/
|
||||
public function scopeStatus($query, string $status)
|
||||
{
|
||||
return $query->where('status', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 공정유형별 필터
|
||||
*/
|
||||
public function scopeProcessType($query, string $type)
|
||||
{
|
||||
return $query->where('process_type', $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 담당자별 필터
|
||||
*/
|
||||
public function scopeAssignee($query, int $assigneeId)
|
||||
{
|
||||
return $query->where('assignee_id', $assigneeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 팀별 필터
|
||||
*/
|
||||
public function scopeTeam($query, int $teamId)
|
||||
{
|
||||
return $query->where('team_id', $teamId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 미배정
|
||||
*/
|
||||
public function scopeUnassigned($query)
|
||||
{
|
||||
return $query->where('status', self::STATUS_UNASSIGNED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 진행중 (pending, waiting, in_progress)
|
||||
*/
|
||||
public function scopeInProgress($query)
|
||||
{
|
||||
return $query->whereIn('status', [
|
||||
self::STATUS_PENDING,
|
||||
self::STATUS_WAITING,
|
||||
self::STATUS_IN_PROGRESS,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 완료됨 (completed, shipped)
|
||||
*/
|
||||
public function scopeCompleted($query)
|
||||
{
|
||||
return $query->whereIn('status', [
|
||||
self::STATUS_COMPLETED,
|
||||
self::STATUS_SHIPPED,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 예정일 범위
|
||||
*/
|
||||
public function scopeScheduledBetween($query, $from, $to)
|
||||
{
|
||||
return $query->whereBetween('scheduled_date', [$from, $to]);
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
// 헬퍼 메서드
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 벤딩 공정인지 확인
|
||||
*/
|
||||
public function isBending(): bool
|
||||
{
|
||||
return $this->process_type === self::PROCESS_BENDING;
|
||||
}
|
||||
|
||||
/**
|
||||
* 미배정 상태인지 확인
|
||||
*/
|
||||
public function isUnassigned(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_UNASSIGNED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 진행중인지 확인
|
||||
*/
|
||||
public function isInProgress(): bool
|
||||
{
|
||||
return in_array($this->status, [
|
||||
self::STATUS_PENDING,
|
||||
self::STATUS_WAITING,
|
||||
self::STATUS_IN_PROGRESS,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 완료되었는지 확인
|
||||
*/
|
||||
public function isCompleted(): bool
|
||||
{
|
||||
return in_array($this->status, [
|
||||
self::STATUS_COMPLETED,
|
||||
self::STATUS_SHIPPED,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 미해결 이슈 수
|
||||
*/
|
||||
public function getOpenIssuesCountAttribute(): int
|
||||
{
|
||||
return $this->issues()->where('status', '!=', 'resolved')->count();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user