fixed inventroy item balance

This commit is contained in:
NyanLinHtut
2020-02-24 18:16:20 +06:30
parent 306b430299
commit 06647b3917

View File

@@ -82,7 +82,9 @@ class InventoryDefinition < ApplicationRecord
end
def self.get_by_category(filter)
least_stock = StockJournal.select(:balance).joins("JOIN inventory_definitions ON stock_journals.item_code = inventory_definitions.item_code").order(:id => :desc).limit(1).to_sql
least_stock = StockJournal.select(:balance)
.where('stock_journals.updated_at = (SELECT MAX(stock_journals.updated_at) FROM stock_journals WHERE (stock_journals.item_code = inventory_definitions.item_code))')
.order(:id => :desc).to_sql
@inventory_definitions = InventoryDefinition.select("inventory_definitions.*,
(CASE WHEN sj.credit IS NULL THEN 0 ELSE sj.credit END) as credit,