From b86ae8d32d5c94863de7e304170c5b5138c87fc5 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 13 Jun 2017 20:11:24 +0630 Subject: [PATCH] customer search --- app/controllers/crm/customers_controller.rb | 9 ++-- .../origami/customers_controller.rb | 11 +++-- app/models/customer.rb | 7 ++- app/views/crm/customers/index.html.erb | 43 ++++++++++--------- app/views/layouts/CRM.html.erb | 2 +- app/views/origami/customers/index.html.erb | 29 +++++++------ 6 files changed, 61 insertions(+), 40 deletions(-) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 57f4eafc..f3a1fdf1 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -10,9 +10,12 @@ class Crm::CustomersController < BaseCrmController @crm_customers = Customer.order("customer_id").page(params[:page]) #@products = Product.order("name").page(params[:page]).per(5) else - @crm_customers = Customer.where("name LIKE ?", "%#{filter}%").order("name").page(params[:page]) end + @crm_customers = Customer.search(filter) + + end #@crm_customers = Customer.all - @crm_customer = Customer.new + @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(50) + @crm_customer = Customer.new if flash["errors"] @crm_customer.valid? @@ -52,7 +55,7 @@ class Crm::CustomersController < BaseCrmController membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("get_all_member_account") - merchant_uid = memberaction.merchant_account_id.to_s + 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 diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 7d0b5502..e3fc7378 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -17,12 +17,17 @@ class Origami::CustomersController < BaseOrigamiController @sale_id = params[:sale_id] filter = params[:filter] + filter = params[:filter] + if filter.nil? - @crm_customers = Customer.order("name").page params[:page] + @crm_customers = Customer.order("customer_id").page(params[:page]) + #@products = Product.order("name").page(params[:page]).per(5) else - @crm_customers = Customer.where("name LIKE ?", "%#{filter}%").order("name").page params[:page] + @crm_customers = Customer.search(filter) + end - # @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(2) + #@crm_customers = Customer.all + @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(50) @crm_customer = Customer.new if flash["errors"] diff --git a/app/models/customer.rb b/app/models/customer.rb index b5e101cb..93834b43 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -34,12 +34,17 @@ class Customer < ApplicationRecord def self.search(search) if search - find(:all, :conditions => ['name LIKE ?', "%#{search}%"]) + # find(:all, :conditions => ['name LIKE ? OR contact_no LIKE ?', "%#{search}%", "%#{search}%"]) + where("name LIKE ? OR contact_no LIKE ?", "%#{search}%", "%#{search}%",) else find(:all) end end + # def self.search(search) + # where("name LIKE ? OR contact_no LIKE ?", "%#{search}%", "%#{search}%",) + # end + def lastest_invoices sales.where(:customer_id => self.id).order("created_at desc").limit(5) end diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index d72c6a38..17f207c3 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -14,7 +14,7 @@
-
+
@@ -42,20 +42,21 @@ - <% @crm_customers.each do |crm_customer| %> - - - - <%= crm_customer.name %> - <%= crm_customer.company %> - <%= crm_customer.contact_no %> - <%= crm_customer.email %> - - <%= link_to 'Show', crm_customer_path(crm_customer) %> - - - - + <% if @crm_customers.count > 0 %> + <% @crm_customers.each do |crm_customer| %> + + + + <%= crm_customer.name %> + <%= crm_customer.company rescue '-' %> + <%= crm_customer.contact_no %> + <%= crm_customer.email %> + <%= link_to 'Show', crm_customer_path(crm_customer) %> + + + <% end %> + <%else%> +

There are no record for your search

<% end %> @@ -66,7 +67,7 @@
-
+
<%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %> @@ -115,6 +116,11 @@
<%end%>
+
@@ -216,7 +222,4 @@ $(function() { } - - - - + \ No newline at end of file diff --git a/app/views/layouts/CRM.html.erb b/app/views/layouts/CRM.html.erb index 42b559e2..f1a43726 100644 --- a/app/views/layouts/CRM.html.erb +++ b/app/views/layouts/CRM.html.erb @@ -21,7 +21,7 @@ <% if !flash["errors"]%> - <%=message%> + <%=message%> <% end %>
<% end %> diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index 6fa5ae03..ba6ff75c 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -24,7 +24,8 @@ - <%= form_tag crm_customers_path, :method => :get do %> + <% path ="/origami/#{@sale_id}/customers" %> + <%= form_tag path, :method => :get do %>
@@ -42,17 +43,21 @@ - <% @crm_customers.each do |crm_customer| %> - - - - <%= crm_customer.name %> - <%= crm_customer.company rescue '-' %> - <%= crm_customer.contact_no %> - <%= crm_customer.email %> - - - + <% if @crm_customers.count > 0 %> + <% @crm_customers.each do |crm_customer| %> + + + + <%= crm_customer.name %> + <%= crm_customer.company rescue '-' %> + <%= crm_customer.contact_no %> + <%= crm_customer.email %> + + + + <% end %> + <%else%> +

There are no record for your search

<% end %>