add calc tax order in sale

This commit is contained in:
Yan
2017-09-11 14:05:19 +06:30
parent b4ceff9631
commit efb60e6f79

View File

@@ -292,6 +292,8 @@ class Sale < ApplicationRecord
# Tax Re-Calculte
def compute_tax(sale, total_taxable, total_discount = 0)
shop = Shop.first();
#if tax is not apply create new record
SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax|
#delete existing and create new
@@ -322,7 +324,9 @@ class Sale < ApplicationRecord
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
end
#new taxable amount is standard rule for step by step
# total_taxable = total_taxable + sale_tax.tax_payable_amount
if shop.calc_tax_order
total_taxable = total_taxable + sale_tax.tax_payable_amount
end
sale_tax.inclusive = tax.inclusive
sale_tax.save
@@ -346,7 +350,7 @@ class Sale < ApplicationRecord
tax_profiles = TaxProfile.all.order("order_by asc")
customer = Customer.find(self.customer_id)
puts customer
#Create new tax records
tax_profiles.each do |tax|
customer.tax_profiles.each do |cus_tax|
@@ -368,7 +372,9 @@ class Sale < ApplicationRecord
end
#new taxable amount is standard rule for step by step
# total_taxable = total_taxable + sale_tax.tax_payable_amount
if shop.calc_tax_order
total_taxable = total_taxable + sale_tax.tax_payable_amount
end
sale_tax.inclusive = tax.inclusive
sale_tax.save