From fb8c67f05804d6e526e9e09b2ef1f45933737b1c Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 10 Aug 2017 13:38:39 +0630 Subject: [PATCH] fix for customer tax --- app/controllers/crm/customers_controller.rb | 3 ++- app/views/crm/customers/index.html.erb | 9 +++++---- app/views/origami/customers/index.html.erb | 3 ++- db/seeds.rb | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 180901ad..fe490abb 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -65,6 +65,7 @@ class Crm::CustomersController < BaseCrmController # GET /crm/customers/1/edit def edit + @customer = Customer.find(params[:id]) end # POST /crm/customers @@ -78,7 +79,7 @@ class Crm::CustomersController < BaseCrmController if @crm_customers.save # update tax profile customer = Customer.find(@crm_customers.customer_id) - customer.update_attributes(tax_profiles: params[:customer][:tax_profiles].to_json) + customer.update_attributes(tax_profiles: params[:customer][:tax_profiles]) name = customer_params[:name] phone = customer_params[:contact_no] email = customer_params[:email] diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 0b893747..34aaf51e 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -121,7 +121,7 @@ $(document).on('click',".customer_tr",function(){ update_sale(customer_id,sale_id); }else{ - var url = "customers/"+customer_id; + var url = "customers/" + customer_id + "/edit"; } $.ajax({ @@ -129,10 +129,11 @@ $(document).on('click',".customer_tr",function(){ url: url, data: {}, dataType: "json", - success: function(data) { + success: function(data) { // Selected for Taxes - //var taxes = JSON.stringify(data.tax_profiles); - var parse_taxes = JSON.parse(data.tax_profiles); + var taxes = JSON.stringify(data.tax_profiles); + var parse_taxes = JSON.parse(taxes); + console.log(parse_taxes); $.each(parse_taxes, function(i, value){ $("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected"); }); diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index c41e3cd6..6f4f53df 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -307,7 +307,8 @@ data: {}, dataType: "json", success: function(data) { - var parse_taxes = JSON.parse(data.tax_profiles); + var taxes = JSON.stringify(data.tax_profiles); + var parse_taxes = JSON.parse(taxes); $.each(parse_taxes, function(i, value){ $("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected"); }); diff --git a/db/seeds.rb b/db/seeds.rb index 1b024797..24a1debb 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -99,8 +99,8 @@ customer_type = Lookup.create([{lookup_type:'customer_type', name: 'Dinein', val {lookup_type:'customer_type', name: 'Delivery', value: 'Delivery'}]) #WALK CUSTOMER - Default CUSTOMER (take key 1) -customer = Customer.create({name:"WALK-IN", email: "cus1@customer.com", contact_no:"000000000",card_no:"000", customer_type:"Dinein", tax_profiles:"[2,1]"}) -customer2 = Customer.create({name:"TAKEAWAY", email: "cus2@customer.com", contact_no:"111111111",card_no:"111", customer_type:"Takeaway", tax_profiles:"[1]"}) +customer = Customer.create({name:"WALK-IN", email: "cus1@customer.com", contact_no:"000000000",card_no:"000", customer_type:"Dinein", tax_profiles:"[\"2\", \"1\"]"}) +customer2 = Customer.create({name:"TAKEAWAY", email: "cus2@customer.com", contact_no:"111111111",card_no:"111", customer_type:"Takeaway", tax_profiles:"[\"1\"]"}) #Default ZOne # zone = Zone.create({id:1, name: "Normal Zone", is_active:true, created_by: "SYSTEM DEFAULT"})