shop code
This commit is contained in:
@@ -8,7 +8,7 @@ class InventoryDefinition < ApplicationRecord
|
||||
logger.debug saleObj.sale_items.to_json
|
||||
if !saleObj.nil?
|
||||
saleObj.sale_items.each do |item|
|
||||
found, inventory_definition = find_product_in_inventory(item)
|
||||
found, inventory_definition = find_product_in_inventory(item,saleObj.shop_code)
|
||||
if found
|
||||
check_balance(item,inventory_definition)
|
||||
end
|
||||
@@ -23,7 +23,7 @@ class InventoryDefinition < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_product_in_inventory(item,instance_code)
|
||||
def self.find_product_in_inventory(item,shop_code=nil)
|
||||
# unless instance_code.empty?
|
||||
# instance_code = instance_code.to_s
|
||||
# instance_code[0] = ""
|
||||
@@ -36,16 +36,15 @@ class InventoryDefinition < ApplicationRecord
|
||||
# puts "found prodcut+++++++++++++++++++++++++++++++++++==="
|
||||
# puts prod.to_json
|
||||
# end
|
||||
|
||||
if product = InventoryDefinition.find_by_item_code(item.item_instance_code)
|
||||
if stock_check_item = StockCheckItem.find_by_item_code(item.item_instance_code)
|
||||
if product = InventoryDefinition.find_by_item_code_and_shop_code(item.item_instance_code,shop_code)
|
||||
if stock_check_item = StockCheckItem.find_by_item_code_and_shop_code(item.item_instance_code,shop_code)
|
||||
return true, product
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_balance(item, inventory_definition) # item => saleItemOBj
|
||||
stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first
|
||||
stock = StockJournal.where("shop_code='#{inventory_definition.shop_code}' and item_code=?", item.item_instance_code).order("id DESC").first
|
||||
unless stock.nil?
|
||||
modify_balance(item, stock, inventory_definition)
|
||||
else
|
||||
@@ -94,7 +93,7 @@ class InventoryDefinition < ApplicationRecord
|
||||
.order("mi.menu_category_id desc")
|
||||
end
|
||||
|
||||
def self.get_by_category(filter)
|
||||
def self.get_by_category(shop,filter)
|
||||
# THEN (SELECT min(balance) FROM stock_journals
|
||||
# least_stock = "SELECT (CASE WHEN stock_journals.remark != 'out of stock'
|
||||
# THEN (SELECT balance FROM stock_journals
|
||||
@@ -123,9 +122,9 @@ class InventoryDefinition < ApplicationRecord
|
||||
" JOIN menu_items mi ON mi.id = mii.menu_item_id" +
|
||||
" JOIN menu_categories mc ON mc.id = mi.menu_category_id ")
|
||||
.joins(" JOIN accounts acc ON acc.id = mi.account_id")
|
||||
.where("inventory_definitions.item_code LIKE ? OR inventory_definitions.min_order_level LIKE ?
|
||||
.where("inventory_definitions.shop_code='#{shop.shop_code}' and (inventory_definitions.item_code LIKE ? OR inventory_definitions.min_order_level LIKE ?
|
||||
OR inventory_definitions.max_stock_level LIKE ? OR sj.balance LIKE ? OR mi.name LIKE ?
|
||||
OR mii.item_instance_name LIKE ? OR mc.name LIKE ?","%#{filter}%","%#{filter}%","%#{filter}%",
|
||||
OR mii.item_instance_name LIKE ? OR mc.name LIKE ?)","%#{filter}%","%#{filter}%","%#{filter}%",
|
||||
"%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%")
|
||||
.group("mi.menu_category_id,inventory_definitions.item_code")
|
||||
.order("balance asc, mi.name asc,acc.title desc,mi.menu_category_id desc")
|
||||
|
||||
Reference in New Issue
Block a user