diff --git a/app/controllers/batch_line_items_controller.rb b/app/controllers/batch_line_items_controller.rb
index 1dedb52..16bbd4d 100644
--- a/app/controllers/batch_line_items_controller.rb
+++ b/app/controllers/batch_line_items_controller.rb
@@ -32,7 +32,6 @@ class BatchLineItemsController < ApplicationController
client_id=params[:client]
product_category_id=params[:product_category]
-
@batchLineItems=nil
if !batch_list.empty?
diff --git a/app/controllers/batches_controller.rb b/app/controllers/batches_controller.rb
index eab4ec1..198bd66 100644
--- a/app/controllers/batches_controller.rb
+++ b/app/controllers/batches_controller.rb
@@ -2,8 +2,53 @@ class BatchesController < ApplicationController
skip_before_filter :verify_authenticity_token
before_action :authenticate_member!
def index
+ @product_category_id=""
+ @clients=Client.all.order('id desc')
+ @product_categories=ProductCategory.all.order('id desc')
@batches=Batch.joins('inner join users on users.id=batches.user_id')
.select('batches.*,users.name as user_name').order('batches.id desc').page(params[:page])
+ @count = Batch.joins('inner join users on users.id=batches.user_id')
+ .select('batches.*').count
end
+
+ def search
+ client_id=params[:client_id]
+ product_category_id=params[:product_category_id]
+ search_keyword = params[:search_keyword]
+
+ if client_id == "" && product_category_id == "" && search_keyword == "" then
+ @batches=Batch.joins('inner join users on users.id=batches.user_id')
+ .select('batches.*,users.name as user_name').order('batches.id desc').page(params[:page])
+ @count = Batch.joins('inner join users on users.id=batches.user_id')
+ .select('batches.*').count
+
+ elsif client_id == "" && product_category_id == "" then
+ @batches=Batch.joins('inner join users on users.id=batches.user_id')
+ .select('batches.*,users.name as user_name').where('LOWER(order_ref) like ?', "%#{params[:search_keyword]}%").order('batches.id desc').page(params[:page])
+ @count=Batch.joins('inner join users on users.id=batches.user_id')
+ .select('batches.*').where('LOWER(order_ref) like ?', "%#{params[:search_keyword]}%").count
+
+ elsif client_id == "" then
+ @batches=Batch.joins('inner join users on users.id=batches.user_id')
+ .select('batches.*,users.name as user_name').where('product_category_id=? and LOWER(order_ref) like ?',params[:product_category_id], "%#{params[:search_keyword]}%").order('batches.id desc').page(params[:page])
+
+ @count=Batch.joins('inner join users on users.id=batches.user_id')
+ .select('batches.*').where('product_category_id=? and LOWER(order_ref) like ?',params[:product_category_id], "%#{params[:search_keyword]}%").count
+
+
+ elsif product_category_id == "" then
+ @batches=Batch.joins('inner join users on users.id=batches.user_id')
+ .select('batches.*,users.name as user_name').where('client_id=? and LOWER(order_ref) like ?', params[:client_id], "%#{params[:search_keyword]}%").order('batches.id desc').page(params[:page])
+
+ @count=Batch.joins('inner join users on users.id=batches.user_id')
+ .select('batches.*').where('client_id=? and LOWER(order_ref) like ?', params[:client_id], "%#{params[:search_keyword]}%").count
+ else
+ @batches=Batch.joins('inner join users on users.id=batches.user_id')
+ .select('batches.*,users.name as user_name').where('product_category_id=? and client_id=? and LOWER(order_ref) like ?',params[:product_category_id], params[:client_id], "%#{params[:search_keyword]}%").order('batches.id desc').page(params[:page])
+ @count=Batch.joins('inner join users on users.id=batches.user_id')
+ .select('batches.*').where('product_category_id=? and client_id=? and LOWER(order_ref) like ?',params[:product_category_id], params[:client_id], "%#{params[:search_keyword]}%").count
+
+ end
+ end
end
\ No newline at end of file
diff --git a/app/views/batch_line_items/index.html.erb b/app/views/batch_line_items/index.html.erb
index d5739b4..de30f4c 100644
--- a/app/views/batch_line_items/index.html.erb
+++ b/app/views/batch_line_items/index.html.erb
@@ -1,26 +1,25 @@
- <%= form_tag export_path(:format => :csv),:method => :post do%>
-
-
- <%= select_tag "client", options_from_collection_for_select(@clients, "id", "name"), :class => 'form-control'%>
-
-
-
- <%= select_tag "product_category", options_from_collection_for_select(@product_categories, "id", "name"), :class => 'form-control'%>
-
-
-
-
-
- <%= button_tag "Export csv?",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %>
-
- <% end %>
+ <%= form_tag export_path(:format => :csv),:method => :post do%>
+
+
+ <%= select_tag "client", options_from_collection_for_select(@clients, "id", "name"), :class => 'form-control'%>
+
+
+
+ <%= select_tag "product_category", options_from_collection_for_select(@product_categories, "id", "name"), :class => 'form-control'%>
+
+
+
+
+ <%= button_tag "Export csv?",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %>
+
+ <% end %>