From 5d63d38e4e548b4c3616b3797f4c8a9590870116 Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 25 May 2018 15:25:39 +0630 Subject: [PATCH] add inclc in receipt bill --- app/models/sale.rb | 53 +++++++++++++++++++--------------- app/pdf/receipt_bill_a5_pdf.rb | 2 +- app/pdf/receipt_bill_pdf.rb | 2 +- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index aa489c7d..979d265c 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -421,7 +421,7 @@ class Sale < ApplicationRecord end total_tax_amount = 0 - tax_incl_exec = "execulsive" + tax_incl_exec = "exclusive" #tax_profile - list by order_by tax_profiles = TaxProfile.all.order("order_by asc") customer = Customer.find(sale.customer_id) @@ -431,29 +431,30 @@ class Sale < ApplicationRecord tax_profiles.each do |tax| if tax.group_type.to_s == order_source.to_s if tax_type - if tax_type.to_s == tax.name.to_s || tax_type == 'all' - sale_tax = SaleTax.new(:sale => sale) - sale_tax.tax_name = tax.name - sale_tax.tax_rate = tax.rate + if tax_type.to_s == tax.name.to_s || tax_type == 'all' + sale_tax = SaleTax.new(:sale => sale) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = tax.rate - # substract , to give after discount - total_tax = total_taxable - total_discount - #include or execulive - if tax.inclusive - rate = tax.rate - divided_value = (100 + rate)/rate - sale_tax.tax_payable_amount = total_tax / divided_value - else - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 - total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount - end - #new taxable amount is standard rule for step by step - if shop.calc_tax_order - total_taxable = total_taxable + sale_tax.tax_payable_amount - end - sale_tax.inclusive = tax.inclusive - sale_tax.save + # substract , to give after discount + total_tax = total_taxable - total_discount + #include or execulive + if tax.inclusive + tax_incl_exec = "inclusive" + rate = tax.rate + divided_value = (100 + rate)/rate + sale_tax.tax_payable_amount = total_tax / divided_value + else + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount end + #new taxable amount is standard rule for step by step + if shop.calc_tax_order + total_taxable = total_taxable + sale_tax.tax_payable_amount + end + sale_tax.inclusive = tax.inclusive + sale_tax.save + end else # customer.tax_profiles.each do |cus_tax| # if cus_tax.to_i == tax.id @@ -465,6 +466,7 @@ class Sale < ApplicationRecord total_tax = total_taxable - total_discount #include or execulive if tax.inclusive + tax_incl_exec = "inclusive" rate = tax.rate divided_value = (100 + rate)/rate sale_tax.tax_payable_amount = total_tax / divided_value @@ -484,7 +486,7 @@ class Sale < ApplicationRecord end end end - sale.tax_type = + sale.tax_type = tax_incl_exec sale.total_tax = total_tax_amount end @@ -499,6 +501,7 @@ class Sale < ApplicationRecord end total_tax_amount = 0 + tax_incl_exec = "exclusive" #tax_profile - list by order_by tax_profiles = TaxProfile.all.order("order_by asc") @@ -520,6 +523,7 @@ class Sale < ApplicationRecord total_tax = total_taxable - self.total_discount #include or execulive if tax.inclusive + tax_incl_exec = "inclusive" rate = tax.rate divided_value = (100 + rate)/rate sale_tax.tax_payable_amount = total_tax / divided_value @@ -539,7 +543,8 @@ class Sale < ApplicationRecord # end end end - self.total_tax = total_tax_amount + self.tax_type = tax_incl_exec + self.total_tax = total_tax_amount end def product_get_unit_price(item_code) diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 550195ed..707ecf00 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -304,7 +304,7 @@ class ReceiptBillA5Pdf < Prawn::Document if sale_data.sale_taxes.length > 0 incl_tax = "" - if sale_data.tax_type == "inculsive" + if sale_data.tax_type == "inclusive" incl_tax = "Incl." end sale_data.sale_taxes.each do |st| diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index ac79297c..92ce858d 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -291,7 +291,7 @@ class ReceiptBillPdf < Prawn::Document if sale_data.sale_taxes.length > 0 incl_tax = "" - if sale_data.tax_type == "inculsive" + if sale_data.tax_type == "inclusive" incl_tax = "Incl." end