inventory development
This commit is contained in:
@@ -1,2 +1,39 @@
|
||||
class InventoryDefinition < ApplicationRecord
|
||||
|
||||
scope :active, -> {where(:is_active => true)}
|
||||
|
||||
def calculate_product_count(saleObj)
|
||||
saleObj.sale_items.each do |item|
|
||||
found, inventory_definition = find_product_in_inventory(item)
|
||||
if found
|
||||
check_balance(item,inventory_definition)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_product_in_inventory(item)
|
||||
product = InventoryDefinition.find_by_item_code(item.product_code)
|
||||
if product.nil?
|
||||
return false, nil
|
||||
else
|
||||
return true, product
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_balance(item,inventory_definition)
|
||||
stock = StockJournal.where('item_code=?', item.item_code).order('created_at desc').take
|
||||
unless stock.nil?
|
||||
modify_balance(item, stock.balance, inventory_definition)
|
||||
end
|
||||
end
|
||||
|
||||
def self.modify_balance(item, stock_balance, inventory_definition)
|
||||
if stock.balance.to_i >= item.qty
|
||||
puts ">> stock is greater than orde qty"
|
||||
add_to_journal(item, balance, "ok", inventory_definition)
|
||||
else
|
||||
puts " << stock is less than order qty"
|
||||
add_to_journal(item, balance, "out of stock", inventory_definition)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -117,6 +117,7 @@ class Sale < ApplicationRecord
|
||||
create_saleitem_diningcharges(charges, diningprice, booking.dining_facility.name, dining_time)
|
||||
end
|
||||
|
||||
InventoryJob.perform_later(self.id)
|
||||
return true, self.id
|
||||
end
|
||||
|
||||
|
||||
@@ -1,2 +1,24 @@
|
||||
class StockJournal < ApplicationRecord
|
||||
|
||||
SALES_TRANS = "sale"
|
||||
STOCK_CHECK_TRANS = "stock_check"
|
||||
|
||||
def add_to_journal(item, balance, stock_message, inventory_definition)
|
||||
|
||||
balance = calculate_balance(balance, item.qty)
|
||||
|
||||
journal = StockJournal.new
|
||||
journal.item_code = item.item_code
|
||||
journal.inventory_definition_id = inventory_definition.id
|
||||
journal.debit = item.qty
|
||||
journal.balance = balance
|
||||
journal.remark = stock_message
|
||||
journal.trans_ref = item.id
|
||||
journal.trans_type = StockJournal::SALES_TRANS
|
||||
end
|
||||
|
||||
def self.calculate_balance(balance, qty)
|
||||
return balance.to_i - qty.to_i
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user