fixed inventory
This commit is contained in:
@@ -7,14 +7,14 @@ class Inventory::InventoryController < BaseInventoryController
|
||||
@inventory_definitions = InventoryDefinition.get_by_category(filter)
|
||||
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
inventory_definition_id = params[:inventory_definition_id]
|
||||
inventory = InventoryDefinition.find(inventory_definition_id)
|
||||
|
||||
@stock_journals = StockJournal.where(item_code: inventory.item_code)
|
||||
@stock_journals = StockJournal.where(item_code: inventory.item_code).order("id DESC")
|
||||
@stock_journals = Kaminari.paginate_array(@stock_journals).page(params[:page]).per(20)
|
||||
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xls
|
||||
|
||||
@@ -180,7 +180,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
else
|
||||
sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user)
|
||||
end
|
||||
|
||||
|
||||
# end
|
||||
|
||||
if !path.include? ("credit_payment")
|
||||
@@ -304,6 +304,12 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
|
||||
#end
|
||||
end
|
||||
logger.debug 'saleObj++++++++++++++++++++++++++'
|
||||
logger.debug saleObj.to_json
|
||||
if !saleObj.nil?
|
||||
# InventoryJob.perform_now(self.id)
|
||||
InventoryDefinition.calculate_product_count(saleObj)
|
||||
end
|
||||
end
|
||||
|
||||
# status, filename, sale_receipt_no, printer_name = Payment.pay(getCloudDomain, cash, sale_id, member_info, type, tax_type, path, latest_order_no, shop_detail, current_user, nil, nil)
|
||||
@@ -741,6 +747,10 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
end
|
||||
end
|
||||
# end
|
||||
if !saleObj.nil?
|
||||
#InventoryJob.perform_now(self.id)
|
||||
InventoryDefinition.calculate_product_count(saleObj)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ class Origami::SalesController < BaseOrigamiController
|
||||
def show
|
||||
@webview = false
|
||||
if check_mobile
|
||||
@webview = true
|
||||
@webview = true
|
||||
end
|
||||
|
||||
|
||||
@tables = Table.unscoped.all.active.order('status desc')
|
||||
@rooms = Room.unscoped.all.active.order('status desc')
|
||||
@complete = Sale.completed_sale("cashier")
|
||||
@@ -36,7 +36,7 @@ class Origami::SalesController < BaseOrigamiController
|
||||
if booking.sale_id.nil?
|
||||
order_array = []
|
||||
booking.booking_orders.each do |booking_order|
|
||||
|
||||
|
||||
booking.booking_status = 'moved'
|
||||
order = Order.find(booking_order.order_id)
|
||||
order.status = 'billed'
|
||||
@@ -60,16 +60,16 @@ class Origami::SalesController < BaseOrigamiController
|
||||
booking.save
|
||||
|
||||
order_array.push(order.order_id)
|
||||
|
||||
|
||||
end
|
||||
|
||||
receipt_no = Sale.find(sale_id).receipt_no
|
||||
action_by = current_user.name
|
||||
type = "ADD_TO_EXISTING"
|
||||
|
||||
|
||||
remark = "#{action_by} add to existing order #{order_array} to Receipt No=>#{receipt_no} in #{table.name}"
|
||||
sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type )
|
||||
|
||||
|
||||
booking_order = BookingOrder.where('booking_id=?',booking)
|
||||
booking_order.each do |bo|
|
||||
bo.booking_id = existing_booking.booking_id
|
||||
@@ -77,9 +77,9 @@ class Origami::SalesController < BaseOrigamiController
|
||||
end
|
||||
end
|
||||
end
|
||||
if !sale_data.empty?
|
||||
# if !sale_data.empty?
|
||||
# InventoryJob.perform_now(self.id)
|
||||
InventoryDefinition.calculate_product_count(nil,sale_data)
|
||||
# InventoryDefinition.calculate_product_count(nil,sale_data)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -44,27 +44,69 @@ class InventoryDefinition < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.modify_balance(item, stock, inventory_definition) #saleitemObj
|
||||
void_qty = 0
|
||||
if item.product_name.downcase.include?("void")
|
||||
void_qty = item.qty.abs.to_i
|
||||
end
|
||||
check_item = StockCheckItem.where('item_code=?', item.item_instance_code).order("id DESC").first
|
||||
if stock.balance.to_i >= item.qty
|
||||
puts ">> stock is greater than order qty"
|
||||
StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition)
|
||||
check_item.different = check_item.different - item.qty
|
||||
check_item.save
|
||||
if item.qty.to_i > 0
|
||||
StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition)
|
||||
if !void_qty.nil? | void_qty != 0
|
||||
check_item.different = check_item.different - item.qty
|
||||
check_item.save
|
||||
end
|
||||
else
|
||||
if item.product_name.downcase.include?("void")
|
||||
StockJournal.add_to_journal(item, stock.balance, "void", inventory_definition)
|
||||
check_item.different = check_item.different + void_qty
|
||||
check_item.save
|
||||
end
|
||||
end
|
||||
else
|
||||
puts " << stock is less than order qty"
|
||||
data = item
|
||||
extra_qty = item.qty.to_i - stock.balance.to_i
|
||||
if stock.balance.to_i > 0
|
||||
item.qty = stock.balance.to_i
|
||||
StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition)
|
||||
data.qty = extra_qty
|
||||
StockJournal.add_to_journal(data, 0, "out of stock", inventory_definition)
|
||||
check_item.different = check_item.different - item.qty
|
||||
check_item.save
|
||||
if item.qty.to_i > 0
|
||||
StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition)
|
||||
check_item.different = check_item.different - item.qty
|
||||
check_item.save
|
||||
data.qty = extra_qty
|
||||
StockJournal.add_to_journal(data, 0, "out of stock", inventory_definition)
|
||||
if !void_qty.nil? | void_qty != 0
|
||||
check_item.different = check_item.different - item.qty
|
||||
check_item.save
|
||||
else
|
||||
check_item.different = check_item.different + void_qty
|
||||
check_item.save
|
||||
end
|
||||
else
|
||||
if item.product_name.downcase.include?("void")
|
||||
StockJournal.add_to_journal(item, stock.balance, "void", inventory_definition)
|
||||
check_item.different = check_item.different + void_qty
|
||||
check_item.save
|
||||
end
|
||||
end
|
||||
else
|
||||
StockJournal.add_to_journal(item, stock.balance, "out of stock", inventory_definition)
|
||||
check_item.different = check_item.different - item.qty
|
||||
check_item.save
|
||||
if item.qty.to_i > 0
|
||||
StockJournal.add_to_journal(item, stock.balance, "out of stock", inventory_definition)
|
||||
if !void_qty.nil? | void_qty != 0
|
||||
check_item.different = check_item.different - item.qty
|
||||
check_item.save
|
||||
else
|
||||
check_item.different = check_item.different + void_qty
|
||||
check_item.save
|
||||
end
|
||||
else
|
||||
if item.product_name.downcase.include?("void")
|
||||
StockJournal.add_to_journal(item, stock.balance, "void", inventory_definition)
|
||||
check_item.different = check_item.different + void_qty
|
||||
check_item.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -93,7 +135,7 @@ class InventoryDefinition < ApplicationRecord
|
||||
# ORDER BY stock_journals.created_at DESC LIMIT 1"
|
||||
least_stock = "(SELECT
|
||||
(SELECT balance FROM stock_journals WHERE item_code = inventory_definitions.item_code
|
||||
ORDER BY created_at DESC LIMIT 1)
|
||||
ORDER BY id DESC LIMIT 1)
|
||||
FROM stock_journals
|
||||
WHERE stock_journals.item_code = inventory_definitions.item_code
|
||||
ORDER BY stock_journals.created_at DESC LIMIT 1)"
|
||||
|
||||
@@ -84,7 +84,7 @@ class Sale < ApplicationRecord
|
||||
link_order_sale(order.order_id)
|
||||
end
|
||||
# InventoryJob.perform_now(self.id)
|
||||
InventoryDefinition.calculate_product_count(saleObj)
|
||||
# InventoryDefinition.calculate_product_count(saleObj)
|
||||
|
||||
|
||||
|
||||
@@ -489,7 +489,7 @@ class Sale < ApplicationRecord
|
||||
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax
|
||||
sale.grand_total_round
|
||||
end
|
||||
|
||||
|
||||
if discount_type == "member_discount"
|
||||
sale.discount_type = discount_type
|
||||
end
|
||||
|
||||
@@ -2,11 +2,12 @@ class StockCheckItem < ApplicationRecord
|
||||
belongs_to :stock_check
|
||||
|
||||
def create(stock_id, item)
|
||||
check_item = StockCheckItem.find_by_item_code(item['sku'])
|
||||
# check_item = StockCheckItem.find_by_item_code(item['sku'])
|
||||
check_item = StockCheckItem.where('item_code=?', item_code).order("id DESC").first
|
||||
if check_item.nil?
|
||||
balance = 0
|
||||
else
|
||||
balance = StockCheckItem.last.different
|
||||
balance = check_item.different
|
||||
end
|
||||
journal_id = StockCheckItem.find_journal(item['sku'])
|
||||
remark, different = StockCheckItem.stock_different(item['qty'], balance )
|
||||
|
||||
@@ -5,22 +5,40 @@ class StockJournal < ApplicationRecord
|
||||
|
||||
def self.add_to_journal(item, balance, stock_message, inventory_definition) # item => saleObj | balance => Stock journal
|
||||
journal = StockJournal.new
|
||||
journal.credit = balance
|
||||
if item.qty < 0
|
||||
credit_balance = item.qty.abs.to_i
|
||||
debit = 0
|
||||
else
|
||||
credit_balance = balance
|
||||
debit = item.qty
|
||||
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
|
||||
|
||||
|
||||
balance = calculate_balance(balance, item.qty)
|
||||
|
||||
journal.item_code = item.item_instance_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
|
||||
journal.save
|
||||
end
|
||||
|
||||
def self.calculate_balance(balance, qty)
|
||||
return balance.to_i - qty.to_i
|
||||
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
|
||||
end
|
||||
|
||||
def self.from_stock_check(item)
|
||||
|
||||
Reference in New Issue
Block a user