shop code
This commit is contained in:
@@ -24,7 +24,8 @@ class StockJournal < ApplicationRecord
|
||||
inventory_definition_id: inventory_definition.id,
|
||||
remark: stock_message,
|
||||
trans_ref: trans_ref,
|
||||
trans_type: trans_type
|
||||
trans_type: trans_type,
|
||||
shop_code: inventory_definition.shop_code
|
||||
)
|
||||
end
|
||||
|
||||
@@ -32,41 +33,44 @@ class StockJournal < ApplicationRecord
|
||||
return balance.to_i - qty.to_i
|
||||
end
|
||||
|
||||
def self.from_stock_check(item)
|
||||
stock_journal = StockJournal.where('item_code=?', item.item_code).order("id DESC").first
|
||||
def self.from_stock_check(item,shop)
|
||||
stock_journal = StockJournal.where("shop_code='#{shop.shop_code}' and item_code=?", item.item_code).order("id DESC").first
|
||||
if stock_journal.nil?
|
||||
old_blance = 0
|
||||
inventory_definition_id = InventoryDefinition.find_by_item_code_and_shop_code(item.item_code,shop.shop_code).id
|
||||
else
|
||||
old_blance = stock_journal.balance
|
||||
inventory_definition_id = stock_journal.inventory_definition_id
|
||||
end
|
||||
definition_id = InventoryDefinition.find_by_item_code(item.item_code)
|
||||
# definition_id = InventoryDefinition.find_by_item_code(item.item_code)
|
||||
journal = StockJournal.new
|
||||
journal.item_code = item.item_code
|
||||
journal.inventory_definition_id = definition_id.id
|
||||
journal.inventory_definition_id = inventory_definition_id
|
||||
journal.debit = 0
|
||||
journal.credit = item.stock_count
|
||||
journal.balance = item.stock_count + old_blance.to_i
|
||||
journal.remark = StockJournal::STOCK_CHECK_TRANS
|
||||
journal.trans_ref = item.id
|
||||
journal.trans_type = StockJournal::STOCK_CHECK_TRANS
|
||||
journal.shop_code = shop.shop_code
|
||||
journal.save
|
||||
end
|
||||
|
||||
def self.inventory_balances(today,from,to,from_time,to_time,shop)
|
||||
if !from.nil? && !to.nil?
|
||||
query = shop.stock_journals.select("mii.item_instance_name as item_instance_name,balance")
|
||||
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")
|
||||
.joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code")
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'")
|
||||
else
|
||||
query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'")
|
||||
end
|
||||
query = query.group("mii.item_instance_name")
|
||||
query = query.where("shop_code='#{shop.shop_code}'").group("mii.item_instance_name")
|
||||
.order("mii.item_instance_name ASC")
|
||||
else
|
||||
query = shop.stock_journals.select("mii.item_instance_name as item_instance_name,balance")
|
||||
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")
|
||||
.joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code")
|
||||
.where("DATE_FORMAT(stock_journals.created_at,'%Y-%m-%d') = '#{today}'")
|
||||
.where("shop_code='#{shop.shop_code}' and DATE_FORMAT(stock_journals.created_at,'%Y-%m-%d') = '#{today}'")
|
||||
.group("mii.item_instance_name")
|
||||
.order("mii.item_instance_name ASC")
|
||||
end
|
||||
@@ -81,8 +85,8 @@ class StockJournal < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.delete_stock_journal(item_code)
|
||||
self.where("item_code=?", item_code).delete_all
|
||||
def self.delete_stock_journal(item_code,shop)
|
||||
self.where("item_code=? and shop_code='#{shop.shop_code}'", item_code).delete_all
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user