SQL reporting system for activerecord