member sync

This commit is contained in:
Myat Zin Wai Maw
2019-12-10 17:23:52 +06:30
parent b0452030b0
commit bb0335ce6b

View File

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