diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 2f846601..b6664050 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -21,7 +21,7 @@ class Crm::CustomersController < BaseCrmController # paymal_customer = Customer.search_paypar_account_no(filter) # search account no from paypar if type == "card" - + response = Customer.search_paypar_account_no(filter) if !@crm_customers.present? if response["status"] == true @@ -70,7 +70,7 @@ class Crm::CustomersController < BaseCrmController else flash[:member_error]="Need to press sync button " end - + end end end @@ -95,7 +95,7 @@ class Crm::CustomersController < BaseCrmController lookup_customer = Lookup.collection_of('customer_settings') if !lookup_customer.empty? lookup_customer.each do |create_setting| - if create_setting[0].downcase == "create" + if create_setting[0].downcase == "create" if create_setting[1] == '0' && current_login_employee.role == 'cashier' @create_flag = false end @@ -135,7 +135,7 @@ class Crm::CustomersController < BaseCrmController params[:type] = nil params[:customer_id] = params[:id] @credit_sales = SalePayment.get_credit_sales(params) - + #get customer amount @customer = Customer.find(params[:id]) @response = Customer.get_membership_transactions(@customer) @@ -158,8 +158,9 @@ class Crm::CustomersController < BaseCrmController def edit @customer = Customer.find(params[:id]) end + def sync - @customer = Customer.find(params[:id]) + @customer = Customer.find(params[:id]) respond_to do |format| name = @customer.name phone = @customer.contact_no @@ -169,31 +170,21 @@ class Crm::CustomersController < BaseCrmController nrc = @customer.nrc_no card_no = @customer.card_no paypar_account_no = @customer.paypar_account_no - id = @crm_customer.membership_id - member_group_id = @customer.membership_type - if !id.present? && !member_group_id.nil? + id = @customer.membership_id + member_group_id = @customer.membership_type + # if !id.present? && !member_group_id.nil? membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("create_membership_customer") merchant_uid = memberaction.merchant_account_id.to_s auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, - member_group_id: member_group_id, - id:id, - merchant_uid:merchant_uid,auth_token:auth_token}.to_json - - # Check for paypar account exists - # if paypar_account_no != nil || paypar_account_no != '' - if paypar_account_no.present? member_params = { name: name,phone: phone,email: email, dob: dob,address: address,nrc:nrc,card_no:card_no, paypar_account_no: paypar_account_no, member_group_id: member_group_id, id:id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json - end begin response = HTTParty.post(url, @@ -221,7 +212,7 @@ class Crm::CustomersController < BaseCrmController Rails.logger.debug "--------Sync Member response -------" Rails.logger.debug response.to_json if response["status"] == true - + status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) format.html { redirect_to crm_customers_path } @@ -247,14 +238,14 @@ class Crm::CustomersController < BaseCrmController format.html { redirect_to crm_customers_path } flash[:member_error] =response["message"] end - end + # end end end # POST /crm/customers # POST /crm/customers.json - def create - # Remove "" default first - params[:customer][:tax_profiles].delete_at(0) + def create + # Remove "" default first + params[:customer][:tax_profiles].delete_at(0) @checked_contact = Customer.find_by_contact_no(customer_params[:contact_no]) if @checked_contact.nil? respond_to do |format| @@ -272,7 +263,7 @@ class Crm::CustomersController < BaseCrmController nrc = customer_params[:nrc_no] card_no = customer_params[:card_no] paypar_account_no = customer_params[:paypar_account_no] - member_group_id = params[:member_group_id] + member_group_id = params[:member_group_id] if member_group_id.present? membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -282,7 +273,7 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, + dob: dob,address: address,nrc:nrc,card_no:card_no, member_group_id: member_group_id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json @@ -333,7 +324,7 @@ class Crm::CustomersController < BaseCrmController end # format.json { render :index, status: :created, location: @crm_customers } else - customer = Customer.find(@crm_customers.customer_id) + customer = Customer.find(@crm_customers.customer_id) # Check membership id and bind to user if response["membership_id"] != nil @@ -399,7 +390,7 @@ class Crm::CustomersController < BaseCrmController # PATCH/PUT /crm/customers/1 # PATCH/PUT /crm/customers/1.json def update - # Remove "" default first + # Remove "" default first params[:customer][:tax_profiles].delete_at(0) @checked_contact = nil @existed_contact = Customer.find_by_customer_id_and_contact_no(customer_params[:id], customer_params[:contact_no]) @@ -409,7 +400,7 @@ class Crm::CustomersController < BaseCrmController if !@existed_contact.nil? || @checked_contact.nil? respond_to do |format| if @crm_customer.update(customer_params) - # update tax profile + # update tax profile @crm_customer.update_attributes(tax_profiles: params[:customer][:tax_profiles]) name = customer_params[:name] phone = customer_params[:contact_no] @@ -420,7 +411,7 @@ class Crm::CustomersController < BaseCrmController card_no = customer_params[:card_no] paypar_account_no = customer_params[:paypar_account_no] id = @crm_customer.membership_id - member_group_id = params[:member_group_id] + member_group_id = params[:member_group_id] if !id.present? && !member_group_id.nil? membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -430,7 +421,7 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, + dob: dob,address: address,nrc:nrc,card_no:card_no, member_group_id: member_group_id, id:id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json @@ -471,7 +462,7 @@ class Crm::CustomersController < BaseCrmController Rails.logger.debug "--------Update Member response -------" Rails.logger.debug response.to_json if response["status"] == true - + status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) format.html { redirect_to crm_customers_path } @@ -496,7 +487,7 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, + dob: dob,address: address,nrc:nrc,card_no:card_no, member_group_id: member_group_id, id:id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json @@ -601,7 +592,7 @@ class Crm::CustomersController < BaseCrmController flash[:member_notice]='Membership was successfully updated' end end - + end @@ -617,6 +608,5 @@ class Crm::CustomersController < BaseCrmController params.require(:customer).permit(:id, :name, :company, :contact_no, :email, :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no, :paypar_account_no, :customer_type, :image_path) end - -end +end