Files
sx-fc/app/controllers/inventory/inventory_controller.rb
2018-08-16 15:49:20 +06:30

32 lines
1.2 KiB
Ruby
Executable File

class Inventory::InventoryController < BaseInventoryController
load_and_authorize_resource
def index
@inventory_definitions = InventoryDefinition.select("inventory_definitions.*,
(CASE WHEN sj.credit IS NULL THEN '-' ELSE sj.credit END) as credit,
(CASE WHEN sj.debit IS NULL THEN '-' ELSE sj.debit END) as debit,
(CASE WHEN sj.balance IS NULL THEN '-' ELSE sj.balance END) as balance")
.joins(" LEFT JOIN stock_journals sj ON sj.inventory_definition_id=inventory_definitions.id")
.where("(CASE WHEN sj.balance > 0 THEN sj.balance=(SELECT MIN(balance) FROM stock_journals WHERE stock_journals.item_code = inventory_definitions.item_code ORDER BY created_at DESC) ELSE 1 END)")
.group("inventory_definitions.item_code")
.order("(CASE WHEN sj.balance > 0 THEN MIN(sj.balance) ELSE NULL END )")
end
def show
inventory_definition_id = params[:inventory_definition_id]
inventory = InventoryDefinition.find(inventory_definition_id)
@stock_journals = StockJournal.where(item_code: inventory.item_code)
respond_to do |format|
format.html
format.xls
end
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
end