merge with r-19

This commit is contained in:
NyanLinHtut
2020-01-11 11:08:33 +06:30
106 changed files with 2722 additions and 3024 deletions

View File

@@ -83,8 +83,9 @@ class Crm::CustomersController < BaseCrmController
@membership_types = Lookup.collection_of("member_group_type")
# @taxes = TaxProfile.where(:group_type => 'cashier')
@taxes = TaxProfile.unscope(:order).select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name")
.order("group_type ASC,order_by ASC")
@taxes = TaxProfile.unscope(:order).select("tax_profiles.id, CONCAT(tax_profiles.name, '(', lookups.name, ')') as name")
.joins(:lookup)
.order("group_type ASC, order_by ASC")
@filter = filter
@@ -147,104 +148,101 @@ class Crm::CustomersController < BaseCrmController
def new
@crm_customer = Customer.new
@membership = Customer.get_member_group()
end
# GET /crm/customers/1/edit
def edit
@customer = Customer.find(params[:id])
end
def sync
@customer = Customer.find(params[:id])
respond_to do |format|
name = @customer.name
phone = @customer.contact_no
email = @customer.email
dob = @customer.date_of_birth
address = @customer.address
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?
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
respond_to do |format|
name = @customer.name
phone = @customer.contact_no
email = @customer.email
dob = @customer.date_of_birth
address = @customer.address
nrc = @customer.nrc_no
card_no = @customer.card_no
paypar_account_no = @customer.paypar_account_no
id = @customer.membership_id
member_group_id = @customer.membership_type
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
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
# 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
)
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" => "No internet connection "}
rescue HTTParty::Error
response = {"status" => false, "message" => "No internet connection "}
rescue Net::OpenTimeout
response = {"status" => false, "message" => "No internet connection "}
rescue Net::OpenTimeout
response = {"status" => false, "message" => "No internet connection "}
rescue OpenURI::HTTPError
response = {"status" => false, "message" => "No internet connection "}
rescue OpenURI::HTTPError
response = {"status" => false, "message" => "No internet connection "}
rescue SocketError
response = {"status" => false, "message" => "No internet connection "}
end
customer = Customer.find(@crm_customer.customer_id)
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 }
flash[:member_notice] ='Member was successfully synced'
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 )
format.html { redirect_to crm_customers_path }
flash[:member_notice] ='Member was successfully synced'
else
status = customer.update_attributes(membership_type:member_group_id)
end
# When paypar account no not exist in paypar
if response["message"] == "Account does not exist."
customer.destroy
format.html { redirect_to crm_customers_path }
flash[:member_error] ='Member cannot created.Invalid Account.'
else
format.html { redirect_to crm_customers_path }
flash[:member_error] =response["message"]
end
format.html { redirect_to crm_customers_path }
flash[:member_error] =response["message"]
end
end
rescue SocketError
response = {"status" => false, "message" => "No internet connection "}
end
customer = Customer.find(@crm_customer.customer_id)
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 }
flash[:member_notice] ='Member was successfully synced'
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 )
format.html { redirect_to crm_customers_path }
flash[:member_notice] ='Member was successfully synced'
else
status = customer.update_attributes(membership_type:member_group_id)
end
# When paypar account no not exist in paypar
if response["message"] == "Account does not exist."
customer.destroy
format.html { redirect_to crm_customers_path }
flash[:member_error] ='Member cannot created.Invalid Account.'
else
format.html { redirect_to crm_customers_path }
flash[:member_error] =response["message"]
end
format.html { redirect_to crm_customers_path }
flash[:member_error] =response["message"]
end
end
end
end
# POST /crm/customers
# POST /crm/customers.json