check customer contact no
This commit is contained in:
@@ -99,13 +99,153 @@ class Crm::CustomersController < BaseCrmController
|
|||||||
def create
|
def create
|
||||||
# Remove "" default first
|
# Remove "" default first
|
||||||
params[:customer][:tax_profiles].delete_at(0)
|
params[:customer][:tax_profiles].delete_at(0)
|
||||||
@crm_customers = Customer.new(customer_params)
|
@checked_contact = Customer.find_by_contact_no(customer_params[:contact_no])
|
||||||
|
if @checked_contact.nil?
|
||||||
|
respond_to do |format|
|
||||||
|
@crm_customers = Customer.new(customer_params)
|
||||||
|
|
||||||
respond_to do |format|
|
if @crm_customers.save
|
||||||
if @crm_customers.save
|
# update tax profile
|
||||||
# update tax profile
|
customer = Customer.find(@crm_customers.customer_id)
|
||||||
customer = Customer.find(@crm_customers.customer_id)
|
customer.update_attributes(tax_profiles: params[:customer][:tax_profiles])
|
||||||
customer.update_attributes(tax_profiles: params[:customer][:tax_profiles])
|
name = customer_params[:name]
|
||||||
|
phone = customer_params[:contact_no]
|
||||||
|
email = customer_params[:email]
|
||||||
|
dob = customer_params[:date_of_birth]
|
||||||
|
address = customer_params[:address]
|
||||||
|
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]
|
||||||
|
|
||||||
|
if member_group_id.present?
|
||||||
|
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,
|
||||||
|
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,
|
||||||
|
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
response = HTTParty.post(url,
|
||||||
|
:body => member_params,
|
||||||
|
:headers => {
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Accept' => 'application/json; version=3'
|
||||||
|
},
|
||||||
|
:timeout => 10
|
||||||
|
)
|
||||||
|
|
||||||
|
rescue HTTParty::Error
|
||||||
|
response = {"status" => false, "message" => "Can't open membership server "}
|
||||||
|
|
||||||
|
rescue Net::OpenTimeout
|
||||||
|
response = {"status" => false, "message" => "Can't open membership server "}
|
||||||
|
|
||||||
|
rescue OpenURI::HTTPError
|
||||||
|
response = {"status" => false, "message" => "Can't open membership server "}
|
||||||
|
|
||||||
|
rescue SocketError
|
||||||
|
response = {"status" => false, "message" => "Can't open membership server "}
|
||||||
|
end
|
||||||
|
Rails.logger.debug "--------------Create Member---------"
|
||||||
|
Rails.logger.debug response.to_json
|
||||||
|
if response["status"] == true
|
||||||
|
customer = Customer.find(@crm_customers.customer_id)
|
||||||
|
status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id )
|
||||||
|
|
||||||
|
if params[:sale_id]
|
||||||
|
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer was successfully created.' }
|
||||||
|
else
|
||||||
|
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created'}
|
||||||
|
end
|
||||||
|
# format.json { render :index, status: :created, location: @crm_customers }
|
||||||
|
else
|
||||||
|
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
|
||||||
|
|
||||||
|
# When paypar account no not exist in paypar
|
||||||
|
if response["message"] == "Account has not exist."
|
||||||
|
customer.destroy
|
||||||
|
if params[:sale_id]
|
||||||
|
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer cannot created.' + response["message"]}
|
||||||
|
else
|
||||||
|
format.html { redirect_to crm_customers_path, notice: 'Customer cannot created.' + response["message"] }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if params[:sale_id]
|
||||||
|
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer was successfully created.' + response["message"]}
|
||||||
|
else
|
||||||
|
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' + response["message"] }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if params[:sale_id]
|
||||||
|
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer was successfully created. noted'}
|
||||||
|
else
|
||||||
|
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created. ' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if params[:sale_id]
|
||||||
|
flash[:errors] = @crm_customers.errors
|
||||||
|
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page]}
|
||||||
|
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
|
||||||
|
else
|
||||||
|
flash[:errors] = @crm_customers.errors
|
||||||
|
format.html { redirect_to crm_customers_path}
|
||||||
|
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
flash[:errors] = {"contact_no":["has already been taken"]}
|
||||||
|
respond_to do |format|
|
||||||
|
if params[:sale_id]
|
||||||
|
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page]}
|
||||||
|
else
|
||||||
|
format.html { redirect_to crm_customers_path}
|
||||||
|
end
|
||||||
|
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end #end of contact no checked
|
||||||
|
end
|
||||||
|
# PATCH/PUT /crm/customers/1
|
||||||
|
# PATCH/PUT /crm/customers/1.json
|
||||||
|
def update
|
||||||
|
# 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])
|
||||||
|
if @existed_contact.nil?
|
||||||
|
@checked_contact = Customer.find_by_contact_no(customer_params[:contact_no])
|
||||||
|
end
|
||||||
|
if !@existed_contact.nil? && @checked_contact.nil?
|
||||||
|
respond_to do |format|
|
||||||
|
if @crm_customer.update(customer_params)
|
||||||
|
# update tax profile
|
||||||
|
@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]
|
||||||
email = customer_params[:email]
|
email = customer_params[:email]
|
||||||
@@ -114,9 +254,10 @@ 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]
|
||||||
|
id = @crm_customer.membership_id
|
||||||
member_group_id = params[:member_group_id]
|
member_group_id = params[:member_group_id]
|
||||||
|
|
||||||
if member_group_id.present?
|
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
|
||||||
@@ -124,255 +265,139 @@ 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
|
id:id,
|
||||||
|
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
|
||||||
|
|
||||||
# Check for paypar account exists
|
# Check for paypar account exists
|
||||||
# if paypar_account_no != nil || paypar_account_no != ''
|
# if paypar_account_no != nil || paypar_account_no != ''
|
||||||
if paypar_account_no.present?
|
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,
|
||||||
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
|
id:id,
|
||||||
|
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
response = HTTParty.post(url,
|
response = HTTParty.post(url,
|
||||||
:body => member_params,
|
:body => member_params,
|
||||||
:headers => {
|
:headers => {
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
'Accept' => 'application/json; version=3'
|
'Accept' => 'application/json; version=3'
|
||||||
},
|
},
|
||||||
:timeout => 10
|
:timeout => 10
|
||||||
)
|
)
|
||||||
|
rescue Net::OpenTimeout
|
||||||
|
response = { status: false }
|
||||||
|
|
||||||
rescue HTTParty::Error
|
rescue OpenURI::HTTPError
|
||||||
response = {"status" => false, "message" => "Can't open membership server "}
|
response = { status: false}
|
||||||
|
|
||||||
rescue Net::OpenTimeout
|
rescue SocketError
|
||||||
response = {"status" => false, "message" => "Can't open membership server "}
|
response = { status: false}
|
||||||
|
|
||||||
rescue OpenURI::HTTPError
|
|
||||||
response = {"status" => false, "message" => "Can't open membership server "}
|
|
||||||
|
|
||||||
rescue SocketError
|
|
||||||
response = {"status" => false, "message" => "Can't open membership server "}
|
|
||||||
end
|
end
|
||||||
Rails.logger.debug "--------------Create Member---------"
|
customer = Customer.find(@crm_customer.customer_id)
|
||||||
|
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
|
||||||
customer = Customer.find(@crm_customers.customer_id)
|
|
||||||
status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id )
|
|
||||||
|
|
||||||
if params[:sale_id]
|
status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id )
|
||||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer was successfully created.' }
|
|
||||||
else
|
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated'}
|
||||||
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created'}
|
|
||||||
end
|
|
||||||
# format.json { render :index, status: :created, location: @crm_customers }
|
|
||||||
else
|
else
|
||||||
customer = Customer.find(@crm_customers.customer_id)
|
# Check membership id and bind to user
|
||||||
|
if response["membership_id"] != nil
|
||||||
# Check membership id and bind to user
|
status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id )
|
||||||
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
|
|
||||||
|
|
||||||
# When paypar account no not exist in paypar
|
|
||||||
if response["message"] == "Account has not exist."
|
|
||||||
customer.destroy
|
|
||||||
if params[:sale_id]
|
|
||||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer cannot created.' + response["message"]}
|
|
||||||
else
|
|
||||||
format.html { redirect_to crm_customers_path, notice: 'Customer cannot created.' + response["message"] }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if params[:sale_id]
|
|
||||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer was successfully created.' + response["message"]}
|
|
||||||
else
|
|
||||||
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' + response["message"] }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if params[:sale_id]
|
|
||||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer was successfully created. noted'}
|
|
||||||
else
|
else
|
||||||
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created. ' }
|
status = customer.update_attributes(membership_type:member_group_id)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
else
|
|
||||||
|
|
||||||
if params[:sale_id]
|
format.html { redirect_to crm_customers_path, notice: response["error"] }
|
||||||
flash[:errors] = @crm_customers.errors
|
end
|
||||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page]}
|
|
||||||
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
|
|
||||||
else
|
else
|
||||||
flash[:errors] = @crm_customers.errors
|
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
||||||
format.html { redirect_to crm_customers_path}
|
memberaction = MembershipAction.find_by_membership_type("update_membership_customer")
|
||||||
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
|
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.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,
|
||||||
|
:body => member_params,
|
||||||
|
:headers => {
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Accept' => 'application/json; version=3'
|
||||||
|
},
|
||||||
|
:timeout => 10
|
||||||
|
)
|
||||||
|
rescue Net::OpenTimeout
|
||||||
|
response = { status: false }
|
||||||
|
|
||||||
|
rescue OpenURI::HTTPError
|
||||||
|
response = { status: false}
|
||||||
|
|
||||||
|
rescue SocketError
|
||||||
|
response = { status: false}
|
||||||
|
end
|
||||||
|
Rails.logger.debug "--------Update Member response -------"
|
||||||
|
Rails.logger.debug response.to_json
|
||||||
|
if response["status"] == true
|
||||||
|
customer = Customer.find(@crm_customer.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
|
||||||
|
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' }
|
||||||
|
format.json { render :show, status: :ok, location: @crm_customer }
|
||||||
|
else
|
||||||
|
customer = Customer.find(@crm_customer.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
|
||||||
|
format.html { redirect_to crm_customers_path, notice: response["message"] }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# PATCH/PUT /crm/customers/1
|
|
||||||
# PATCH/PUT /crm/customers/1.json
|
|
||||||
def update
|
|
||||||
# Remove "" default first
|
|
||||||
params[:customer][:tax_profiles].delete_at(0)
|
|
||||||
respond_to do |format|
|
|
||||||
if @crm_customer.update(customer_params)
|
|
||||||
# update tax profile
|
|
||||||
@crm_customer.update_attributes(tax_profiles: params[:customer][:tax_profiles])
|
|
||||||
name = customer_params[:name]
|
|
||||||
phone = customer_params[:contact_no]
|
|
||||||
email = customer_params[:email]
|
|
||||||
dob = customer_params[:date_of_birth]
|
|
||||||
address = customer_params[:address]
|
|
||||||
nrc = customer_params[:nrc_no]
|
|
||||||
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]
|
|
||||||
|
|
||||||
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,
|
|
||||||
:body => member_params,
|
|
||||||
:headers => {
|
|
||||||
'Content-Type' => 'application/json',
|
|
||||||
'Accept' => 'application/json; version=3'
|
|
||||||
},
|
|
||||||
:timeout => 10
|
|
||||||
)
|
|
||||||
rescue Net::OpenTimeout
|
|
||||||
response = { status: false }
|
|
||||||
|
|
||||||
rescue OpenURI::HTTPError
|
|
||||||
response = { status: false}
|
|
||||||
|
|
||||||
rescue SocketError
|
|
||||||
response = { status: false}
|
|
||||||
end
|
|
||||||
customer = Customer.find(@crm_customer.customer_id)
|
|
||||||
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, notice: 'Customer was successfully updated'}
|
|
||||||
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["error"] }
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
|
||||||
memberaction = MembershipAction.find_by_membership_type("update_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.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,
|
|
||||||
:body => member_params,
|
|
||||||
:headers => {
|
|
||||||
'Content-Type' => 'application/json',
|
|
||||||
'Accept' => 'application/json; version=3'
|
|
||||||
},
|
|
||||||
:timeout => 10
|
|
||||||
)
|
|
||||||
rescue Net::OpenTimeout
|
|
||||||
response = { status: false }
|
|
||||||
|
|
||||||
rescue OpenURI::HTTPError
|
|
||||||
response = { status: false}
|
|
||||||
|
|
||||||
rescue SocketError
|
|
||||||
response = { status: false}
|
|
||||||
end
|
|
||||||
Rails.logger.debug "--------Update Member response -------"
|
|
||||||
Rails.logger.debug response.to_json
|
|
||||||
if response["status"] == true
|
|
||||||
customer = Customer.find(@crm_customer.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
|
|
||||||
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' }
|
|
||||||
format.json { render :show, status: :ok, location: @crm_customer }
|
|
||||||
else
|
|
||||||
customer = Customer.find(@crm_customer.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
|
|
||||||
format.html { redirect_to crm_customers_path, notice: response["message"] }
|
|
||||||
end
|
|
||||||
|
|
||||||
|
flash[:errors] = @crm_customer.errors
|
||||||
|
format.html { redirect_to crm_customers_path}
|
||||||
|
format.json { render json: @crm_customer.errors, status: :unprocessable_entity }
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
flash[:errors] = @crm_customer.errors
|
|
||||||
format.html { redirect_to crm_customers_path}
|
|
||||||
format.json { render json: @crm_customer.errors, status: :unprocessable_entity }
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
flash[:errors] = {"contact_no":["has already been taken"]}
|
||||||
|
respond_to do |format|
|
||||||
|
if params[:sale_id]
|
||||||
|
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page]}
|
||||||
|
else
|
||||||
|
format.html { redirect_to crm_customers_path}
|
||||||
|
end
|
||||||
|
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class Customer < ApplicationRecord
|
|||||||
has_many :sales
|
has_many :sales
|
||||||
|
|
||||||
validates_presence_of :name, :contact_no, :email #,:card_no
|
validates_presence_of :name, :contact_no, :email #,:card_no
|
||||||
validates :contact_no, uniqueness: true, numericality: true
|
validates :contact_no, numericality: true #uniqueness: true,
|
||||||
validates :email, uniqueness: true,format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create }
|
validates :email, uniqueness: true,format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create }
|
||||||
# validates :card_no, uniqueness: true
|
# validates :card_no, uniqueness: true
|
||||||
# validates :paypar_account_no, uniqueness: true
|
# validates :paypar_account_no, uniqueness: true
|
||||||
|
|||||||
Reference in New Issue
Block a user