From 0e93eb37651c9d5741db1274a968ec98605c7df5 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 11 Aug 2017 12:13:30 +0630 Subject: [PATCH] fix for customer tax ui and calc tax after bind customer --- app/controllers/origami/customers_controller.rb | 2 ++ app/models/sale.rb | 14 ++++++++++---- app/views/crm/customers/index.html.erb | 6 ++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index ec826416..9c054378 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -89,6 +89,8 @@ class Origami::CustomersController < BaseOrigamiController if status == true render json: JSON.generate({:status => true}) + # Re-calc All Amount in Sale + sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount) else render json: JSON.generate({:status => false, :error_message => "Record not found"}) end diff --git a/app/models/sale.rb b/app/models/sale.rb index 9f4ae9f7..7a4a7a62 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -274,11 +274,14 @@ class Sale < ApplicationRecord #tax_profile - list by order_by tax_profiles = TaxProfile.all.order("order_by asc") customer = Customer.find(sale.customer_id) - +puts customer.tax_profiles # #Creat new tax records tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| - if cus_tax.to_i == tax.id + customer.tax_profiles.each do |cus_tax| +puts tax +puts cus_tax + if cus_tax.to_i == tax.id +puts "WALSS" sale_tax = SaleTax.new(:sale => sale) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -319,11 +322,14 @@ class Sale < ApplicationRecord tax_profiles = TaxProfile.all.order("order_by asc") customer = Customer.find(self.customer_id) - +puts customer.tax_profiles # #Create new tax records tax_profiles.each do |tax| customer.tax_profiles.each do |cus_tax| +puts tax +puts cus_tax if cus_tax.to_i == tax.id +puts "WALSS" 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/index.html.erb b/app/views/crm/customers/index.html.erb index 34aaf51e..14e38822 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -124,18 +124,20 @@ $(document).on('click',".customer_tr",function(){ var url = "customers/" + customer_id + "/edit"; } + $("#customer_tax_profiles").children().removeAttr("selected").css({'color':'#000','background':'none'});; + $.ajax({ type: "GET", 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(taxes); console.log(parse_taxes); $.each(parse_taxes, function(i, value){ - $("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected"); + $("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected").css({'color':'#fff','background':'#215d9c'}); }); $('#customer_id').val(data.id);