Query builder and reporting engine