edit csv
This commit is contained in:
@@ -6,12 +6,19 @@ class BatchLineItemsController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
# user_id=current_member.user_id
|
# user_id=current_member.user_id
|
||||||
@clients=Client.all.order('id asc')
|
@product_category_id=""
|
||||||
find_client=Client.select(:id).order('id asc').first
|
@clients=Client.all.order('id desc')
|
||||||
if !find_client.nil?
|
@product_categories=ProductCategory.all.order('id desc')
|
||||||
client_id=find_client.id
|
|
||||||
|
|
||||||
sub_query="(select * from batches where client_id="+client_id.to_s+")"
|
find_client=Client.select(:id).order('id desc').first
|
||||||
|
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')
|
@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)
|
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
|
||||||
else
|
else
|
||||||
@@ -23,17 +30,19 @@ class BatchLineItemsController < ApplicationController
|
|||||||
# user_id=current_member.user_id
|
# user_id=current_member.user_id
|
||||||
batch_list=params[:batch]
|
batch_list=params[:batch]
|
||||||
client_id=params[:client]
|
client_id=params[:client]
|
||||||
|
product_category_id=params[:product_category]
|
||||||
|
|
||||||
|
|
||||||
@batchLineItems=nil
|
@batchLineItems=nil
|
||||||
|
|
||||||
if !batch_list.empty?
|
if !batch_list.empty?
|
||||||
sub_query="(select * from batches where id in ("+batch_list+") and client_id="+client_id.to_s+")"
|
sub_query="(select * from batches where id in ("+batch_list+") and 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')
|
@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)
|
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
|
||||||
|
|
||||||
else
|
else
|
||||||
sub_query="(select * from batches where client_id="+client_id.to_s+")"
|
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')
|
@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)
|
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
|
||||||
|
|
||||||
@@ -45,11 +54,14 @@ class BatchLineItemsController < ApplicationController
|
|||||||
end
|
end
|
||||||
def get_batch
|
def get_batch
|
||||||
client_id=params[:client_id]
|
client_id=params[:client_id]
|
||||||
batches=Batch.where('client_id=?',client_id)
|
product_category_id=params[:product_category_id]
|
||||||
|
|
||||||
|
batches=Batch.where('client_id=? and product_category_id=?',client_id,product_category_id)
|
||||||
|
.select('order_ref,id')
|
||||||
if !batches.nil?
|
if !batches.nil?
|
||||||
render :json => { :data => batches,:status => true }
|
render :json => { :data => batches,:status => true }
|
||||||
# respond_with(data: batches,status: true)
|
# respond_with(data: batches,status: true)
|
||||||
else
|
# else
|
||||||
# respond_with(data: nil,status: false)
|
# respond_with(data: nil,status: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -61,6 +73,7 @@ class BatchLineItemsController < ApplicationController
|
|||||||
@clients=Client.all
|
@clients=Client.all
|
||||||
@batches=Batch.where('user_id=?',user_id)
|
@batches=Batch.where('user_id=?',user_id)
|
||||||
client_id=params[:client]
|
client_id=params[:client]
|
||||||
|
product_category_id=params[:product_category]
|
||||||
find_client=Client.find_by_id(client_id)
|
find_client=Client.find_by_id(client_id)
|
||||||
location_code=find_client.location_code
|
location_code=find_client.location_code
|
||||||
|
|
||||||
@@ -73,31 +86,27 @@ class BatchLineItemsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
if !batch_list.empty?
|
if !batch_list.empty?
|
||||||
res=Batch.where("client_id=? and id in (?)",client_id,batch_list).update_all("export_count = export_count + 1,exported_by='"+exported_by+"'")
|
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+")"
|
||||||
|
|
||||||
# sub_query=Batch.where('id in (?)',batch_list).select('*').to_sql
|
|
||||||
sub_query= "(select * from batches where client_id="+client_id.to_s+")"
|
|
||||||
|
|
||||||
@batchLineItems = BatchLineItem.joins('inner join '+sub_query +" as batches on batches.id=batch_line_items.batch_id")
|
@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')
|
.joins('inner join product_categories product on product.id=batches.product_category_id')
|
||||||
.where('batch_id in (?)',batch_list)
|
.where('batch_id in (?)',batch_list)
|
||||||
.select("*,product.product_type_id ,product.name,'' as secret_token,'' as location")
|
.select("*,product.product_type_id ,product.name,'' as secret_token,'' as location")
|
||||||
else
|
else
|
||||||
Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1,exported_by='"+exported_by+"'")
|
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+")"
|
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')
|
@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')
|
.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")
|
.select("*,product.product_type_id ,product.name,'' as secret_token,'' as location")
|
||||||
end
|
end
|
||||||
|
|
||||||
if !@batchLineItems.empty?
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
format.csv { send_data @batchLineItems.to_csv(client_id,location_code), filename: "encoder-#{Date.today}.csv" }
|
format.csv { send_data @batchLineItems.to_csv(client_id,location_code), filename: "encoder-#{Date.today}.csv" }
|
||||||
end
|
|
||||||
else
|
|
||||||
flash[:message] = "No data to export."
|
|
||||||
redirect_to batch_line_items_path
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -10,7 +10,12 @@
|
|||||||
<label><strong>Select Client:</strong></label>
|
<label><strong>Select Client:</strong></label>
|
||||||
<%= select_tag "client", options_from_collection_for_select(@clients, "id", "name"), :class => 'form-control'%>
|
<%= select_tag "client", options_from_collection_for_select(@clients, "id", "name"), :class => 'form-control'%>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-6">
|
<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>
|
<label><strong>Select Batch:</strong></label><br>
|
||||||
<select class='selectpicker' id='batch' name='batch[]' multiple= "multiple"></select>
|
<select class='selectpicker' id='batch' name='batch[]' multiple= "multiple"></select>
|
||||||
<%= button_tag "Export csv?",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %>
|
<%= button_tag "Export csv?",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %>
|
||||||
@@ -74,47 +79,63 @@
|
|||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$('#loading').hide();
|
$('#loading').hide();
|
||||||
client_id=$("#client").val();
|
client_id=$("#client").val();
|
||||||
get_batch(client_id)
|
$("#product_category").val("<%= @product_category_id %>");
|
||||||
$('#client').on('change', function() {
|
product_category_id=$("#product_category").val()
|
||||||
client_id=$(this).val()
|
|
||||||
get_batch(client_id)
|
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)
|
||||||
});
|
});
|
||||||
function get_batch(client_id){
|
function get_batch(client_id,product_category_id){
|
||||||
$('#batch').multiselect('disable');
|
$('#batch').multiselect('disable');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
url: '<%= get_batch_path %>',
|
url: '<%= get_batch_path %>',
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
data : {'client_id':client_id },
|
data : {'client_id':client_id ,'product_category_id':product_category_id},
|
||||||
success: function(result){
|
success: function(result){
|
||||||
if (result.status){
|
if (result.data){
|
||||||
$('#batch').multiselect('enable');
|
$('#batch').multiselect('enable');
|
||||||
$("#batch").empty();
|
$("#batch").empty();
|
||||||
$.each(result.data, function (i, item){
|
$.each(result.data, function (i, item){
|
||||||
$("#batch").append("<option value="+item.id+">"+ item.order_ref +"</option>")
|
$("#batch").append("<option value="+item.id+">"+ item.order_ref +"</option>")
|
||||||
});
|
});
|
||||||
$('#batch').multiselect("refresh");
|
$('#batch').multiselect("refresh");
|
||||||
$("#batch").multiselect('rebuild');
|
$("#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" ).on('change', function(){
|
||||||
client=$(this).val();
|
client=$(this).val();
|
||||||
batch=$("#batch").val();
|
product_category=$("#product_category").val();
|
||||||
filter(client,batch);
|
batch=$("#batch").val();
|
||||||
|
|
||||||
|
filter(client,product_category,batch);
|
||||||
})
|
})
|
||||||
$('#batch').change(function(){
|
$('#batch').change(function(){
|
||||||
client=$("#client").val();
|
client=$("#client :selected").val();
|
||||||
|
product_category=$("#product_category").val();
|
||||||
batch=$(this).val();
|
batch=$(this).val();
|
||||||
filter(client,batch);
|
filter(client,product_category,batch);
|
||||||
|
|
||||||
});
|
});
|
||||||
function filter(client,batch){
|
function filter(client,product_category,batch){
|
||||||
if (batch==null){
|
if (batch==null){
|
||||||
batch=""
|
batch=""
|
||||||
}
|
}
|
||||||
paramlist='client='+client+"&batch="+batch
|
paramlist='client='+client+"&product_category="+product_category+"&batch="+batch
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type:'GET',
|
type:'GET',
|
||||||
url: '<%= filter_path %>',
|
url: '<%= filter_path %>',
|
||||||
|
|||||||
Reference in New Issue
Block a user