diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index ffa714a2..93d2f95b 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -6,12 +6,34 @@ class Crm::CustomersController < BaseCrmController # GET /crm/customers.json def index filter = params[:filter] + type = params[:type] if filter.nil? @crm_customers = Customer.all else @crm_customers = Customer.search(filter) - + # search account no from paypar + if !@crm_customers.present? && type == "card" + response = Customer.search_paypar_account_no(filter) + if response["status"] == true + @crm_customers = Customer.new + @crm_customers.name = response["customer_data"]["name"] + @crm_customers.contact_no = response["customer_data"]["phone"] + @crm_customers.email = response["customer_data"]["email"] + @crm_customers.date_of_birth = response["customer_data"]["DOB"] + @crm_customers.nrc_no = response["customer_data"]["NRC"] + @crm_customers.address = response["customer_data"]["address"] + @crm_customers.card_no = response["customer_data"]["customer_card_no"] + @crm_customers.paypar_account_no = filter + @crm_customers.membership_id = response["customer_data"]["id"] + @crm_customers.membership_type = response["customer_data"]["member_group_id"] + @crm_customers.customer_type = "Dinein" + @crm_customers.tax_profiles = ["1", "2"] + @crm_customers.save + @crm_customers = Customer.search(filter) + end + end end + puts @crm_customers #@crm_customers = Customer.all @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(50) @crm_customer = Customer.new diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 8faaa221..a8048ff1 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -9,13 +9,39 @@ class Origami::CustomersController < BaseOrigamiController end def get_customer + filter = params[:filter] + type = params[:type] + 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) + @crm_customers = Customer.search(filter) + # search account no from paypar + if !@crm_customers.present? && type == "card" + response = Customer.search_paypar_account_no(filter) + if response["status"] == true + @crm_customers = Customer.new + @crm_customers.name = response["customer_data"]["name"] + @crm_customers.contact_no = response["customer_data"]["phone"] + @crm_customers.email = response["customer_data"]["email"] + @crm_customers.date_of_birth = response["customer_data"]["DOB"] + @crm_customers.nrc_no = response["customer_data"]["NRC"] + @crm_customers.address = response["customer_data"]["address"] + @crm_customers.card_no = 121212 + @crm_customers.paypar_account_no = filter + @crm_customers.membership_id = response["customer_data"]["id"] + @crm_customers.membership_type = response["customer_data"]["member_group_id"] + @crm_customers.customer_type = "Dinein" + @crm_customers.tax_profiles = ["1", "2"] + @crm_customers.save + else + @crm_customers = {:status=> response["status"],:message=>response["message"] } + end + end end + puts @crm_customers render :json => @crm_customers.to_json end diff --git a/app/models/customer.rb b/app/models/customer.rb index dff92ba2..75978056 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -194,6 +194,41 @@ class Customer < ApplicationRecord end end + def self.search_paypar_account_no(account_no) + membership = MembershipSetting.find_by_membership_type("paypar_url") + memberaction = MembershipAction.find_by_membership_type("search_paypar_account_no") + 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 + begin + response = HTTParty.get(url, + :body => { paypar_account_no:account_no, + merchant_uid:merchant_uid, + auth_token:auth_token + }.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }, + :timeout => 10 + ) + rescue HTTParty::Error + response = {status: false, message: "Server Error"} + + rescue Net::OpenTimeout + response = { status: false , message: "Server Time out"} + + rescue OpenURI::HTTPError + response = { status: false, message: "Can't connect server"} + + rescue SocketError + response = { status: false, message: "Can't connect server"} + end + puts "sssssssssssss" + puts response.to_json + return response + end + def self.search(search) if search # find(:all, :conditions => ['name LIKE ? OR contact_no LIKE ?', "%#{search}%", "%#{search}%"]) diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb index 35c3a46d..c39f065f 100644 --- a/app/views/crm/customers/_new_form.html.erb +++ b/app/views/crm/customers/_new_form.html.erb @@ -169,6 +169,7 @@ if(cardNo.length == 16){ $("#paypar_account_no").val(cardNo); $("#search").val(cardNo); + $("#type").val("card"); } } \ No newline at end of file diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 71772c92..9d2fa62b 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -25,6 +25,7 @@ <%= form_tag crm_customers_path, :id => "filter_form", :method => :get do %>
+ diff --git a/app/views/origami/addorders/show.html.erb b/app/views/origami/addorders/show.html.erb index 2a01d664..fdea2efc 100644 --- a/app/views/origami/addorders/show.html.erb +++ b/app/views/origami/addorders/show.html.erb @@ -114,8 +114,9 @@
+
+
-

@@ -164,7 +165,7 @@ $(function(){ menu_items_list.empty(); menu_items = data.menu_items; - + for(var field in menu_items) { instances = menu_items[field].instances ; @@ -191,7 +192,7 @@ $(function(){ +'' +'' - +"