finished customer and join membership in crm

This commit is contained in:
Aung Myo
2017-06-07 16:38:24 +06:30
parent 9e3eaaf214
commit 387ffa996b
14 changed files with 248 additions and 92 deletions

View File

@@ -4,8 +4,8 @@ class Crm::CustomersController < ApplicationController
# GET /crm/customers
# GET /crm/customers.json
def index
@crm_customers = Customer.all
@crm_customer = Customer.new
@crm_customers = Customer.all
@crm_customer = Customer.new
@membership = Customer.get_member_group
if @membership["status"] == true
@member_group = @membership["data"]
@@ -35,12 +35,11 @@ class Crm::CustomersController < ApplicationController
# POST /crm/customers
# POST /crm/customers.json
def create
puts "Hello"
puts customer_params.to_json
@crm_customers = Customer.new(customer_params)
respond_to do |format|
if @crm_customers.save
name = customer_params[:name]
phone = customer_params[:contact_no]
@@ -52,23 +51,33 @@ class Crm::CustomersController < ApplicationController
app_token = membership.auth_token.to_s
url = membership.gateway_url.to_s + "/api/create_membership_customer".to_s
response = HTTParty.post(url,
:body => { name: name,phone: phone,email: email,date_of_birth: date_of_birth,membership_id: membership_id}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}
)
response = HTTParty.post(url, :body => { name: name,phone: phone,email: email,
date_of_birth: date_of_birth,
membership_id: membership_id}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}
)
puts "rrrrrrrrrrrrrr"
puts response.to_json
if response["status"] == true
customer = Customer.find(@crm_customers.customer_id)
status = customer.update_attributes(membership_id: response["customer_datas"]["id"])
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' }
format.json { render :index, status: :created, location: @crm_customers }
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' }
# format.json { render :index, status: :created, location: @crm_customers }
else
@crm_customers.destroy
format.html { redirect_to crm_customers_path, notice: 'Customer was not successfully created.' }
end
# format.json { render :index, status: :created, location: @crm_customers }
else
format.html { render :index }
format.json { render json: @crm_customer.errors, status: :unprocessable_entity }
format.html { redirect_to crm_customers_path}
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
end
end
end
@@ -76,9 +85,30 @@ class Crm::CustomersController < ApplicationController
# PATCH/PUT /crm/customers/1
# PATCH/PUT /crm/customers/1.json
def update
respond_to do |format|
if @crm_customer.update(customer_params)
format.html { redirect_to @crm_customer, notice: 'Customer was successfully updated.' }
name = customer_params[:name]
phone = customer_params[:contact_no]
email = customer_params[:email]
date_of_birth = customer_params[:date_of_birth]
id = customer_params[:membership_id]
membership = MembershipSetting.find_by_membership_type("smartpay_url")
app_token = membership.auth_token.to_s
url = membership.gateway_url.to_s + "/api/update_membership_customer".to_s
response = HTTParty.post(url, :body => { name: name,phone: phone,email: email,
date_of_birth: date_of_birth,
id: id}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}
)
puts response.to_json
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' }
format.json { render :show, status: :ok, location: @crm_customer }
else
format.html { render :edit }

View File

@@ -3,22 +3,24 @@ class Crm::HomeController < BaseCrmController
@booking = Booking.all
@customer = Customer.all
#@booking = Booking.select("bookings.id as booking_id,
# bookings.checkin_at,
# bookings.checkin_by,
# bookings.dining_facility_id,
# od.customer_id as customer,
# od.id as order_id,
# od.item_count as count,
# odt.id as order_item_id,
# odt.item_name as item_name")
# .joins("join booking_orders as bko ON bko.booking_id = bookings.id")
# .joins("right join orders as od ON od.id = bko.order_id")
# .joins("right join order_items as odt ON odt.order_id=od.id")
# .order("bookings.id DESC")
end
def show
end
#print for crm
def print
@booking = Booking.find(params[:id])
unique_code="CrmOrderPdf"
#print_settings = PrintSetting.find_by_unique_code(unique_code)
printer = Printer::ReceiptPrinter.new()
printer.print_crm_order(@booking)
end
end