Pull from master
This commit is contained in:
@@ -14,14 +14,20 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController
|
||||
end
|
||||
|
||||
if status
|
||||
check_customer = Customer.find_by_email_and_membership_id_and_customer_type(params[:email],params[:membership_id],'Doemal')
|
||||
if !check_customer.nil?
|
||||
customer_id = check_customer.customer_id
|
||||
if params[:customer_id] && !params[:customer_id].nil?
|
||||
customer = OrderReservation.addCustomer(params)
|
||||
customer_id = customer.customer_id
|
||||
else
|
||||
customer = OrderReservation.addCustomer(params)
|
||||
customer_id = customer.id
|
||||
check_customer = Customer.find_by_email_and_membership_id_and_customer_type(params[:email],params[:membership_id],'Doemal')
|
||||
if !check_customer.nil?
|
||||
customer_id = check_customer.customer_id
|
||||
else
|
||||
customer = OrderReservation.addCustomer(params)
|
||||
customer_id = customer.customer_id
|
||||
end
|
||||
end
|
||||
if !customer_id.nil?
|
||||
|
||||
if customer_id.nil?
|
||||
render :json => { :status => false, :message => "email and customer are already existed!" }
|
||||
else
|
||||
render :json => { :status => true, :data => { :customer_id => customer_id} }
|
||||
|
||||
@@ -98,14 +98,154 @@ class Crm::CustomersController < BaseCrmController
|
||||
# POST /crm/customers.json
|
||||
def create
|
||||
# Remove "" default first
|
||||
params[:customer][:tax_profiles].delete_at(0)
|
||||
@crm_customers = Customer.new(customer_params)
|
||||
params[:customer][:tax_profiles].delete_at(0)
|
||||
@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
|
||||
# update tax profile
|
||||
customer = Customer.find(@crm_customers.customer_id)
|
||||
customer.update_attributes(tax_profiles: params[:customer][:tax_profiles])
|
||||
if @crm_customers.save
|
||||
# update tax profile
|
||||
customer = Customer.find(@crm_customers.customer_id)
|
||||
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]
|
||||
phone = customer_params[:contact_no]
|
||||
email = customer_params[:email]
|
||||
@@ -114,9 +254,10 @@ class Crm::CustomersController < BaseCrmController
|
||||
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]
|
||||
id = @crm_customer.membership_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")
|
||||
memberaction = MembershipAction.find_by_membership_type("create_membership_customer")
|
||||
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
|
||||
|
||||
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
|
||||
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,
|
||||
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
|
||||
end
|
||||
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'
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json; version=3'
|
||||
},
|
||||
:timeout => 10
|
||||
)
|
||||
)
|
||||
rescue Net::OpenTimeout
|
||||
response = { status: false }
|
||||
|
||||
rescue HTTParty::Error
|
||||
response = {"status" => false, "message" => "Can't open membership server "}
|
||||
rescue OpenURI::HTTPError
|
||||
response = { status: false}
|
||||
|
||||
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 "}
|
||||
rescue SocketError
|
||||
response = { status: false}
|
||||
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
|
||||
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 )
|
||||
|
||||
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 }
|
||||
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated'}
|
||||
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'}
|
||||
# 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
|
||||
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created. ' }
|
||||
end
|
||||
end
|
||||
else
|
||||
status = customer.update_attributes(membership_type:member_group_id)
|
||||
end
|
||||
|
||||
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 }
|
||||
format.html { redirect_to crm_customers_path, notice: response["error"] }
|
||||
end
|
||||
else
|
||||
flash[:errors] = @crm_customers.errors
|
||||
format.html { redirect_to crm_customers_path}
|
||||
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
else
|
||||
|
||||
flash[:errors] = @crm_customer.errors
|
||||
format.html { redirect_to crm_customers_path}
|
||||
format.json { render json: @crm_customer.errors, status: :unprocessable_entity }
|
||||
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
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class HomeController < ApplicationController
|
||||
redirect_to origami_root_path
|
||||
elsif @employee.role == "waiter"
|
||||
session[:session_token] = @employee.token_session
|
||||
redirect_to origami_dashboard_path
|
||||
route_by_role(@employee)
|
||||
elsif @employee.role == "account"
|
||||
session[:session_token] = @employee.token_session
|
||||
redirect_to reports_dailysale_index_path
|
||||
|
||||
@@ -25,15 +25,18 @@ class Origami::DashboardController < BaseOrigamiController
|
||||
|
||||
@sale_data = Array.new
|
||||
@total_payment_methods = Sale.total_payment_methods(today,current_user)
|
||||
|
||||
@total_payment_methods.each do |payment|
|
||||
if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb"
|
||||
pay = Sale.payment_sale('card', today, current_user)
|
||||
@sale_data.push({'card' => pay.payment_amount})
|
||||
else
|
||||
pay = Sale.payment_sale(payment.payment_method, today, current_user)
|
||||
@sale_data.push({payment.payment_method => pay.payment_amount})
|
||||
end
|
||||
if !@total_payment_methods.nil?
|
||||
@total_payment_methods.each do |payment|
|
||||
if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb"
|
||||
pay = Sale.payment_sale('card', today, current_user)
|
||||
@sale_data.push({'card' => pay.payment_amount})
|
||||
else
|
||||
pay = Sale.payment_sale(payment.payment_method, today, current_user)
|
||||
@sale_data.push({payment.payment_method => pay.payment_amount})
|
||||
end
|
||||
end
|
||||
else
|
||||
@sale_data = nil
|
||||
end
|
||||
@summ_sale = Sale.summary_sale_receipt(today,current_user)
|
||||
@total_customer = Sale.total_customer(today,current_user)
|
||||
@@ -45,12 +48,16 @@ class Origami::DashboardController < BaseOrigamiController
|
||||
@total_order = Sale.total_order(today,current_user)
|
||||
@total_accounts = Sale.total_account(today,current_user)
|
||||
@account_data = Array.new
|
||||
@total_accounts.each do |account|
|
||||
acc = Sale.account_data(account.account_id, today,current_user)
|
||||
if !acc.nil?
|
||||
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
|
||||
end
|
||||
end
|
||||
if !@total_accounts.nil?
|
||||
@total_accounts.each do |account|
|
||||
acc = Sale.account_data(account.account_id, today,current_user)
|
||||
if !acc.nil?
|
||||
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
|
||||
end
|
||||
end
|
||||
else
|
||||
@account_data = nil
|
||||
end
|
||||
|
||||
@top_items = Sale.top_items(today,current_user)
|
||||
@total_foc_items = Sale.total_foc_items(today,current_user)
|
||||
|
||||
Reference in New Issue
Block a user