SELECT COUNT(DISTINCT p.id) FROM products p LEFT JOIN inventory_levels il ON p.id = il.product_id WHERE p.status = 'active' AND p.reorder_level > 0 AND COALESCE(il.quantity, 0) <= p.reorder_level AND p.deleted_at IS NULL