From 2794103e52b45986b5706010751e3f229a270b67 Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 9 Aug 2017 17:54:22 +0630 Subject: [PATCH] update customer tax calc --- .../origami/customers_controller.rb | 4 +- app/models/sale.rb | 7 ++- app/views/crm/customers/_new_form.html.erb | 23 ++++---- app/views/origami/customers/index.html.erb | 57 +++++++++++++------ 4 files changed, 57 insertions(+), 34 deletions(-) diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 026e59e3..ec826416 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -37,14 +37,14 @@ class Origami::CustomersController < BaseOrigamiController @crm_customers = Customer.order("customer_id").page(params[:page]) #@products = Product.order("name").page(params[:page]).per(5) else - @crm_customers = Customer.search(filter) - + @crm_customers = Customer.search(filter) end #@crm_customers = Customer.all @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(50) @crm_customer = Customer.new @count_customer = Customer.count_customer + @taxes = TaxProfile.all.order("order_by asc") # if flash["errors"] # @crm_customer.valid? # end diff --git a/app/models/sale.rb b/app/models/sale.rb index 712584a5..b252fdf1 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -277,8 +277,8 @@ class Sale < ApplicationRecord # #Creat new tax records tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| - if cus_tax == tax.id + customer.tax_profiles.each do |cus_tax| + if cus_tax.to_i == tax.id sale_tax = SaleTax.new(:sale => sale) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -318,10 +318,11 @@ class Sale < ApplicationRecord tax_profiles = TaxProfile.all.order("order_by asc") customer = Customer.find(self.customer_id) + # #Create new tax records tax_profiles.each do |tax| customer.tax_profiles.each do |cus_tax| - if cus_tax == tax.id + if cus_tax.to_i == tax.id sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb index 5f1d1b46..35c3a46d 100644 --- a/app/views/crm/customers/_new_form.html.erb +++ b/app/views/crm/customers/_new_form.html.erb @@ -82,17 +82,7 @@
<%= f.text_field :date_of_birth,:value=>"01-01-1990",:class=>"form-control datepicker"%> -
- -
"> - <%= f.input :card_no, :class => "form-control col-md-6 card_no"%> - <% flash.each do |name, msg| %> - <% str="[\"#{msg['card_no']}\"]" - str.gsub!('["', '') - str.gsub!('"]', '') %> - <%= str %> - <% end %> -
+
@@ -103,10 +93,21 @@ <%end %>
+
<%= f.input :tax_profiles, :collection => @taxes, :input_html => { :multiple => true }, :class => "form-control col-md-6 tax_profiles" %>
+
"> + <%= f.input :card_no, :class => "form-control col-md-6 card_no"%> + <% flash.each do |name, msg| %> + <% str="[\"#{msg['card_no']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> + <% end %> +
+
diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index 3c22c2e4..c41e3cd6 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -81,23 +81,7 @@ <%= f.error_notification %> - <%= f.hidden_field :id, :class => "form-control col-md-6 " %> -
"> - <%= f.input :card_no, :class => "form-control col-md-6 card_no"%> - <% flash.each do |name, msg| %> - <% str="[\"#{msg['name']}\"]" - str.gsub!('["', '') - str.gsub!('"]', '') %> - <%= str %> - <% end -%> -
-
- -
- -
-
-
+ <%= f.hidden_field :id, :class => "form-control col-md-6 " %>

@@ -176,6 +160,37 @@ <%= f.text_field :date_of_birth,:value=>"01-01-1990",:class=>"form-control datepicker"%>
+
+ + +
+ +
+ <%= f.input :tax_profiles, :collection => @taxes, :input_html => { :multiple => true }, :class => "form-control col-md-6 tax_profiles" %> +
+ +
"> + <%= f.input :card_no, :class => "form-control col-md-6 card_no"%> + <% flash.each do |name, msg| %> + <% str="[\"#{msg['name']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> + <% end -%> +
+
+ +
+ +
+
+
+