From 0f1ce09416e630209fd29d634ffdd78b0b4a18d5 Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 9 May 2018 15:40:13 +0630 Subject: [PATCH] change customer and sale tax for takeaway --- app/controllers/crm/customers_controller.rb | 2 +- .../origami/customers_controller.rb | 2 +- app/models/sale.rb | 56 +++++++++++++++++++ .../crm/customers/_card_read_form.html.erb | 0 .../crm/customers/_crm_customer.json.jbuilder | 0 app/views/crm/customers/_form.html.erb | 0 app/views/crm/customers/_new_form.html.erb | 0 app/views/crm/customers/edit.html.erb | 0 app/views/crm/customers/edit.json.jbuilder | 0 app/views/crm/customers/index.html.erb | 0 app/views/crm/customers/index.json.jbuilder | 0 app/views/crm/customers/new.html.erb | 0 app/views/crm/customers/show.html.erb | 0 app/views/crm/customers/show.json.jbuilder | 0 app/views/origami/customers/index.html.erb | 0 15 files changed, 58 insertions(+), 2 deletions(-) mode change 100755 => 100644 app/controllers/crm/customers_controller.rb mode change 100755 => 100644 app/controllers/origami/customers_controller.rb mode change 100755 => 100644 app/views/crm/customers/_card_read_form.html.erb mode change 100755 => 100644 app/views/crm/customers/_crm_customer.json.jbuilder mode change 100755 => 100644 app/views/crm/customers/_form.html.erb mode change 100755 => 100644 app/views/crm/customers/_new_form.html.erb mode change 100755 => 100644 app/views/crm/customers/edit.html.erb mode change 100755 => 100644 app/views/crm/customers/edit.json.jbuilder mode change 100755 => 100644 app/views/crm/customers/index.html.erb mode change 100755 => 100644 app/views/crm/customers/index.json.jbuilder mode change 100755 => 100644 app/views/crm/customers/new.html.erb mode change 100755 => 100644 app/views/crm/customers/show.html.erb mode change 100755 => 100644 app/views/crm/customers/show.json.jbuilder mode change 100755 => 100644 app/views/origami/customers/index.html.erb diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb old mode 100755 new mode 100644 index 3082687b..1d0ad8e4 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -39,7 +39,7 @@ class Crm::CustomersController < BaseCrmController @membership_types = Lookup.collection_of("member_group_type") - @taxes = TaxProfile.all.order("order_by asc") + @taxes = TaxProfile.where(:group_type => 'cashier') @filter = filter diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb old mode 100755 new mode 100644 index 537703a1..ec559870 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -86,7 +86,7 @@ class Origami::CustomersController < BaseOrigamiController @crm_customer = Customer.new @count_customer = Customer.count_customer - @taxes = TaxProfile.all.order("order_by asc") + @taxes = TaxProfile.where(:group_type => 'cashier') # if flash["errors"] # @crm_customer.valid? # end diff --git a/app/models/sale.rb b/app/models/sale.rb index 8390c981..3be637d0 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -430,6 +430,32 @@ class Sale < ApplicationRecord # customer.tax_profiles.each do |cus_tax| # if cus_tax.to_i == tax.id if tax.group_type.to_s == order_source.to_s + if customer.customer_type.downcase == 'takeaway' + if tax.name.downcase == 'commercial tax' + 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 + end + else sale_tax = SaleTax.new(:sale => sale) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -452,6 +478,8 @@ class Sale < ApplicationRecord sale_tax.inclusive = tax.inclusive sale_tax.save + end + end # end # end @@ -484,6 +512,33 @@ class Sale < ApplicationRecord # customer.tax_profiles.each do |cus_tax| # if cus_tax.to_i == tax.id if tax.group_type.to_s == order_source.to_s + if customer.customer_type.downcase == 'takeaway' + if tax.name.downcase == 'commercial tax' + sale_tax = SaleTax.new(:sale => self) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = tax.rate + + # substract , to give after discount + total_tax = total_taxable - self.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 + end + else sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -507,6 +562,7 @@ class Sale < ApplicationRecord sale_tax.inclusive = tax.inclusive sale_tax.save + end end # end # end diff --git a/app/views/crm/customers/_card_read_form.html.erb b/app/views/crm/customers/_card_read_form.html.erb old mode 100755 new mode 100644 diff --git a/app/views/crm/customers/_crm_customer.json.jbuilder b/app/views/crm/customers/_crm_customer.json.jbuilder old mode 100755 new mode 100644 diff --git a/app/views/crm/customers/_form.html.erb b/app/views/crm/customers/_form.html.erb old mode 100755 new mode 100644 diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb old mode 100755 new mode 100644 diff --git a/app/views/crm/customers/edit.html.erb b/app/views/crm/customers/edit.html.erb old mode 100755 new mode 100644 diff --git a/app/views/crm/customers/edit.json.jbuilder b/app/views/crm/customers/edit.json.jbuilder old mode 100755 new mode 100644 diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb old mode 100755 new mode 100644 diff --git a/app/views/crm/customers/index.json.jbuilder b/app/views/crm/customers/index.json.jbuilder old mode 100755 new mode 100644 diff --git a/app/views/crm/customers/new.html.erb b/app/views/crm/customers/new.html.erb old mode 100755 new mode 100644 diff --git a/app/views/crm/customers/show.html.erb b/app/views/crm/customers/show.html.erb old mode 100755 new mode 100644 diff --git a/app/views/crm/customers/show.json.jbuilder b/app/views/crm/customers/show.json.jbuilder old mode 100755 new mode 100644 diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb old mode 100755 new mode 100644