app/controllers/admin/store/reports_controller.rb
def monthly_sales
    sql = <<-EOF
      select shp.created_at, count(*), sum(o.total)
      from store_shipments shp
      join store_orders o on o.id = shp.order_id
      where shp.created_at > '#{@start_date}' and shp.created_at < '#{@end_date}'
      and o.sales_channel LIKE '#{@selected_channel}'
      #{"and shp.fulfilled_by_id=" + params[:affiliate_id] if params[:affiliate_id].present?}
      group by year(shp.created_at), month(shp.created_at)
      order by date(shp.created_at) desc;
    EOF

    @data = []
    ActiveRecord::Base.connection.execute(sql).each { |row| @data << row }
  end
# Number of orders places each month in the given date range
Number of orders places each month in the given date range
Number of orders places each month in the given date range
def monthly_sales
    sql = <<-EOF
      select shp.created_at, count(*), sum(o.total)
      from store_shipments shp
      join store_orders o on o.id = shp.order_id
      where shp.created_at > '#{@start_date}' and shp.created_at < '#{@end_date}'
      and o.sales_channel LIKE '#{@selected_channel}'
      #{"and shp.fulfilled_by_id=" + params[:affiliate_id] if params[:affiliate_id].present?}
      group by year(shp.created_at), month(shp.created_at)
      order by date(shp.created_at) desc;
    EOF
    @data = []
    ActiveRecord::Base.connection.execute(sql).each { |row| @data << row }
  end
def monthly_sales sql = <<-EOF 
      select shp.created_at, count(*), sum(o.total)
      from store_shipments shp
      join store_orders o on o.id = shp.order_id
      where shp.created_at > ' #{ @start_date } ' and shp.created_at < ' #{ @end_date } '
      and o.sales_channel LIKE ' #{ @selected_channel } '
       #{ "and shp.fulfilled_by_id=" + params [ :affiliate_id ] if params [ :affiliate_id ] . present? } 
      group by year(shp.created_at), month(shp.created_at)
      order by date(shp.created_at) desc;
     EOF @data = [ ] ActiveRecord :: Base . connection . execute ( sql ) . each { | row | @data << row } end
Number of orders places each month in the given date range
Number of orders places each month in the given date range