From e241c6a681c5fd9f6cf53fddb524d5953af6243b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Fri, 13 Mar 2026 10:14:15 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[work-order]=20=EB=B3=B4=EC=A1=B0?= =?UTF-8?q?=EA=B3=B5=EC=A0=95/=EB=AF=B8=EB=B0=B0=EC=A0=95=20=EC=9E=91?= =?UTF-8?q?=EC=97=85=EC=A7=80=EC=8B=9C=20=EB=AA=A9=EB=A1=9D=20=EC=A0=9C?= =?UTF-8?q?=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - process_id NOT NULL 기본 필터 추가 - is_auxiliary 보조공정 제외 조건 추가 - stats()에도 동일 필터 적용 - 기타(none) 탭 관련 로직 제거 Co-Authored-By: Claude Opus 4.6 --- app/Services/WorkOrderService.php | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/app/Services/WorkOrderService.php b/app/Services/WorkOrderService.php index 3da8978..366e419 100644 --- a/app/Services/WorkOrderService.php +++ b/app/Services/WorkOrderService.php @@ -51,6 +51,8 @@ public function index(array $params) $query = WorkOrder::query() ->where('tenant_id', $tenantId) + ->whereNotNull('process_id') + ->where(fn ($q) => $q->whereNull('options->is_auxiliary')->orWhere('options->is_auxiliary', false)) ->with([ 'assignee:id,name', 'assignees.user:id,name', @@ -80,14 +82,9 @@ public function index(array $params) } // 공정 필터 (process_id) - // - 'none' 또는 '0': 공정 미지정 (process_id IS NULL) - // - 숫자: 해당 공정 ID로 필터 - if ($processId !== null) { - if ($processId === 'none' || $processId === '0' || $processId === 0) { - $query->whereNull('process_id'); - } else { - $query->where('process_id', $processId); - } + // 기본 조건으로 process_id IS NOT NULL이므로 'none'은 무의미 + if ($processId !== null && $processId !== 'none' && $processId !== '0' && $processId !== 0) { + $query->where('process_id', $processId); } // 공정 코드 필터 (process_code) - 대시보드용 @@ -163,29 +160,29 @@ public function stats(): array { $tenantId = $this->tenantId(); - $counts = WorkOrder::where('tenant_id', $tenantId) + // 실제 작업건만 카운트 (공정 배정 + 보조공정 제외) + $baseQuery = WorkOrder::where('tenant_id', $tenantId) + ->whereNotNull('process_id') + ->where(fn ($q) => $q->whereNull('options->is_auxiliary')->orWhere('options->is_auxiliary', false)); + + $counts = (clone $baseQuery) ->select('status', DB::raw('count(*) as count')) ->groupBy('status') ->pluck('count', 'status') ->toArray(); // 공정별 카운트 (탭 숫자 표시용) - $byProcess = WorkOrder::where('tenant_id', $tenantId) + $byProcess = (clone $baseQuery) ->select('process_id', DB::raw('count(*) as count')) ->groupBy('process_id') ->pluck('count', 'process_id') ->toArray(); $total = array_sum($counts); - $noneCount = $byProcess[''] ?? $byProcess[0] ?? 0; - // null 키는 빈 문자열로 변환되므로 별도 처리 + // process_id IS NOT NULL 기본 필터 적용으로 null 키 처리 불필요 $processedByProcess = []; foreach ($byProcess as $key => $count) { - if ($key === '' || $key === 0 || $key === null) { - $processedByProcess['none'] = $count; - } else { - $processedByProcess[(string) $key] = $count; - } + $processedByProcess[(string) $key] = $count; } return [