fixed inventory
This commit is contained in:
@@ -8,7 +8,7 @@ class StockJournal < ApplicationRecord
|
||||
journal.credit = balance
|
||||
|
||||
balance = calculate_balance(balance, item.qty)
|
||||
|
||||
|
||||
journal.item_code = item.item_instance_code
|
||||
journal.inventory_definition_id = inventory_definition.id
|
||||
journal.debit = item.qty
|
||||
@@ -24,13 +24,19 @@ class StockJournal < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.from_stock_check(item)
|
||||
stock_journal = StockJournal.where('item_code=?', item.item_code).order("id DESC").first
|
||||
if stock_journal.nil?
|
||||
old_blance = 0
|
||||
else
|
||||
old_blance = stock_journal.balance
|
||||
end
|
||||
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.debit = 0
|
||||
journal.credit = item.stock_count
|
||||
journal.balance = 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
|
||||
@@ -43,7 +49,7 @@ class StockJournal < ApplicationRecord
|
||||
.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
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user