This commit is contained in:
Nweni
2017-06-30 09:49:51 +06:30
parent 77220ae65b
commit 959102b338
5 changed files with 69 additions and 20 deletions

View File

@@ -6,12 +6,12 @@ class Crm::CustomersController < BaseCrmController
# GET /crm/customers.json
def index
filter = params[:filter]
if filter.nil?
@crm_customers = Customer.all
else
@crm_customers = Customer.search(filter)
@crm_customers = Customer.search(filter)
end
#@crm_customers = Customer.all
@crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(50)
@@ -32,7 +32,7 @@ class Crm::CustomersController < BaseCrmController
def show
@orders = Order.where("customer_id=?", params[:id])
@sales = Sale.where("customer_id=?", params[:id])
if @orders
@order_items = []
@orders.each do |order|
@@ -70,7 +70,7 @@ class Crm::CustomersController < BaseCrmController
def create
@crm_customers = Customer.new(customer_params)
respond_to do |format|
if @crm_customers.save
name = customer_params[:name]
@@ -81,7 +81,7 @@ class Crm::CustomersController < BaseCrmController
nrc = customer_params[:nrc_no]
card_no = customer_params[:card_no]
member_group_id = params[:member_group_id]
if !member_group_id.nil?
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("create_membership_customer")
@@ -90,7 +90,7 @@ class Crm::CustomersController < BaseCrmController
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
begin
response = HTTParty.post(url,
response = HTTParty.post(url,
:body => {name: name,phone: phone,email: email,
dob: dob,address: address,nrc:nrc,card_no:card_no,
member_group_id: member_group_id,
@@ -103,18 +103,24 @@ class Crm::CustomersController < BaseCrmController
)
rescue Net::OpenTimeout
response = { status: false }
rescue OpenURI::HTTPError
response = { status: false}
rescue SocketError
response = { status: false}
end
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]+'/customers', notice: 'Customer was successfully created.' }
else
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created'}
end
end
# format.json { render :index, status: :created, location: @crm_customers }
else
# @crm_customers.destroy
@@ -129,7 +135,7 @@ class Crm::CustomersController < BaseCrmController
if params[:sale_id]
flash[:errors] = @crm_customers.errors
format.html { redirect_to '/origami/'+params[:sale_id]+'/customers'}
format.html { redirect_to '/origami/'+params[:sale_id]+'/customers'}
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
else
flash[:errors] = @crm_customers.errors
@@ -166,7 +172,7 @@ end
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
begin
response = HTTParty.post(url,
response = HTTParty.post(url,
:body => { name: name,phone: phone,email: email,
dob: dob,address: address,nrc:nrc,
card_no:card_no,member_group_id: member_group_id,
@@ -176,16 +182,22 @@ end
'Accept' => 'application/json'
},
:timeout => 10
)
)
rescue Net::OpenTimeout
response = { status: false }
rescue OpenURI::HTTPError
response = { status: false}
rescue SocketError
response = { status: false}
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
format.html { redirect_to crm_customers_path, notice: response["message"] }
@@ -199,7 +211,7 @@ end
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
begin
response = HTTParty.post(url,
response = HTTParty.post(url,
:body => {name: name,phone: phone,email: email,
dob: dob,address: address,nrc:nrc,card_no:card_no,
id: id,member_group_id:member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
@@ -211,6 +223,12 @@ end
)
rescue Net::OpenTimeout
response = { status: false }
rescue OpenURI::HTTPError
response = { status: false}
rescue SocketError
response = { status: false}
end
if response["status"] == true
@@ -219,8 +237,8 @@ end
else
format.html { redirect_to crm_customers_path, notice: response["message"] }
end
end
end
else
@@ -251,7 +269,7 @@ end
# Never trust parameters from the scary internet, only allow the white list through.
def customer_params
params.require(:customer).permit(:name, :company, :contact_no, :email,
params.require(:customer).permit(:name, :company, :contact_no, :email,
:date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no)
end
end