Created
March 2, 2018 21:53
-
-
Save jeremiahlukus/040a9b40be1d7822d2988e2c10fd50f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@products = Product.by_company(current_user.company.slug).includes(:facilities, :total_stocks).distinct(:sku) | |
sql = "SELECT DISTINCT ON (product_id) * FROM facility_stocks WHERE product_id IN (#{@products.pluck(:id).join(', ')}) ORDER BY product_id, created_at DESC" | |
@facility_stocks = ActiveRecord::Base.connection.execute(sql) | |
in view | |
<td><%= @facility_stocks.select { |h| h['facility_id' ] == facility.id}.map { |h| h['pallet_quantity'] }.sum %></td> | |
<td><%= @facility_stocks.select { |h| h['facility_id' ] == facility.id}.map { |h| h['case_quantity'] }.sum %></td> | |
<td><%= @facility_stocks.select { |h| h['facility_id' ] == facility.id}.map { |h| h['item_quantity'] }.sum %></td> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment