diff --git a/app/Services/ShipmentService.php b/app/Services/ShipmentService.php index b6c1e073..2556da19 100644 --- a/app/Services/ShipmentService.php +++ b/app/Services/ShipmentService.php @@ -20,7 +20,9 @@ public function index(array $params): LengthAwarePaginator $query = Shipment::query() ->where('tenant_id', $tenantId) - ->with(['items', 'vehicleDispatches', 'order.client', 'order.writer', 'workOrder', 'creator']); + ->with(['items', 'vehicleDispatches', 'order.client', 'order.writer', 'workOrder', 'creator']) + // 재공품(STOCK) 수주의 출고는 목록에서 제외 + ->whereDoesntHave('order', fn ($q) => $q->where('order_type_code', 'STOCK')); // 검색어 필터 if (! empty($params['search'])) { @@ -84,30 +86,34 @@ public function stats(): array { $tenantId = $this->tenantId(); - $total = Shipment::where('tenant_id', $tenantId)->count(); + // 재공품(STOCK) 수주 제외 base query + $base = fn () => Shipment::where('tenant_id', $tenantId) + ->whereDoesntHave('order', fn ($q) => $q->where('order_type_code', 'STOCK')); - $scheduled = Shipment::where('tenant_id', $tenantId) + $total = $base()->count(); + + $scheduled = $base() ->where('status', 'scheduled') ->count(); - $ready = Shipment::where('tenant_id', $tenantId) + $ready = $base() ->where('status', 'ready') ->count(); - $shipping = Shipment::where('tenant_id', $tenantId) + $shipping = $base() ->where('status', 'shipping') ->count(); - $completed = Shipment::where('tenant_id', $tenantId) + $completed = $base() ->where('status', 'completed') ->count(); - $urgent = Shipment::where('tenant_id', $tenantId) + $urgent = $base() ->where('priority', 'urgent') ->whereIn('status', ['scheduled', 'ready']) ->count(); - $todayScheduled = Shipment::where('tenant_id', $tenantId) + $todayScheduled = $base() ->whereDate('scheduled_date', now()) ->count();