fixed inventory
This commit is contained in:
@@ -238,35 +238,43 @@ class SaleItem < ApplicationRecord
|
||||
is_edit = self.qty >= 0 && self.qty != self.qty_was
|
||||
is_foc = self.status == "foc" && self.status_was != "foc"
|
||||
cancel_foc = self.status_was == "foc"
|
||||
if is_foc
|
||||
StockJournal.update_stock_journal(self.item_instance_code, "foc")
|
||||
elsif cancel_foc
|
||||
StockJournal.update_stock_journal(self.item_instance_code, "cancel_foc")
|
||||
end
|
||||
if is_void or cancel_void or is_edit
|
||||
# if is_foc
|
||||
# StockJournal.update_stock_journal(self.item_instance_code, "foc")
|
||||
# else cancel_foc
|
||||
# StockJournal.update_stock_journal(self.item_instance_code, "cancel_foc")
|
||||
# end
|
||||
if is_void or cancel_void or is_edit or is_foc or cancel_foc
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self)
|
||||
if found
|
||||
stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first
|
||||
unless stock.nil?
|
||||
check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first
|
||||
if is_void
|
||||
qty = -self.qty
|
||||
remark = "void"
|
||||
elsif cancel_void
|
||||
qty = self.qty
|
||||
remark = "cancel void"
|
||||
elsif is_edit
|
||||
qty = self.qty - self.qty_was
|
||||
remark = "edit"
|
||||
# elsif is_foc
|
||||
# logger.debug 'foc++++++++++++++++++++++++++++'
|
||||
# logger.debug is_foc
|
||||
# remark = "foc"
|
||||
# StockJournal.update_stock_journal(self.item_instance_code, remark)
|
||||
if is_void or cancel_void or is_edit
|
||||
if is_void
|
||||
qty = -self.qty
|
||||
remark = "void"
|
||||
elsif cancel_void
|
||||
qty = self.qty
|
||||
remark = "cancel void"
|
||||
elsif is_edit
|
||||
qty = self.qty - self.qty_was
|
||||
remark = "edit"
|
||||
end
|
||||
StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS)
|
||||
check_item.different = check_item.different + qty
|
||||
check_item.save
|
||||
else is_foc or cancel_foc
|
||||
qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit")
|
||||
if order_item_id = self.sale.bookings.first.order_items.where(item_instance_code: self.item_instance_code, qty: self.qty + qty).select(:order_items_id).first.order_items_id
|
||||
if stock_journal = StockJournal.find_by_trans_ref(order_item_id)
|
||||
if is_foc
|
||||
stock_journal.update(remark: "foc")
|
||||
elsif cancel_foc
|
||||
stock_journal.update(remark: "cancel_foc")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS)
|
||||
check_item.different = check_item.different + qty
|
||||
check_item.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user