commit by nda

This commit is contained in:
nandar
2018-08-01 17:04:00 +06:30
parent f74d19cb2e
commit b885b658f6
6 changed files with 265 additions and 12 deletions

View File

@@ -14,6 +14,32 @@ class BatchLineItemsController < ApplicationController
@product_category_id=""
@clients=Client.all.order('id desc')
@product_categories=ProductCategory.all.order('id desc')
find_client=Client.select(:id).order('id desc').last
if !find_client.nil?
client_id=find_client.id
find_batch=Batch.where('client_id=?',client_id).order('id desc').first
if !find_batch.nil?
@product_category_id=find_batch.product_category_id
end
sub_query="(select * from batches where client_id="+client_id.to_s+" and product_category_id ="+@product_category_id.to_s+" )"
@batchLineItems=BatchLineItem.joins('inner join '+sub_query+' as batches on batches.id=batch_line_items.batch_id')
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
@result_count= @batchLineItems.total_count
else
@batchLineItems=BatchLineItem.joins('inner join batches on batches.id=batch_line_items.batch_id')
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
@result_count= @batchLineItems.total_count
end
end
def export_to_seller
@product_category_id=""
@clients=Client.all.order('id desc')
@product_categories=ProductCategory.all.order('id desc')
@sellers=User.where("user_type=?","Seller")
find_client=Client.select(:id).order('id desc').last
@@ -35,7 +61,7 @@ class BatchLineItemsController < ApplicationController
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
@result_count= @batchLineItems.total_count
end
end
end
def search
# user_id=current_member.user_id
@@ -84,7 +110,6 @@ class BatchLineItemsController < ApplicationController
@batches=Batch.where('user_id=?',user_id)
client_id=params[:client]
product_category_id=params[:product_category]
seller_id = params[:seller]
find_client=Client.find_by_id(client_id)
location_code=find_client.location_code
client_name=find_client.name.downcase
@@ -100,7 +125,7 @@ class BatchLineItemsController < ApplicationController
end
if !batch_list.empty?
res=Batch.where("client_id=? and product_category_id=? and id in (?)",client_id,product_category_id,batch_list).update_all("export_count = export_count + 1,exported_by='"+exported_by+"',export_to_seller_id='"+seller_id+"'")
res=Batch.where("client_id=? and product_category_id=? and id in (?)",client_id,product_category_id,batch_list).update_all("export_count = export_count + 1,exported_by='"+exported_by+"'")
sub_query= "(select * from batches where client_id="+client_id.to_s+" and product_category_id="+ product_category_id.to_s+")"
@@ -110,7 +135,59 @@ class BatchLineItemsController < ApplicationController
.where('batch_id in (?)',batch_list)
.select("*,product.product_type_id ,product.name,'' as secret_token,'' as location_name")
else
Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1,exported_by='"+exported_by+"',export_to_seller_id='"+seller_id+"'")
Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1,exported_by='"+exported_by+"'")
sub_query="(select * from batches where client_id ="+client_id+" and product_category_id="+ product_category_id+")"
@batchLineItems = BatchLineItem.joins('inner join '+sub_query+' as batches on batches.id=batch_line_items.batch_id')
.joins('inner join product_categories as product on product.id=batches.product_category_id')
.select("*,product.product_type_id ,product.name,'' as secret_token,'' as location_name")
end
datestr= Time.now.strftime("%Y/%m/%d %H:%M:%S")
filename=client_name.to_s+"_"+product_name.to_s+"_"+datestr
respond_to do |format|
format.html
format.csv { send_data @batchLineItems.to_csv(client_id,location_code), filename: "#{filename}.csv" }
end
end
def export_seller
batch_list=""
@batchLineItems=nil
user_id=current_member.user_id
@clients=Client.all
@batches=Batch.where('user_id=?',user_id)
client_id=params[:client]
product_category_id=params[:product_category]
seller_id = params[:seller]
find_client=Client.find_by_id(client_id)
location_code=find_client.location_code
client_name=find_client.name.downcase
find_product=ProductCategory.find_by_id(product_category_id)
product_name=find_product.name.downcase
find_user=User.find_by_id(user_id)
if !find_user.nil?
exported_by=find_user.name
end
if params[:batch].present?
batch_list=params[:batch]
end
today_date = Time.now.to_s
if !batch_list.empty?
res=Batch.where("client_id=? and product_category_id=? and id in (?)",client_id,product_category_id,batch_list).update_all("export_count = export_count + 1,exported_by='"+exported_by+"',export_to_seller_id='"+seller_id+"',export_to_seller_date='"+today_date+"'")
sub_query= "(select * from batches where client_id="+client_id.to_s+" and product_category_id="+ product_category_id.to_s+")"
@batchLineItems = BatchLineItem.joins('inner join '+sub_query +" as batches on batches.id=batch_line_items.batch_id")
.joins('inner join product_categories product on product.id=batches.product_category_id')
.where('batch_id in (?)',batch_list)
.select("*,product.product_type_id ,product.name,'' as secret_token,'' as location_name")
else
# Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1,exported_by='"+exported_by+"',export_to_seller_id='"+seller_id+"',export_to_seller_date='"+today_date+"'")
Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1,exported_by='"+exported_by+"',export_to_seller_id='"+seller_id+"',export_to_seller_date='"+today_date+"'")
sub_query="(select * from batches where client_id ="+client_id+" and product_category_id="+ product_category_id+")"
@batchLineItems = BatchLineItem.joins('inner join '+sub_query+' as batches on batches.id=batch_line_items.batch_id')
.joins('inner join product_categories as product on product.id=batches.product_category_id')

