fixed inventory
This commit is contained in:
@@ -1,44 +1,35 @@
|
||||
class StockJournal < ApplicationRecord
|
||||
|
||||
SALES_TRANS = "sale"
|
||||
ORDER_TRANS = "order"
|
||||
STOCK_CHECK_TRANS = "stock_check"
|
||||
|
||||
def self.add_to_journal(item, balance, stock_message, inventory_definition) # item => saleObj | balance => Stock journal
|
||||
journal = StockJournal.new
|
||||
if item.qty < 0
|
||||
credit_balance = item.qty.abs.to_i
|
||||
debit = 0
|
||||
def self.add_to_journal(item_instance_code, qty, old_balance, stock_message, inventory_definition, trans_ref, trans_type) # item => saleObj | balance => Stock journal
|
||||
|
||||
balance = calculate_balance(old_balance, qty)
|
||||
|
||||
if balance < old_balance
|
||||
credit = 0
|
||||
debit = qty.abs
|
||||
else
|
||||
credit_balance = balance
|
||||
debit = item.qty
|
||||
credit = qty.abs
|
||||
debit = 0
|
||||
end
|
||||
|
||||
journal.credit = credit_balance
|
||||
balance = calculate_balance(balance, item)
|
||||
|
||||
journal.item_code = item.item_instance_code
|
||||
journal.inventory_definition_id = inventory_definition.id
|
||||
journal.debit = debit
|
||||
journal.balance = balance
|
||||
journal.remark = stock_message
|
||||
journal.trans_ref = item.id
|
||||
journal.trans_type = StockJournal::SALES_TRANS
|
||||
journal.save
|
||||
|
||||
|
||||
|
||||
journal = StockJournal.create(
|
||||
item_code: item_instance_code,
|
||||
credit: credit,
|
||||
debit: debit,
|
||||
balance: balance,
|
||||
inventory_definition_id: inventory_definition.id,
|
||||
remark: stock_message,
|
||||
trans_ref: trans_ref,
|
||||
trans_type: trans_type
|
||||
)
|
||||
end
|
||||
|
||||
def self.calculate_balance(balance, item)
|
||||
if item.product_name.downcase.include?("void")
|
||||
logger.debug 'balance++++++++++++++++++'
|
||||
logger.debug balance
|
||||
logger.debug 'qty+++++++++++++++++++++++'
|
||||
logger.debug item.qty
|
||||
return balance.to_i + item.qty.abs.to_i
|
||||
else
|
||||
return balance.to_i - item.qty.to_i
|
||||
end
|
||||
def self.calculate_balance(balance, qty)
|
||||
return balance.to_i - qty.to_i
|
||||
end
|
||||
|
||||
def self.from_stock_check(item)
|
||||
|
||||
Reference in New Issue
Block a user