id; return [ 'total_shipments' => Shipment::where('business_id', $business_id)->count(), 'pending' => Shipment::where('business_id', $business_id)->whereIn('status', ['draft', 'scheduled'])->count(), 'at_customs' => Shipment::where('business_id', $business_id)->where('status', 'at_customs')->count(), 'in_transit' => Shipment::where('business_id', $business_id)->where('status', 'in_transit')->count(), 'delivered' => Shipment::where('business_id', $business_id)->where('status', 'delivered')->count(), 'customs_pending' => CustomsClearance::where('business_id', $business_id) ->whereNotIn('status', ['cleared', 'released', 'cancelled']) ->count(), 'vehicles' => Vehicle::where('business_id', $business_id)->where('is_active', true)->count(), 'drivers' => Driver::where('business_id', $business_id)->where('is_active', true)->count(), 'carriers' => Carrier::where('business_id', $business_id)->where('is_active', true)->count(), ]; } public function getRecentShipments(Business $business, int $limit = 10) { return Shipment::where('business_id', $business->id) ->with(['contact:id,name', 'driver:id,name', 'vehicle:id,plate_number', 'customsClearance:id,shipment_id,ref_no,status']) ->orderByDesc('created_at') ->limit($limit) ->get(); } }