finished CRM and customer

This commit is contained in:
Aung Myo
2017-06-12 14:23:20 +06:30
parent 0943808ac8
commit e90178cfdc
13 changed files with 121 additions and 62 deletions

View File

@@ -14,9 +14,9 @@ class Crm::CustomersController < BaseCrmController
end
#@crm_customers = Customer.all
@crm_customer = Customer.new
@crm_customer.valid?
if @crm_customer.valid?
@crm_customer.errors.messages
end
# @membership = Customer.get_member_group
# if @membership["status"] == true
# @member_group = @membership["data"]
@@ -54,17 +54,17 @@ class Crm::CustomersController < BaseCrmController
# POST /crm/customers
# POST /crm/customers.json
def create
def create
@crm_customers = Customer.new(customer_params)
respond_to do |format|
if @crm_customers.save
name = customer_params[:name]
phone = customer_params[:contact_no]
email = customer_params[:email]
date_of_birth = customer_params[:date_of_birth]
membership_id = params[:membership_id]
member_group_id = params[:member_group_id]
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("create_membership_customer")
@@ -73,7 +73,7 @@ class Crm::CustomersController < BaseCrmController
response = HTTParty.post(url, :body => { name: name,phone: phone,email: email,
date_of_birth: date_of_birth,
membership_id: membership_id}.to_json,
member_group_id: member_group_id}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
@@ -85,37 +85,34 @@ class Crm::CustomersController < BaseCrmController
customer = Customer.find(@crm_customers.customer_id)
status = customer.update_attributes(membership_id: response["customer_datas"]["id"])
if params[:sale_id].nil?
format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer', notice: 'Customer was successfully created.' }
if params[:sale_id]
format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer', 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
@crm_customers.destroy
if params[:sale_id].nil?
if params[:sale_id]
format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'}
else
format.html { redirect_to crm_customers_path, notice: response["message"] }
end
end
# format.json { render :index, status: :created, location: @crm_customers }
else
if params[:sale_id].nil?
if params[:sale_id]
format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'}
else
format.html { redirect_to crm_customers_path}
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
end
end
end
end
end
@@ -131,6 +128,7 @@ end
email = customer_params[:email]
date_of_birth = customer_params[:date_of_birth]
id = customer_params[:membership_id]
member_group_id = params[:member_group_id]
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("update_membership_customer")
@@ -139,7 +137,7 @@ end
response = HTTParty.post(url, :body => { name: name,phone: phone,email: email,
date_of_birth: date_of_birth,
id: id}.to_json,
id: id,member_group_id:member_group_id}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'