control for member create and member discount
This commit is contained in:
@@ -81,7 +81,7 @@ class Crm::CustomersController < BaseCrmController
|
|||||||
nrc = customer_params[:nrc_no]
|
nrc = customer_params[:nrc_no]
|
||||||
card_no = customer_params[:card_no]
|
card_no = customer_params[:card_no]
|
||||||
paypar_account_no = customer_params[:paypar_account_no]
|
paypar_account_no = customer_params[:paypar_account_no]
|
||||||
member_group_id = params[:member_group_id]
|
member_group_id = params[:member_group_id]
|
||||||
|
|
||||||
if member_group_id.present?
|
if member_group_id.present?
|
||||||
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
||||||
@@ -90,13 +90,23 @@ class Crm::CustomersController < BaseCrmController
|
|||||||
auth_token = memberaction.auth_token.to_s
|
auth_token = memberaction.auth_token.to_s
|
||||||
url = membership.gateway_url.to_s + memberaction.gateway_url.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 != ''
|
||||||
|
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
|
begin
|
||||||
response = HTTParty.post(url,
|
response = HTTParty.post(url,
|
||||||
:body => {name: name,phone: phone,email: email,
|
:body => member_params,
|
||||||
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,
|
|
||||||
:headers => {
|
:headers => {
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
'Accept' => 'application/json'
|
'Accept' => 'application/json'
|
||||||
@@ -137,6 +147,12 @@ class Crm::CustomersController < BaseCrmController
|
|||||||
status = customer.update_attributes(membership_type:member_group_id)
|
status = customer.update_attributes(membership_type:member_group_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# When paypar account no not exist in paypar
|
||||||
|
if response["message"] == "Account has not exist."
|
||||||
|
customer.destroy
|
||||||
|
format.html { redirect_to '/origami/'+params[:sale_id]+'/customers', notice: 'Customer cannot created.' + response["message"]}
|
||||||
|
end
|
||||||
|
|
||||||
if params[:sale_id]
|
if params[:sale_id]
|
||||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/customers', notice: 'Customer was successfully created.' + response["message"]}
|
format.html { redirect_to '/origami/'+params[:sale_id]+'/customers', notice: 'Customer was successfully created.' + response["message"]}
|
||||||
else
|
else
|
||||||
@@ -181,23 +197,32 @@ end
|
|||||||
card_no = customer_params[:card_no]
|
card_no = customer_params[:card_no]
|
||||||
paypar_account_no = customer_params[:paypar_account_no]
|
paypar_account_no = customer_params[:paypar_account_no]
|
||||||
id = @crm_customer.membership_id
|
id = @crm_customer.membership_id
|
||||||
member_group_id = params[:member_group_id]
|
member_group_id = params[:member_group_id]
|
||||||
|
|
||||||
if id.nil? && !member_group_id.nil?
|
if id.nil? && !member_group_id.nil?
|
||||||
|
|
||||||
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
||||||
memberaction = MembershipAction.find_by_membership_type("create_membership_customer")
|
memberaction = MembershipAction.find_by_membership_type("create_membership_customer")
|
||||||
merchant_uid = memberaction.merchant_account_id.to_s
|
merchant_uid = memberaction.merchant_account_id.to_s
|
||||||
auth_token = memberaction.auth_token.to_s
|
auth_token = memberaction.auth_token.to_s
|
||||||
url = membership.gateway_url.to_s + memberaction.gateway_url.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 != ''
|
||||||
|
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
|
begin
|
||||||
response = HTTParty.post(url,
|
response = HTTParty.post(url,
|
||||||
:body => { name: name,phone: phone,email: email,
|
:body => member_params,
|
||||||
dob: dob,address: address,nrc:nrc,
|
|
||||||
paypar_account_no: paypar_account_no,
|
|
||||||
card_no:card_no,member_group_id: member_group_id,
|
|
||||||
merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
|
|
||||||
:headers => {
|
:headers => {
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
'Accept' => 'application/json'
|
'Accept' => 'application/json'
|
||||||
@@ -230,20 +255,30 @@ end
|
|||||||
|
|
||||||
format.html { redirect_to crm_customers_path, notice: response["error"] }
|
format.html { redirect_to crm_customers_path, notice: response["error"] }
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
||||||
memberaction = MembershipAction.find_by_membership_type("update_membership_customer")
|
memberaction = MembershipAction.find_by_membership_type("update_membership_customer")
|
||||||
merchant_uid = memberaction.merchant_account_id.to_s
|
merchant_uid = memberaction.merchant_account_id.to_s
|
||||||
auth_token = memberaction.auth_token.to_s
|
auth_token = memberaction.auth_token.to_s
|
||||||
url = membership.gateway_url.to_s + memberaction.gateway_url.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 != ''
|
||||||
|
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
|
begin
|
||||||
response = HTTParty.post(url,
|
response = HTTParty.post(url,
|
||||||
:body => {name: name,phone: phone,email: email,
|
:body => member_params,
|
||||||
dob: dob,address: address,nrc:nrc,card_no:card_no,
|
|
||||||
paypar_account_no: paypar_account_no,
|
|
||||||
id: id,member_group_id:member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
|
|
||||||
:headers => {
|
:headers => {
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
'Accept' => 'application/json'
|
'Accept' => 'application/json'
|
||||||
|
|||||||
@@ -8,6 +8,17 @@ class Origami::CustomersController < BaseOrigamiController
|
|||||||
def show
|
def show
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_customer
|
||||||
|
filter = params[:filter]
|
||||||
|
if filter.nil?
|
||||||
|
@crm_customers = Customer.order("customer_id").page(params[:page])
|
||||||
|
#@products = Product.order("name").page(params[:page]).per(5)
|
||||||
|
else
|
||||||
|
@crm_customers = Customer.search(filter)
|
||||||
|
end
|
||||||
|
render :json => @crm_customers.to_json
|
||||||
|
end
|
||||||
|
|
||||||
def add_customer
|
def add_customer
|
||||||
|
|
||||||
@sale_id = params[:sale_id]
|
@sale_id = params[:sale_id]
|
||||||
@@ -18,9 +29,7 @@ class Origami::CustomersController < BaseOrigamiController
|
|||||||
@booking_order = BookingOrder.find_by_order_id(@sale_id)
|
@booking_order = BookingOrder.find_by_order_id(@sale_id)
|
||||||
@booking = Booking.find(@booking_order.booking_id)
|
@booking = Booking.find(@booking_order.booking_id)
|
||||||
@dining_facility = DiningFacility.find(@booking.dining_facility_id)
|
@dining_facility = DiningFacility.find(@booking.dining_facility_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
filter = params[:filter]
|
|
||||||
|
|
||||||
filter = params[:filter]
|
filter = params[:filter]
|
||||||
|
|
||||||
@@ -53,12 +62,12 @@ class Origami::CustomersController < BaseOrigamiController
|
|||||||
customer_id = params[:customer_id]
|
customer_id = params[:customer_id]
|
||||||
|
|
||||||
# Check and find with card no
|
# Check and find with card no
|
||||||
if(!customer_id.include? "CUS")
|
# if(!customer_id.include? "CUS")
|
||||||
customer = Customer.find_by_paypar_account_no(customer_id)
|
# customer = Customer.find_by_paypar_account_no(customer_id)
|
||||||
if(customer != nil)
|
# if(customer != nil)
|
||||||
customer_id = customer.customer_id
|
# customer_id = customer.customer_id
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
if(id == "SAL")
|
if(id == "SAL")
|
||||||
sale = Sale.find(params[:sale_id])
|
sale = Sale.find(params[:sale_id])
|
||||||
|
|||||||
@@ -155,31 +155,35 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
auth_token = memberaction.auth_token.to_s
|
auth_token = memberaction.auth_token.to_s
|
||||||
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
|
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
|
||||||
|
|
||||||
# Control for Paypar Cloud
|
# Check for items for Paypar Cloud
|
||||||
begin
|
if arr.length > 0
|
||||||
response = HTTParty.post(url,
|
begin
|
||||||
:body => { account_no: nil,
|
response = HTTParty.post(url,
|
||||||
generic_customer_id:generic_customer_id ,
|
:body => { account_no: nil,
|
||||||
campaign_type_id: campaign_type_id,
|
generic_customer_id:generic_customer_id ,
|
||||||
receipt_no: receipt_no,
|
campaign_type_id: campaign_type_id,
|
||||||
merchant_uid:merchant_uid,
|
receipt_no: receipt_no,
|
||||||
campaign_method:arr.to_json,
|
merchant_uid:merchant_uid,
|
||||||
total_sale_transaction_amount: sale.grand_total,
|
campaign_method:arr.to_json,
|
||||||
auth_token:auth_token}.to_json,
|
total_sale_transaction_amount: sale.grand_total,
|
||||||
:headers => {
|
auth_token:auth_token}.to_json,
|
||||||
'Content-Type' => 'application/json',
|
:headers => {
|
||||||
'Accept' => 'application/json'
|
'Content-Type' => 'application/json',
|
||||||
}, :timeout => 10)
|
'Accept' => 'application/json'
|
||||||
rescue HTTParty::Error
|
}, :timeout => 10)
|
||||||
response = {:status=> false, :message => "Can't open membership server " }
|
rescue HTTParty::Error
|
||||||
|
response = {:status=> false, :message => "Can't open membership server " }
|
||||||
|
|
||||||
rescue Net::OpenTimeout
|
rescue Net::OpenTimeout
|
||||||
response = {:status=> false, :message => "Can't open membership server " }
|
response = {:status=> false, :message => "Can't open membership server " }
|
||||||
rescue OpenURI::HTTPError
|
rescue OpenURI::HTTPError
|
||||||
response = {:status=> false, :message => "Can't open membership server " }
|
response = {:status=> false, :message => "Can't open membership server " }
|
||||||
|
|
||||||
rescue SocketError
|
rescue SocketError
|
||||||
response = {:status=> false, :message => "Can't open membership server " }
|
response = {:status=> false, :message => "Can't open membership server " }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
response = {:status=> false, :message => "You have no selected discount item" }
|
||||||
end
|
end
|
||||||
|
|
||||||
table_id = sale.bookings[0].dining_facility_id
|
table_id = sale.bookings[0].dining_facility_id
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class Ability
|
|||||||
can :index, :receipt_no
|
can :index, :receipt_no
|
||||||
can :index, :shiftsale
|
can :index, :shiftsale
|
||||||
|
|
||||||
|
can :get_customer, Customer
|
||||||
can :add_customer, Customer
|
can :add_customer, Customer
|
||||||
can :update_sale_by_customer, Customer
|
can :update_sale_by_customer, Customer
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ class Ability
|
|||||||
|
|
||||||
can :read, Sale
|
can :read, Sale
|
||||||
can :update, Sale
|
can :update, Sale
|
||||||
|
can :get_customer, Customer
|
||||||
can :add_customer, Customer
|
can :add_customer, Customer
|
||||||
can :update_sale_by_customer, Customer
|
can :update_sale_by_customer, Customer
|
||||||
|
|
||||||
|
|||||||
@@ -229,6 +229,8 @@
|
|||||||
// Read Card Reader
|
// Read Card Reader
|
||||||
$("#member_acc_no").on('click', function(e){
|
$("#member_acc_no").on('click', function(e){
|
||||||
var cardNo = "";
|
var cardNo = "";
|
||||||
|
var customer_id = '';
|
||||||
|
var customer_name = '';
|
||||||
var sale_id = $("#sale_id").val() || 0;
|
var sale_id = $("#sale_id").val() || 0;
|
||||||
var customer_mamber_card_no = 0;
|
var customer_mamber_card_no = 0;
|
||||||
$("#sxModal").show();
|
$("#sxModal").show();
|
||||||
@@ -237,8 +239,18 @@
|
|||||||
$("#sxModal").hide();
|
$("#sxModal").hide();
|
||||||
customer_mamber_card_no = $("#search").val();
|
customer_mamber_card_no = $("#search").val();
|
||||||
|
|
||||||
if(sale_id != 0 && customer_mamber_card_no != 0){
|
if(sale_id != 0 && customer_mamber_card_no != 0){
|
||||||
update_sale(customer_mamber_card_no,sale_id);
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "get_customer" ,
|
||||||
|
data: { filter : customer_mamber_card_no },
|
||||||
|
dataType: "json",
|
||||||
|
success: function(data) {
|
||||||
|
customer_id = data[0].customer_id;
|
||||||
|
customer_name = data[0].name;
|
||||||
|
update_sale(customer_id, customer_name,sale_id);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},100);
|
},100);
|
||||||
});
|
});
|
||||||
@@ -263,10 +275,11 @@
|
|||||||
$(this).closest('tr').find('.checkbox_check').prop( "checked", true );
|
$(this).closest('tr').find('.checkbox_check').prop( "checked", true );
|
||||||
var sale_id = $("#sale_id").val() || 0;
|
var sale_id = $("#sale_id").val() || 0;
|
||||||
var customer_id = $(this).attr('data-ref');
|
var customer_id = $(this).attr('data-ref');
|
||||||
|
var customer_name = $(this).children("td:nth-child(3)").text();
|
||||||
|
|
||||||
if(sale_id != 0){
|
if(sale_id != 0){
|
||||||
// var url = "/"+customer_id;
|
// var url = "/"+customer_id;
|
||||||
update_sale(customer_id,sale_id);
|
update_sale(customer_id, customer_name,sale_id);
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
var url = "customers/"+customer_id;
|
var url = "customers/"+customer_id;
|
||||||
@@ -327,10 +340,15 @@
|
|||||||
// }
|
// }
|
||||||
})
|
})
|
||||||
|
|
||||||
function update_sale(customer_id,sale_id) {
|
function update_sale(customer_id, customer_name, sale_id) {
|
||||||
|
var customer="";
|
||||||
|
if(customer_name != ""){
|
||||||
|
customer = '(' + customer_name + ')';
|
||||||
|
}
|
||||||
|
|
||||||
$.confirm({
|
$.confirm({
|
||||||
title: 'Confirm!',
|
title: 'Confirm!',
|
||||||
content: 'Are You Sure to assign this customer!',
|
content: 'Are You Sure to assign this customer' + customer + '!',
|
||||||
buttons: {
|
buttons: {
|
||||||
|
|
||||||
cancel: function () {
|
cancel: function () {
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ Rails.application.routes.draw do
|
|||||||
get '/:sale_id/customers', to: "customers#add_customer"
|
get '/:sale_id/customers', to: "customers#add_customer"
|
||||||
get '/:customer_id/get_customer' => 'home#get_customer',:as => "show_customer_details"
|
get '/:customer_id/get_customer' => 'home#get_customer',:as => "show_customer_details"
|
||||||
post '/:sale_id/update_sale' , to: "customers#update_sale_by_customer" # update customer id in sale table
|
post '/:sale_id/update_sale' , to: "customers#update_sale_by_customer" # update customer id in sale table
|
||||||
|
post '/:sale_id/get_customer' => "customers#get_customer"
|
||||||
end
|
end
|
||||||
|
|
||||||
#--------- Waiter/Ordering Station ------------#
|
#--------- Waiter/Ordering Station ------------#
|
||||||
|
|||||||
Reference in New Issue
Block a user