search in batches
This commit is contained in:
@@ -32,7 +32,6 @@ class BatchLineItemsController < ApplicationController
|
||||
client_id=params[:client]
|
||||
product_category_id=params[:product_category]
|
||||
|
||||
|
||||
@batchLineItems=nil
|
||||
|
||||
if !batch_list.empty?
|
||||
|
||||
@@ -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
|
||||
@@ -14,7 +14,6 @@
|
||||
<label><strong>Select Product:</strong></label>
|
||||
<%= select_tag "product_category", options_from_collection_for_select(@product_categories, "id", "name"), :class => 'form-control'%>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-4">
|
||||
<label><strong>Select Batch:</strong></label><br>
|
||||
<select class='selectpicker' id='batch' name='batch[]' multiple= "multiple"></select>
|
||||
@@ -71,10 +70,9 @@
|
||||
</table>
|
||||
<%=paginate @batchLineItems %>
|
||||
<div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
$('#loading').hide();
|
||||
@@ -147,7 +145,6 @@ $(document).ready(function(){
|
||||
$('#loading').hide();
|
||||
},
|
||||
success: function(data) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
36
app/views/batches/_search.html.erb
Normal file
36
app/views/batches/_search.html.erb
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
<div class="card-header">
|
||||
<strong>Batch List</strong>
|
||||
<strong>(Count: <%= @count %> ) </strong>
|
||||
</div>
|
||||
<div class="card-block">
|
||||
<table class="table" style="border-top:none" id="myTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Order Ref</th>
|
||||
<th>Created By</th>
|
||||
<th>Qty Processing</th>
|
||||
<th>Qty Success</th>
|
||||
<th>Qty Fail</th>
|
||||
<th>Export Count</th>
|
||||
<th>Exported By</th>
|
||||
<th>Created At</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @batches.each do |batch| %>
|
||||
<tr>
|
||||
<td><%= batch.order_ref rescue '' %></td>
|
||||
<td><%= batch.user_name rescue '' %></td>
|
||||
<td><%= batch.qty_processing rescue '' %></td>
|
||||
<td><%= batch.qty_success rescue '' %></td>
|
||||
<td><%= batch.qty_fail rescue '' %></td>
|
||||
<td><%= batch.export_count %></td>
|
||||
<td><%= batch.exported_by %></td>
|
||||
<td><%= batch.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<%= paginate @batches %>
|
||||
</div>
|
||||
@@ -4,13 +4,39 @@
|
||||
<a class="breadcrumb-item active" href="#">Batches</a>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="row content">
|
||||
<div class="col-lg-4">
|
||||
<label><strong>Search:</strong></label>
|
||||
<input type="text" id="myInput" class="form-control">
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<label><strong>Select Client:</strong></label>
|
||||
<%= select_tag "client", options_from_collection_for_select(@clients, "id", "name"), prompt: "All", :class => 'form-control'%>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<label><strong>Select Product:</strong></label>
|
||||
<%= select_tag "product_category", options_from_collection_for_select(@product_categories, "id", "name"), prompt: "All", :class => 'form-control'%>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="row show_image">
|
||||
<div class="col-lg-6"></div>
|
||||
<div class="col-lg-4" id="loading">
|
||||
<img src="<%= asset_path( 'spinner.gif' ) %>" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row content">
|
||||
<div class="card">
|
||||
<div id="filterrific_results">
|
||||
<div class="card-header">
|
||||
<strong>Batch List</strong>
|
||||
<strong>(Count: <%= @count %> ) </strong>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="card-block">
|
||||
<table class="table" style="border-top:none">
|
||||
|
||||
<table class="table" style="border-top:none" id="myTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Order Ref</th>
|
||||
@@ -39,6 +65,80 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<%= paginate @batches %>
|
||||
<div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
// function mySearch() {
|
||||
// var input, filter, table, tr, td, i;
|
||||
// input = document.getElementById("myInput");
|
||||
// filter = input.value.toUpperCase();
|
||||
|
||||
// table = document.getElementById("myTable");
|
||||
// tr = table.getElementsByTagName("tr");
|
||||
// for (i = 0; i < tr.length; i++) {
|
||||
// td = tr[i].getElementsByTagName("td")[0];
|
||||
// console.log(td);
|
||||
// if (td) {
|
||||
// console.log(td.innerHTML.toUpperCase().indexOf(filter));
|
||||
// if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
|
||||
// tr[i].style.display = "";
|
||||
// } else {
|
||||
// tr[i].style.display = "none";
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
$(document).ready(function(){
|
||||
|
||||
$('#loading').hide();
|
||||
client_id=$("#client").val();
|
||||
product_category_id=$("#product_category").val();
|
||||
search_keyword=$('#myInput').val();
|
||||
|
||||
|
||||
$('#product_category').on('change', function() {
|
||||
product_category=$(this).val();
|
||||
client=$("#client").val();
|
||||
search_keyword=$('#myInput').val();
|
||||
filter(client,product_category,search_keyword);
|
||||
});
|
||||
|
||||
$('#client').on('change', function() {
|
||||
client=$(this).val();
|
||||
product_category=$("#product_category").val();
|
||||
search_keyword=$('#myInput').val();
|
||||
filter(client,product_category,search_keyword);
|
||||
});
|
||||
|
||||
$('#myInput').keyup(function(){
|
||||
search_keyword = $(this).val().toLowerCase();
|
||||
client=$("#client").val();
|
||||
product_category=$("#product_category").val();
|
||||
filter(client,product_category,search_keyword);
|
||||
|
||||
});
|
||||
|
||||
function filter(client,product_category,search_keyword){
|
||||
|
||||
$.ajax({
|
||||
type:'GET',
|
||||
url: '<%= batch_filter_path %>',
|
||||
data : {'client_id':client ,'product_category_id':product_category,'search_keyword':search_keyword},
|
||||
beforeSend: function(){
|
||||
$('#loading').show();
|
||||
},
|
||||
complete: function(){
|
||||
$('#loading').hide();
|
||||
},
|
||||
success: function(data) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
})
|
||||
</script>
|
||||
6
app/views/batches/search.js.erb
Normal file
6
app/views/batches/search.js.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<% js = escape_javascript(
|
||||
|
||||
render(partial: 'batches/search', locals: { batches: @batches })
|
||||
) %>
|
||||
$("#filterrific_results").html("<%= js %>");
|
||||
$('.pagination a').attr('data-remote', 'true');
|
||||
@@ -13,6 +13,9 @@ Rails.application.routes.draw do
|
||||
|
||||
# #batchlineitems
|
||||
get "batch_line_items/search" =>'batch_line_items#search',:as =>'filter'
|
||||
|
||||
#batches
|
||||
get "batches/search" =>'batches#search',:as =>'batch_filter'
|
||||
#users
|
||||
get 'check_registered_email' => "users#check_registered_email"
|
||||
#Encoder
|
||||
|
||||
@@ -14,6 +14,7 @@ ActiveRecord::Schema.define(version: 20170210103359) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
enable_extension "uuid-ossp"
|
||||
|
||||
create_table "batch_line_items", force: :cascade do |t|
|
||||
t.integer "batch_id"
|
||||
|
||||
Reference in New Issue
Block a user