diff --git a/app/controllers/settings/tax_profiles_controller.rb b/app/controllers/settings/tax_profiles_controller.rb index ddf4781a..9ad0b0fc 100755 --- a/app/controllers/settings/tax_profiles_controller.rb +++ b/app/controllers/settings/tax_profiles_controller.rb @@ -45,7 +45,7 @@ class Settings::TaxProfilesController < ApplicationController # POST /settings/tax_profiles # POST /settings/tax_profiles.json def create - + @settings_tax_profile = TaxProfile.new(settings_tax_profile_params) @settings_tax_profile.created_by = current_login_employee.name respond_to do |format| @@ -109,6 +109,6 @@ class Settings::TaxProfilesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_tax_profile_params - params.require(:tax_profile).permit(:name, :group_type, :rate, :inclusive, :order_by, :created_by) + params.require(:tax_profile).permit(:name, :group_type, :rate, :inclusive, :order_by, :created_by,:tax_type) end end diff --git a/app/models/sale.rb b/app/models/sale.rb index dd7cacf5..954674bb 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -486,15 +486,18 @@ class Sale < ApplicationRecord # 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 + if tax.tax_type.to_s =="Net" + sale_tax.tax_payable_amount = tax.rate else - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + 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 + end end - sale_tax.inclusive = tax.inclusive sale_tax.save @@ -609,16 +612,19 @@ class Sale < ApplicationRecord # substract , to give after discount 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 + if tax.tax_type.to_s =="Net" + sale_tax.tax_payable_amount = tax.rate else - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + #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 + end end - sale_tax.inclusive = tax.inclusive sale_tax.save @@ -2048,7 +2054,6 @@ def self.get_sale_data_for_other_payment_credit(sale_id) end def unique_tax_profiles(order_source, customer_id) - puts "unique_tax_profiles unique_tax_profiles" tax_data = TaxProfile.where(group_type: order_source) customer_tax_profiles = Customer.select(:tax_profiles).where(customer_id: customer_id).first diff --git a/app/models/tax_profile.rb b/app/models/tax_profile.rb index 5d85239d..955d58fa 100755 --- a/app/models/tax_profile.rb +++ b/app/models/tax_profile.rb @@ -7,7 +7,7 @@ class TaxProfile < ApplicationRecord def self.calculate_tax(group_type) divided_value =0.0 exclusive =0.0 - tax_profiles = TaxProfile.where(group_type: group_type) + tax_profiles = TaxProfile.where(group_type: group_type,tax_type: 'Percentage') if !tax_profiles.empty? tax_profiles.each do |tax| #include or execulive diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 9c60cd6b..5b5e3eac 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -345,9 +345,14 @@ class ReceiptBillA5Pdf < Prawn::Document sale_data.sale_taxes.each do |st| move_down line_move y_position = cursor - - bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do - text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + if st.tax_rate.to_i == st.tax_payable_amount.to_i + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ st.tax_name }", :size => self.item_font_size,:align => :left + end + else + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + end end bounding_box([self.description_width,y_position], :width =>self.label_width) do text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 2f8ba8ed..ba10e064 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -405,9 +405,14 @@ class ReceiptBillPdf < Prawn::Document sale_data.sale_taxes.each do |st| move_down line_move y_position = cursor - - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + if st.tax_rate.to_i == st.tax_payable_amount.to_i + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ st.tax_name }", :size => self.item_font_size,:align => :left + end + else + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + end end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right diff --git a/app/pdf/receipt_bill_star_pdf.rb b/app/pdf/receipt_bill_star_pdf.rb index 0670b2f9..147ef430 100644 --- a/app/pdf/receipt_bill_star_pdf.rb +++ b/app/pdf/receipt_bill_star_pdf.rb @@ -341,9 +341,14 @@ class ReceiptBillStarPdf < Prawn::Document sale_data.sale_taxes.each do |st| move_down line_move y_position = cursor - - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + if st.tax_rate.to_i == st.tax_payable_amount.to_i + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ st.tax_name }", :size => self.item_font_size,:align => :left + end + else + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + end end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right diff --git a/app/views/settings/tax_profiles/_form.html.erb b/app/views/settings/tax_profiles/_form.html.erb index bfc4c314..b0254690 100755 --- a/app/views/settings/tax_profiles/_form.html.erb +++ b/app/views/settings/tax_profiles/_form.html.erb @@ -12,6 +12,8 @@ <%= f.input :group_type, :collection => Lookup.collection_of("tax_profiles"),:input_html=>{:class=>"col-md-10"},:required=>true %> <%= f.input :name, :input_html=>{:onchange=>"checkDuplicate(this.value);"} %> + <%= f.input :tax_type,input_html: { :class => 'form-control select' }, + collection: %w{Net Percentage},:label => "Tax Type" %> <%= f.input :rate %> <%= f.input :inclusive %> <%= f.input :order_by %> @@ -44,7 +46,7 @@ 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.tax_profiles_txt") %>

- + @@ -69,4 +71,3 @@ } } - diff --git a/db/migrate/20200226124607_add_column_tax_type.rb b/db/migrate/20200226124607_add_column_tax_type.rb new file mode 100644 index 00000000..a00a3a35 --- /dev/null +++ b/db/migrate/20200226124607_add_column_tax_type.rb @@ -0,0 +1,5 @@ +class AddColumnTaxType < ActiveRecord::Migration[5.1] + def change + add_column :tax_profiles, :tax_type, :string, default: "Percentage" + end +end