batch_line_item

This commit is contained in:
KhinSuLinn
2017-10-25 14:43:06 +06:30
7 changed files with 251 additions and 65 deletions

View File

@@ -35,7 +35,6 @@ class BatchLineItemsController < ApplicationController
client_id=params[:client]
product_category_id=params[:product_category]
@batchLineItems=nil
if !batch_list.empty?

View File

@@ -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

View File

@@ -1,26 +1,25 @@
<div class="row ">
<nav class="breadcrumb">
<a class="breadcrumb-item active" href="<%= dashboard_path %>">Home</a>
<a class="breadcrumb-item active" href="#">Batch Line Item List</a>
</nav>
<nav class="breadcrumb">
<a class="breadcrumb-item active" href="<%= dashboard_path %>">Home</a>
<a class="breadcrumb-item active" href="#">Batch Line Item List</a>
</nav>
</div>
<div class="row content">
<%= form_tag export_path(:format => :csv),:method => :post do%>
<div class="col-lg-4">
<label><strong>Select Client:</strong></label>
<%= select_tag "client", options_from_collection_for_select(@clients, "id", "name"), :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"), :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> &nbsp; &nbsp;
<%= button_tag "Export csv?",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %>
</div>
<% end %>
<%= form_tag export_path(:format => :csv),:method => :post do%>
<div class="col-lg-4">
<label><strong>Select Client:</strong></label>
<%= select_tag "client", options_from_collection_for_select(@clients, "id", "name"), :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"), :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> &nbsp; &nbsp;
<%= button_tag "Export csv?",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %>
</div>
<% end %>
</div>
<div class="row show_image">
<div class="col-lg-6"></div>
@@ -72,10 +71,9 @@
</table>
<%=paginate @batchLineItems %>
<div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#loading').hide();
@@ -142,7 +140,7 @@ $(document).ready(function(){
function filter(client,product_category,batch){
if (batch==null){
batch=""
}
}
paramlist='client='+client+"&product_category="+product_category+"&batch="+batch
$.ajax({
@@ -157,7 +155,6 @@ $(document).ready(function(){
},
success: function(data) {
}
});
}

View 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>

View File

@@ -1,44 +1,144 @@
<div class="row ">
<nav class="breadcrumb">
<a class="breadcrumb-item active" href="<%= dashboard_path %>">Home</a>
<a class="breadcrumb-item active" href="#">Batches</a>
</nav>
</div>
<nav class="breadcrumb">
<a class="breadcrumb-item active" href="<%= dashboard_path %>">Home</a>
<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 class="card-header">
<strong>Batch List</strong>
</div>
<div class="card-block">
<table class="table" style="border-top:none">
<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 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" 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>
</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>

View 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');

View File

@@ -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