Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant into loyalty
This commit is contained in:
@@ -4,10 +4,13 @@ class Crm::CustomersController < ApplicationController
|
||||
# GET /crm/customers
|
||||
# GET /crm/customers.json
|
||||
def index
|
||||
@crm_customers = Customer.all
|
||||
@customers = Customer.new
|
||||
@sale_id = 0
|
||||
@crm_customers = Customer.all
|
||||
@crm_customer = Customer.new
|
||||
@membership = Customer.get_member_group
|
||||
|
||||
if @membership["status"] == true
|
||||
@member_group = @membership["data"]
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @crm_customers }
|
||||
@@ -33,15 +36,68 @@ class Crm::CustomersController < ApplicationController
|
||||
# POST /crm/customers
|
||||
# POST /crm/customers.json
|
||||
def create
|
||||
@crm_customer = Customer.new(customer_params)
|
||||
|
||||
@crm_customers = Customer.new(customer_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @crm_customer.save
|
||||
format.html { redirect_to @crm_customer, notice: 'Customer was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @crm_customer }
|
||||
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]
|
||||
|
||||
membership = MembershipSetting.find_by_membership_type("smartpay_url")
|
||||
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'
|
||||
}
|
||||
)
|
||||
|
||||
if response["status"] == true
|
||||
puts "hhhhhhhhhhhhhhhhhh"
|
||||
puts params[:sale_id]
|
||||
customer = Customer.find(@crm_customers.customer_id)
|
||||
status = customer.update_attributes(membership_id: response["customer_datas"]["id"])
|
||||
if params[:sale_id] != 0
|
||||
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' }
|
||||
else
|
||||
format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: 'Customer was successfully created.' }
|
||||
end
|
||||
# format.json { render :index, status: :created, location: @crm_customers }
|
||||
else
|
||||
|
||||
@crm_customers.destroy
|
||||
|
||||
if params[:sale_id] != 0
|
||||
format.html { redirect_to crm_customers_path, notice: response["message"] }
|
||||
|
||||
else
|
||||
format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: response["message"] }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
# format.json { render :index, status: :created, location: @crm_customers }
|
||||
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @crm_customer.errors, status: :unprocessable_entity }
|
||||
if params[:sale_id] != 0
|
||||
format.html { redirect_to crm_customers_path}
|
||||
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
|
||||
|
||||
else
|
||||
format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: response["message"] }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -49,14 +105,38 @@ 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'
|
||||
}
|
||||
)
|
||||
|
||||
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 }
|
||||
format.json { render json: @crm_customer.errors, status: :unprocessable_entity }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -70,6 +150,23 @@ class Crm::CustomersController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /crm/customers/1
|
||||
# DELETE /crm/customers/1.json
|
||||
def get_sale_id
|
||||
|
||||
@sale_id = params[:sale_id]
|
||||
@crm_customers = Customer.all
|
||||
@crm_customer = Customer.new
|
||||
@membership = Customer.get_member_group
|
||||
if @membership["status"] == true
|
||||
@member_group = @membership["data"]
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { render action: "index"}
|
||||
format.json { render json: @crm_customers }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_crm_customer
|
||||
@@ -78,6 +175,9 @@ class Crm::CustomersController < ApplicationController
|
||||
|
||||
# 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, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code)
|
||||
|
||||
params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_type, :membership_authentication_code)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -3,22 +3,38 @@ 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_order
|
||||
|
||||
@booking = Booking.find(params[:id])
|
||||
unique_code="CrmOrderPdf"
|
||||
|
||||
print_settings = PrintSetting.find_by_unique_code(unique_code)
|
||||
|
||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||
|
||||
printer.print_crm_order(@booking,print_settings)
|
||||
|
||||
end
|
||||
|
||||
def update_sale_by_customer
|
||||
|
||||
sale = Sale.find(params[:sale_id])
|
||||
status = sale.update_attributes(customer_id: params[:customer_id])
|
||||
|
||||
if status == true
|
||||
render json: JSON.generate({:status => true})
|
||||
else
|
||||
render json: JSON.generate({:status => false, :error_message => "Record not found"})
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
class Origami::DiscountsController < BaseOrigamiController
|
||||
|
||||
#discount page show from origami index with selected order
|
||||
def index
|
||||
sale_id = params[:id]
|
||||
if Sale.exists?(sale_id)
|
||||
@sale_data = Sale.find(sale_id)
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class Origami::RequestBillsController < BaseOrigamiController
|
||||
|
||||
|
||||
def print
|
||||
@sale = Sale.new
|
||||
sale_order=SaleOrder.new
|
||||
@@ -25,4 +26,4 @@ class Origami::RequestBillsController < BaseOrigamiController
|
||||
printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer_name)
|
||||
redirect_to origami_root_path
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user