This commit is contained in:
Sunandar
2017-02-13 13:12:00 +06:30
parent 5c32fdf7c6
commit febbeda4d6
2 changed files with 79 additions and 49 deletions

View File

@@ -10,7 +10,12 @@
<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-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>
<select class='selectpicker' id='batch' name='batch[]' multiple= "multiple"></select> &nbsp; &nbsp;
<%= button_tag "Export csv?",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %>
@@ -74,47 +79,63 @@
$(document).ready(function(){
$('#loading').hide();
client_id=$("#client").val();
get_batch(client_id)
$('#client').on('change', function() {
client_id=$(this).val()
get_batch(client_id)
$("#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)
});
function get_batch(client_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 },
data : {'client_id':client_id ,'product_category_id':product_category_id},
success: function(result){
if (result.status){
$('#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');
}
}
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();
batch=$("#batch").val();
filter(client,batch);
product_category=$("#product_category").val();
batch=$("#batch").val();
filter(client,product_category,batch);
})
$('#batch').change(function(){
client=$("#client").val();
$('#batch').change(function(){
client=$("#client :selected").val();
product_category=$("#product_category").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){
batch=""
}
paramlist='client='+client+"&batch="+batch
}
paramlist='client='+client+"&product_category="+product_category+"&batch="+batch
$.ajax({
type:'GET',
url: '<%= filter_path %>',