app/controllers/admin/store/reports_controller.rb
def inventory_required
    sql = <<-EOF
      select p.id, p.sku, p.name, p.option_title, sum(quantity), s.name, s.id
      from store_order_items oi
      join store_orders o on oi.order_id = o.id
      join store_products p on oi.product_id = p.id
      left join store_label_sheets s on p.label_sheet_id = s.id
      where o.status in ('backordered', 'awaiting_shipment')
      group by oi.product_id
      order by sum(quantity) desc;
    EOF

    @data = []
    ActiveRecord::Base.connection.execute(sql).each { |row| @data << row }

    @inventory = InventoryItem.where(sku: @data.map { |x| x[1] })
                     .group(:sku).select("sku, sum(quantity) as quantity")
  end
# The inventory required to fulfill current open orders
The inventory required to fulfill current open orders
The inventory required to fulfill current open orders
def inventory_required
    sql = <<-EOF
      select p.id, p.sku, p.name, p.option_title, sum(quantity), s.name, s.id
      from store_order_items oi
      join store_orders o on oi.order_id = o.id
      join store_products p on oi.product_id = p.id
      left join store_label_sheets s on p.label_sheet_id = s.id
      where o.status in ('backordered', 'awaiting_shipment')
      group by oi.product_id
      order by sum(quantity) desc;
    EOF
    @data = []
    ActiveRecord::Base.connection.execute(sql).each { |row| @data << row }
    @inventory = InventoryItem.where(sku: @data.map { |x| x[1] })
                     .group(:sku).select("sku, sum(quantity) as quantity")
  end
def inventory_required sql = <<-EOF 
      select p.id, p.sku, p.name, p.option_title, sum(quantity), s.name, s.id
      from store_order_items oi
      join store_orders o on oi.order_id = o.id
      join store_products p on oi.product_id = p.id
      left join store_label_sheets s on p.label_sheet_id = s.id
      where o.status in ('backordered', 'awaiting_shipment')
      group by oi.product_id
      order by sum(quantity) desc;
     EOF @data = [ ] ActiveRecord :: Base . connection . execute ( sql ) . each { | row | @data << row } @inventory = InventoryItem . where ( sku : @data . map { | x | x [ 1 ] } ) . group ( :sku ) . select ( "sku, sum(quantity) as quantity" ) end
The inventory required to fulfill current open orders
The inventory required to fulfill current open orders