Merge branch 'r-1902001-01-dev' of gitlab.com:code2lab/SXRestaurant into r-1902001-01-dev
This commit is contained in:
@@ -361,8 +361,8 @@ class Sale < ApplicationRecord
|
||||
sale_item.save
|
||||
|
||||
# Re-calc
|
||||
sale = Sale.find(self.id)
|
||||
self.compute_by_sale_items(self.id, sale.sale_items, self.total_discount, nil, order_source)
|
||||
self.sale_items << sale_item
|
||||
self.compute_by_sale_items(self.total_discount, nil, order_source)
|
||||
end
|
||||
def create_saleitem_indutycharges(chargeObj, current_checkin_induties_count, induties_pay_amount, dining_name, dining_time, order_source = nil, basic_pay_amount)
|
||||
sale_item = SaleItem.new
|
||||
@@ -380,8 +380,8 @@ class Sale < ApplicationRecord
|
||||
sale_item.price = induties_pay_amount
|
||||
sale_item.save
|
||||
# Re-calc
|
||||
sale = Sale.find(self.id)
|
||||
self.compute_by_sale_items(self.id, sale.sale_items, self.total_discount, nil, order_source)
|
||||
self.sale_items << sale_item
|
||||
self.compute_by_sale_items(self.total_discount, nil, order_source)
|
||||
end
|
||||
def update_item (item)
|
||||
#save sale_audit
|
||||
@@ -403,14 +403,12 @@ class Sale < ApplicationRecord
|
||||
|
||||
#compute - invoice total
|
||||
def compute(order_source = nil, tax_type = nil)
|
||||
sales_items = self.sale_items
|
||||
|
||||
#Computation Fields
|
||||
subtotal_price = 0
|
||||
total_taxable = 0
|
||||
rounding_adjustment = 0
|
||||
|
||||
sales_items.each do |item|
|
||||
self.sale_items.each do |item|
|
||||
#compute each item and added to total
|
||||
subtotal_price = subtotal_price + item.price
|
||||
|
||||
@@ -429,60 +427,54 @@ class Sale < ApplicationRecord
|
||||
# self.grand_total_round
|
||||
#compute rounding adjustment
|
||||
# adjust_rounding
|
||||
|
||||
self.save!
|
||||
|
||||
end
|
||||
|
||||
#compute - invoice total
|
||||
def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil,tax_type=nil,type=nil)
|
||||
def compute_by_sale_items(total_discount, discount_type=nil, order_source=nil, tax_type=nil, type=nil)
|
||||
shop = Shop.first
|
||||
sale = Sale.find(sale_id)
|
||||
sales_items = sale_itemss
|
||||
|
||||
#Computation Fields
|
||||
subtotal_price = 0
|
||||
total_taxable = 0
|
||||
rounding_adjustment = 0
|
||||
|
||||
sales_items.each do |item|
|
||||
self.sale_items.each do |item|
|
||||
#compute each item and added to total
|
||||
subtotal_price = subtotal_price + item.price
|
||||
subtotal_price = subtotal_price + item.price
|
||||
|
||||
# check for item is taxable and calculate
|
||||
if item.is_taxable
|
||||
total_taxable = total_taxable + item.taxable_price
|
||||
end
|
||||
end
|
||||
compute_tax(sale, total_taxable, total_discount, order_source, tax_type)
|
||||
sale.total_amount = subtotal_price
|
||||
sale.total_discount = total_discount
|
||||
|
||||
compute_tax(total_taxable, total_discount, order_source, tax_type)
|
||||
self.total_amount = subtotal_price
|
||||
self.total_discount = total_discount
|
||||
if type =="foc"
|
||||
sale.grand_total = 0
|
||||
self.grand_total = 0
|
||||
else
|
||||
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax
|
||||
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
|
||||
# sale.grand_total_round
|
||||
end
|
||||
|
||||
if discount_type == "member_discount"
|
||||
sale.discount_type = discount_type
|
||||
self.discount_type = discount_type
|
||||
end
|
||||
#compute rounding adjustment
|
||||
# adjust_rounding
|
||||
|
||||
sale.save!
|
||||
self.save!
|
||||
end
|
||||
|
||||
# No Use too many wrong
|
||||
def compute_without_void(order_source = nil)
|
||||
sales_items = self.sale_items
|
||||
|
||||
#Computation Fields
|
||||
subtotal_price = 0
|
||||
total_taxable = 0
|
||||
rounding_adjustment = 0
|
||||
|
||||
sales_items.each do |item|
|
||||
self.sale_items.each do |item|
|
||||
if item.status != 'void' && item.status != 'foc'
|
||||
#compute each item and added to total
|
||||
subtotal_price = subtotal_price + item.price
|
||||
@@ -506,7 +498,7 @@ class Sale < ApplicationRecord
|
||||
end
|
||||
|
||||
# Tax Re-Calculte
|
||||
def compute_tax(sale, total_taxable, total_discount = 0, order_source = nil, tax_type=nil)
|
||||
def compute_tax(total_taxable, total_discount = 0, order_source = nil, tax_type=nil)
|
||||
shop = Shop.first
|
||||
|
||||
#if tax is not apply create new record
|
||||
@@ -529,9 +521,9 @@ class Sale < ApplicationRecord
|
||||
tax_profiles = unique_tax_profiles(order_source, self.customer_id)
|
||||
|
||||
# #Creat new tax records
|
||||
if sale.payment_status != 'foc'
|
||||
if self.payment_status != 'foc'
|
||||
tax_profiles.each do |tax|
|
||||
sale_tax = SaleTax.new(:sale => sale)
|
||||
sale_tax = SaleTax.new(:sale => self)
|
||||
sale_tax.tax_name = tax.name
|
||||
sale_tax.tax_rate = tax.rate
|
||||
|
||||
@@ -555,8 +547,8 @@ class Sale < ApplicationRecord
|
||||
sale_tax.save
|
||||
end
|
||||
end
|
||||
sale.tax_type = tax_incl_exec
|
||||
sale.total_tax = total_tax_amount
|
||||
self.tax_type = tax_incl_exec
|
||||
self.total_tax = total_tax_amount
|
||||
end
|
||||
|
||||
# Tax Calculate
|
||||
|
||||
Reference in New Issue
Block a user