diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index b2c715ad..d7a73ba0 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -81,7 +81,7 @@ 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] + member_group_id = params[:member_group_id] if member_group_id.present? membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -90,13 +90,23 @@ class Crm::CustomersController < BaseCrmController 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 != '' + 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 => {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, + :body => member_params, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' @@ -137,6 +147,12 @@ class Crm::CustomersController < BaseCrmController 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 + format.html { redirect_to '/origami/'+params[:sale_id]+'/customers', notice: 'Customer cannot created.' + response["message"]} + end + if params[:sale_id] format.html { redirect_to '/origami/'+params[:sale_id]+'/customers', notice: 'Customer was successfully created.' + response["message"]} else @@ -181,23 +197,32 @@ end 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] + member_group_id = params[:member_group_id] if id.nil? && !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, + 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 response = HTTParty.post(url, - :body => { name: name,phone: phone,email: email, - 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, + :body => member_params, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' @@ -230,20 +255,30 @@ 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, + 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 response = HTTParty.post(url, - :body => {name: name,phone: phone,email: email, - 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, + :body => member_params, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 26e3c74b..026e59e3 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -8,6 +8,17 @@ class Origami::CustomersController < BaseOrigamiController def show 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 @sale_id = params[:sale_id] @@ -18,9 +29,7 @@ class Origami::CustomersController < BaseOrigamiController @booking_order = BookingOrder.find_by_order_id(@sale_id) @booking = Booking.find(@booking_order.booking_id) @dining_facility = DiningFacility.find(@booking.dining_facility_id) - end - - filter = params[:filter] + end filter = params[:filter] @@ -53,12 +62,12 @@ class Origami::CustomersController < BaseOrigamiController customer_id = params[:customer_id] # Check and find with card no - if(!customer_id.include? "CUS") - customer = Customer.find_by_paypar_account_no(customer_id) - if(customer != nil) - customer_id = customer.customer_id - end - end + # if(!customer_id.include? "CUS") + # customer = Customer.find_by_paypar_account_no(customer_id) + # if(customer != nil) + # customer_id = customer.customer_id + # end + # end if(id == "SAL") sale = Sale.find(params[:sale_id]) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index e6ddf11f..1e14fbc5 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -155,31 +155,35 @@ class Origami::DiscountsController < BaseOrigamiController auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - # Control for Paypar Cloud - begin - response = HTTParty.post(url, - :body => { account_no: nil, - generic_customer_id:generic_customer_id , - campaign_type_id: campaign_type_id, - receipt_no: receipt_no, - merchant_uid:merchant_uid, - campaign_method:arr.to_json, - total_sale_transaction_amount: sale.grand_total, - auth_token:auth_token}.to_json, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - }, :timeout => 10) - rescue HTTParty::Error - response = {:status=> false, :message => "Can't open membership server " } + # Check for items for Paypar Cloud + if arr.length > 0 + begin + response = HTTParty.post(url, + :body => { account_no: nil, + generic_customer_id:generic_customer_id , + campaign_type_id: campaign_type_id, + receipt_no: receipt_no, + merchant_uid:merchant_uid, + campaign_method:arr.to_json, + total_sale_transaction_amount: sale.grand_total, + auth_token:auth_token}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }, :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 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, :message => "Can't open membership server " } + end + else + response = {:status=> false, :message => "You have no selected discount item" } end table_id = sale.bookings[0].dining_facility_id diff --git a/app/models/ability.rb b/app/models/ability.rb index 368aa424..6f7de340 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -38,6 +38,7 @@ class Ability can :index, :receipt_no can :index, :shiftsale + can :get_customer, Customer can :add_customer, Customer can :update_sale_by_customer, Customer @@ -74,7 +75,7 @@ class Ability can :read, Sale can :update, Sale - + can :get_customer, Customer can :add_customer, Customer can :update_sale_by_customer, Customer diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index f882ad29..3c22c2e4 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -229,6 +229,8 @@ // Read Card Reader $("#member_acc_no").on('click', function(e){ var cardNo = ""; + var customer_id = ''; + var customer_name = ''; var sale_id = $("#sale_id").val() || 0; var customer_mamber_card_no = 0; $("#sxModal").show(); @@ -237,8 +239,18 @@ $("#sxModal").hide(); customer_mamber_card_no = $("#search").val(); - if(sale_id != 0 && customer_mamber_card_no != 0){ - update_sale(customer_mamber_card_no,sale_id); + if(sale_id != 0 && customer_mamber_card_no != 0){ + $.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); }); @@ -263,10 +275,11 @@ $(this).closest('tr').find('.checkbox_check').prop( "checked", true ); var sale_id = $("#sale_id").val() || 0; var customer_id = $(this).attr('data-ref'); + var customer_name = $(this).children("td:nth-child(3)").text(); if(sale_id != 0){ // var url = "/"+customer_id; - update_sale(customer_id,sale_id); + update_sale(customer_id, customer_name,sale_id); }else{ 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({ title: 'Confirm!', - content: 'Are You Sure to assign this customer!', + content: 'Are You Sure to assign this customer' + customer + '!', buttons: { cancel: function () { diff --git a/config/routes.rb b/config/routes.rb index d285cc2e..c6ce7860 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -160,6 +160,7 @@ Rails.application.routes.draw do get '/:sale_id/customers', to: "customers#add_customer" 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/get_customer' => "customers#get_customer" end #--------- Waiter/Ordering Station ------------# diff --git a/dump.rdb b/dump.rdb index 7ef23891..7c136cd5 100644 Binary files a/dump.rdb and b/dump.rdb differ