View File

@@ -0,0 +1,173 @@
<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>
</div>
<div class="row content">
<%= form_tag export_seller_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>
<%= button_tag "Export csv?",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %>
</div>
<br/>
<div class="col-lg-3">
<label><strong>Export to Seller:</strong></label>
<%= select_tag "seller", options_from_collection_for_select(@sellers, "id", "name"), :class => 'form-control'%>
</div>
<% end %>
</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 Line Item List</strong>
</div>
<div class="card-block">
<% flash.each do |key, value| %>
<% if key =='message' %>
<div class="alert alert-danger center">
<a class="close" data-dismiss="alert">×</a>
<%= value %>
<% end %>
</div>
<% end %>
<div id ="filterrific_results">
<table class="table" style="border-top:none">
<thead>
<tr><b><i>Batch Line Items ( <%= @result_count %> )</i></b></tr>
<tr>
<th>Serial No</th>
<th>Asset Identity</th>
<th>Manufacture UID</th>
<th>Batch No</th>
<th>Barcode</th>
<th>Created At </th>
<th>Updated At </th>
</tr>
</thead>
<tbody>
<% @batchLineItems.each do |item| %>
<tr>
<td><%= item.serial_no rescue '' %></td>
<td><%= item.asset_identity rescue '' %></td>
<td><%= item.manufacture_uid rescue '' %></td>
<td><%= item.batch_name rescue '' %></td>
<td><%= item.barcode rescue '' %></td>
<td><%= item.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
<td><%= item.updated_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
</tr>
<% end %>
</tbody>
</table>
<%=paginate @batchLineItems %>
<div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#loading').hide();
client_id=$("#client").val();
$("#product_category").val("<%= @product_category_id %>");
product_category_id=$("#product_category").val()
get_batch(client_id,product_category_id)
$('#product_category').on('change', function() {
product_category_id=$(this).val();
client_id=$("#client").val();
get_batch(client_id,product_category_id);
});
$("#client" ).on('change', function(){
client_id=$(this).val();
product_category_id=$("#product_category").val();
get_batch(client_id,product_category_id);
});
function get_batch(client_id,product_category_id){
$('#batch').multiselect('disable');
$.ajax({
type: "GET",
url: '<%= get_batch_path %>',
dataType: "json",
data : {'client_id':client_id ,'product_category_id':product_category_id},
success: function(result){
if (result.data){
$('#batch').multiselect('enable');
$("#batch").empty();
$.each(result.data, function (i, item){
$("#batch").append("<option value="+item.id+">"+ item.order_ref +"</option>")
});
$("#batch").multiselect('refresh');
$("#batch").multiselect('rebuild');
}
}
});
}
$("#product_category").change(function(){
product_category=$(this).val();
client=$("#client").val();
batch=$("#batch").val();
filter(client,product_category,batch);
});
$("#client" ).on('change', function(){
client=$(this).val();
product_category=$("#product_category").val();
batch=$("#batch").val();
filter(client,product_category,batch);
});
$('#batch').change(function(){
client=$("#client :selected").val();
product_category=$("#product_category").val();
batch=$(this).val();
filter(client,product_category,batch);
});
function filter(client,product_category,batch){
if (batch==null){
batch=""
}
paramlist='client='+client+"&product_category="+product_category+"&batch="+batch
$.ajax({
type:'GET',
url: '<%= filter_path %>',
data:paramlist,
beforeSend: function(){
$('#loading').show();
},
complete: function(){
$('#loading').hide();
},
success: function(data) {
}
});
}
$("ul.multiselect-container > li> a > label").attr("style","padding-left:10px");
})
</script>

View File

@@ -22,10 +22,6 @@
<%= button_tag "Export csv?",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %>
</div>
<br/>
<div class="col-lg-3">
<label><strong>Export to Seller:</strong></label>
<%= select_tag "seller", options_from_collection_for_select(@sellers, "id", "name"), :class => 'form-control'%>
</div>
<% end %>

View File

@@ -11,15 +11,20 @@
<li class="nav-item">
<%= link_to "Batches",batches_path, :class => "nav-link" %>
</li>
<li class="nav-item">
<%= link_to "Batch Line Item", batch_line_items_path, :class => "nav-link" %>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Export</a>
<div class="dropdown-menu">
<%= link_to "Export to Client", batch_line_items_path, :class => "dropdown-item" %>
<%= link_to "Export to Seller",export_to_seller_path, :class => "dropdown-item" %>
</div>
</li>
<li class="nav-item">
<%= link_to "User",users_path, :class => "nav-link" %>
</li>
<li class="nav-item">
<%= link_to "Client",clients_path, :class => "nav-link" %>
</li>
</li>
</ul>
<div class="float-xs-right">
<ul class="nav navbar-nav right">