feat: [status] 재공품 검사완료 시 WO+수주 자동 완료 처리 (단일부품)
This commit is contained in:
@@ -2480,7 +2480,6 @@ public function storeItemInspection(int $workOrderId, int $itemId, array $data):
|
||||
);
|
||||
|
||||
// 검사 완료 시 WO 상태 자동 전이
|
||||
// 1. waiting/pending → in_progress (아직 진행중 아니면)
|
||||
$workOrder->refresh();
|
||||
if (in_array($workOrder->status, [WorkOrder::STATUS_PENDING, WorkOrder::STATUS_WAITING])) {
|
||||
$workOrder->status = WorkOrder::STATUS_IN_PROGRESS;
|
||||
@@ -2490,12 +2489,35 @@ public function storeItemInspection(int $workOrderId, int $itemId, array $data):
|
||||
$this->syncOrderStatus($workOrder, $tenantId);
|
||||
}
|
||||
|
||||
// 2. 모든 공정 단계 완료 확인 → WO 자동 완료
|
||||
$this->autoCompleteWorkOrderIfAllStepsDone($workOrder, $tenantId, $userId);
|
||||
// 재공품(STOCK): 검사 완료 = 전체 완료 (단일 부품이므로)
|
||||
$order = $workOrder->sales_order_id
|
||||
? Order::withoutGlobalScopes()->find($workOrder->sales_order_id)
|
||||
: null;
|
||||
$isStock = $order && $order->order_type_code === 'STOCK';
|
||||
|
||||
if ($isStock) {
|
||||
// 미완료 단계 일괄 완료
|
||||
WorkOrderStepProgress::where('work_order_id', $workOrder->id)
|
||||
->where('status', '!=', 'completed')
|
||||
->update([
|
||||
'status' => 'completed',
|
||||
'completed_at' => now(),
|
||||
'completed_by' => $userId,
|
||||
]);
|
||||
|
||||
// WO → completed
|
||||
if ($workOrder->status !== WorkOrder::STATUS_COMPLETED) {
|
||||
$this->updateStatus($workOrder->id, WorkOrder::STATUS_COMPLETED);
|
||||
}
|
||||
} else {
|
||||
// 일반 수주: 모든 공정 단계 완료 확인 → WO 자동 완료
|
||||
$this->autoCompleteWorkOrderIfAllStepsDone($workOrder, $tenantId, $userId);
|
||||
}
|
||||
|
||||
return [
|
||||
'item_id' => $item->id,
|
||||
'inspection_data' => $item->getInspectionData(),
|
||||
'work_order_completed' => $isStock && $workOrder->fresh()->status === WorkOrder::STATUS_COMPLETED,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user