fixed invetory
This commit is contained in:
@@ -121,7 +121,7 @@ class InventoryDefinition < ApplicationRecord
|
||||
OR mii.item_instance_name LIKE ? OR mc.name LIKE ?","%#{filter}%","%#{filter}%","%#{filter}%",
|
||||
"%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%")
|
||||
.group("mi.menu_category_id,inventory_definitions.item_code")
|
||||
.order("mi.name asc,acc.title desc,mi.menu_category_id desc,balance ASC")
|
||||
.order("balance asc, mi.name asc,acc.title desc,mi.menu_category_id desc")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2974,11 +2974,20 @@ private
|
||||
end
|
||||
|
||||
def update_stock_journal
|
||||
if self.sale_status == "void" && self.sale_status_was != "void"
|
||||
# if self.sale_status == "void"
|
||||
# remark = "void"
|
||||
# elsif self.sale_status == "waste"
|
||||
# remark = "waste"
|
||||
# elsif self.sale_status == "spoile"
|
||||
# remark = "spoile"
|
||||
# elsif self.payment_status == "foc"
|
||||
# remark = "foc"
|
||||
# end
|
||||
self.sale_items.each do |item|
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item)
|
||||
if found
|
||||
stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first
|
||||
if self.sale_status == "void" && self.sale_status_was != "void"
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item)
|
||||
if found
|
||||
stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first
|
||||
unless stock.nil?
|
||||
check_item = StockCheckItem.where('item_code=?', item.item_instance_code).order("id DESC").first
|
||||
StockJournal.add_to_journal(item.item_instance_code, -item.qty, stock.balance, "void", inventory_definition, item.id, StockJournal::SALES_TRANS)
|
||||
@@ -2986,6 +2995,12 @@ private
|
||||
check_item.save
|
||||
end
|
||||
end
|
||||
elsif self.sale_status == "waste"
|
||||
StockJournal.update_stock_journal(item.item_instance_code, "waste")
|
||||
elsif self.sale_status == "spoile"
|
||||
StockJournal.update_stock_journal(item.item_instance_code, "spoile")
|
||||
elsif self.payment_status == "foc" && self.payment_status_was != "foc"
|
||||
StockJournal.update_stock_journal(item.item_instance_code, "foc")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -236,6 +236,13 @@ class SaleItem < ApplicationRecord
|
||||
is_void = self.status == "void" && self.status_was != "void"
|
||||
cancel_void = self.status_was == "void" && self.status.nil?
|
||||
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
|
||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self)
|
||||
if found
|
||||
@@ -251,6 +258,11 @@ class SaleItem < ApplicationRecord
|
||||
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)
|
||||
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
|
||||
|
||||
@@ -66,4 +66,8 @@ class StockCheckItem < ApplicationRecord
|
||||
.order("acc.title desc,mi.menu_category_id desc")
|
||||
return query
|
||||
end
|
||||
|
||||
def self.delete_stock_check_item(item_code)
|
||||
self.where("item_code=?", item_code).delete_all
|
||||
end
|
||||
end
|
||||
|
||||
@@ -72,4 +72,14 @@ class StockJournal < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.update_stock_journal(item_code,remark)
|
||||
stock = self.where("item_code=?", item_code).order("id DESC").first
|
||||
stock.remark = remark
|
||||
stock.save
|
||||
end
|
||||
|
||||
def self.delete_stock_journal(item_code)
|
||||
self.where("item_code=?", item_code).delete_all
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user