diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 4b045221..b2c715ad 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -128,8 +128,15 @@ class Crm::CustomersController < BaseCrmController end # format.json { render :index, status: :created, location: @crm_customers } else - customer = Customer.find(@crm_customers.customer_id) - status = customer.update_attributes(membership_type:member_group_id ) + customer = Customer.find(@crm_customers.customer_id) + + # Check membership id and bind to user + if response["membership_id"] != nil + status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) + else + status = customer.update_attributes(membership_type:member_group_id) + end + if params[:sale_id] format.html { redirect_to '/origami/'+params[:sale_id]+'/customers', notice: 'Customer was successfully created.' + response["message"]} else @@ -208,16 +215,18 @@ end end if response["status"] == true - customer = Customer.find(@crm_customer.customer_id) status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated'} - else - customer = Customer.find(@crm_customer.customer_id) - status = customer.update_attributes(membership_type:member_group_id ) + # Check membership id and bind to user + if response["membership_id"] != nil + status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) + else + status = customer.update_attributes(membership_type:member_group_id) + end format.html { redirect_to crm_customers_path, notice: response["error"] } end @@ -255,6 +264,12 @@ end format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' } format.json { render :show, status: :ok, location: @crm_customer } else + # Check membership id and bind to user + if response["membership_id"] != nil + status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) + else + status = customer.update_attributes(membership_type:member_group_id) + end format.html { redirect_to crm_customers_path, notice: response["message"] } end diff --git a/app/models/customer.rb b/app/models/customer.rb index ef777c2d..06f7f1d1 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -10,7 +10,7 @@ class Customer < ApplicationRecord validates :contact_no, uniqueness: true validates :email, uniqueness: true validates :card_no, uniqueness: true - # validates :paypar_account_no + validates :paypar_account_no, uniqueness: true paginates_per 50 diff --git a/app/models/sale.rb b/app/models/sale.rb index 26fa24cd..197c7106 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -249,7 +249,7 @@ class Sale < ApplicationRecord if item.remark != 'void' #compute each item and added to total subtotal_price = subtotal_price + item.price - total_taxable = total_taxable + item.taxable_price + total_taxable = total_taxable + item.price end end diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb index 3c09d20f..b99c25a3 100644 --- a/app/views/crm/customers/_new_form.html.erb +++ b/app/views/crm/customers/_new_form.html.erb @@ -128,10 +128,9 @@