Inventory Issue
This commit is contained in:
@@ -4,8 +4,6 @@ class InventoryDefinition < ApplicationRecord
|
|||||||
|
|
||||||
def self.calculate_product_count(saleObj=nil,saleobj_after_req_bill=nil)
|
def self.calculate_product_count(saleObj=nil,saleobj_after_req_bill=nil)
|
||||||
if !saleObj.nil?
|
if !saleObj.nil?
|
||||||
Rails.logger.debug "Hello count"
|
|
||||||
Rails.logger.debug saleObj.sale_items.count
|
|
||||||
saleObj.sale_items.each do |item|
|
saleObj.sale_items.each do |item|
|
||||||
found, inventory_definition = find_product_in_inventory(item)
|
found, inventory_definition = find_product_in_inventory(item)
|
||||||
if found
|
if found
|
||||||
@@ -37,7 +35,7 @@ class InventoryDefinition < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.check_balance(item,inventory_definition) # item => saleItemOBj
|
def self.check_balance(item,inventory_definition) # item => saleItemOBj
|
||||||
stock = StockJournal.where('item_code=?', item.item_instance_code).last
|
stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first
|
||||||
unless stock.nil?
|
unless stock.nil?
|
||||||
modify_balance(item, stock, inventory_definition)
|
modify_balance(item, stock, inventory_definition)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ class Sale < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
def generate_invoice_from_booking(booking_id, requested_by, cashier, order_source = nil, current_checkin_induties_count)
|
def generate_invoice_from_booking(booking_id, requested_by, cashier, order_source = nil, current_checkin_induties_count)
|
||||||
|
saleObj =''
|
||||||
booking = Booking.find(booking_id)
|
booking = Booking.find(booking_id)
|
||||||
status = false
|
status = false
|
||||||
Rails.logger.debug "Booking -> " + booking.id.to_s
|
Rails.logger.debug "Booking -> " + booking.id.to_s
|
||||||
@@ -71,13 +72,17 @@ class Sale < ApplicationRecord
|
|||||||
#get all order attached to this booking and combine into 1 invoice
|
#get all order attached to this booking and combine into 1 invoice
|
||||||
|
|
||||||
booking.booking_orders.each do |order|
|
booking.booking_orders.each do |order|
|
||||||
|
# puts "Hello order"
|
||||||
if booking.sale_id
|
if booking.sale_id
|
||||||
status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by, cashier, order_source)
|
status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by, cashier, order_source)
|
||||||
else
|
else
|
||||||
status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by, cashier, order_source)
|
status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by, cashier, order_source)
|
||||||
end
|
end
|
||||||
booking.sale_id = sale_id
|
booking.sale_id = sale_id
|
||||||
|
saleObj = Sale.find(sale_id)
|
||||||
end
|
end
|
||||||
|
# InventoryJob.perform_now(self.id)
|
||||||
|
InventoryDefinition.calculate_product_count(saleObj)
|
||||||
|
|
||||||
order = booking.booking_orders.take.order
|
order = booking.booking_orders.take.order
|
||||||
link_order_sale(order.id)
|
link_order_sale(order.id)
|
||||||
@@ -225,7 +230,7 @@ class Sale < ApplicationRecord
|
|||||||
|
|
||||||
# InventoryJob.perform_now(self.id)
|
# InventoryJob.perform_now(self.id)
|
||||||
saleObj = Sale.find(self.id)
|
saleObj = Sale.find(self.id)
|
||||||
InventoryDefinition.calculate_product_count(saleObj)
|
# InventoryDefinition.calculate_product_count(saleObj)
|
||||||
|
|
||||||
return true, self.id
|
return true, self.id
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user