edit api
This commit is contained in:
@@ -2,40 +2,49 @@ class BatchLineItemsController < ApplicationController
|
|||||||
require "csv"
|
require "csv"
|
||||||
skip_before_filter :verify_authenticity_token
|
skip_before_filter :verify_authenticity_token
|
||||||
before_action :authenticate_member!
|
before_action :authenticate_member!
|
||||||
|
respond_to :json, :html
|
||||||
|
|
||||||
def index
|
def index
|
||||||
user_id=current_member.user_id
|
user_id=current_member.user_id
|
||||||
|
|
||||||
|
@clients=Client.all
|
||||||
|
|
||||||
@batches=Batch.where('user_id=?',user_id)
|
@batches=Batch.where('user_id=?',user_id)
|
||||||
@batchLineItems=BatchLineItem.joins('inner join batches on batches.id=batch_line_items.batch_id')
|
@batchLineItems=BatchLineItem.joins('inner join batches on batches.id=batch_line_items.batch_id')
|
||||||
.where('batches.user_id=?',user_id)
|
.where('batches.user_id=?',user_id)
|
||||||
.select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page])
|
.select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page])
|
||||||
end
|
end
|
||||||
def export
|
def get_batch
|
||||||
batch_list=params[:batch]
|
client_id=params[:client_id]
|
||||||
user_id=current_member.user_id
|
batches=Batch.where('client_id=?',client_id)
|
||||||
if !batch_list.nil?
|
if !batches.nil?
|
||||||
batch_list.each do |batch|
|
respond_with(data: batches,status: true)
|
||||||
find_batch=Batch.find_by_id(batch)
|
else
|
||||||
if !find_batch.nil?
|
respond_with(data: nil,status: false)
|
||||||
export_count=find_batch.export_count
|
end
|
||||||
find_batch.export_count=export_count.to_i+1
|
|
||||||
find_batch.save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@batchLineItems = BatchLineItem.where('batch_id in (?) ',batch_list).select('*')
|
|
||||||
else
|
|
||||||
batches=Batch.all
|
|
||||||
batches.each do |batch|
|
|
||||||
export_count=batch.export_count
|
|
||||||
batch.export_count=export_count.to_i+1
|
|
||||||
batch.save
|
|
||||||
end
|
|
||||||
@batchLineItems = BatchLineItem.all.select('serial_no,wristband_code,batch_id,manufacture_uid,card_type')
|
|
||||||
end
|
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.html
|
|
||||||
format.csv { send_data @batchLineItems.to_csv(user_id), filename: "encoder-#{Date.today}.csv" }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
def export
|
||||||
|
batch_list=""
|
||||||
|
if params[:batch].present?
|
||||||
|
batch_list=params[:batch]
|
||||||
|
end
|
||||||
|
client_id=params[:client]
|
||||||
|
|
||||||
|
user_id=current_member.user_id
|
||||||
|
if !batch_list.empty?
|
||||||
|
if batch_list=="ALL"
|
||||||
|
Batch.where("client_id=?",client_id).update_all("export_count = export_count + 1")
|
||||||
|
@batchLineItems = BatchLineItem.where('client_id=?',client_id).select('serial_no,wristband_code,batch_id,manufacture_uid,card_type')
|
||||||
|
else
|
||||||
|
Batch.where("client_id=? and batch_id in (?)",client_id,batch_list).update_all("export_count = export_count + 1")
|
||||||
|
@batchLineItems = BatchLineItem.where('client_id=? and batch_id in (?)',client_id,batch_list).select('*')
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.csv { send_data @batchLineItems.to_csv(user_id), filename: "encoder-#{Date.today}.csv" }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
redirect_to batch_line_items_path, notice: 'No batch to export for this client.'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -4,21 +4,32 @@
|
|||||||
<a class="breadcrumb-item active" href="#">Batch Line Item List</a>
|
<a class="breadcrumb-item active" href="#">Batch Line Item List</a>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row top-content">
|
<div class="row top-content">
|
||||||
|
<% flash.each do |name, msg| %>
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<a class="close" data-dismiss="alert">×</a>
|
||||||
|
<%= msg %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<br><br>
|
||||||
<%= form_tag export_path(:format => :csv),:method => :post do%>
|
<%= form_tag export_path(:format => :csv),:method => :post do%>
|
||||||
<div class="col-lg-7">
|
<div class="col-lg-4">
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-3">
|
||||||
|
<%= select_tag "client", options_from_collection_for_select(@clients, "id", "name"),:class => 'form-control'%>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-5">
|
<div class="col-lg-5">
|
||||||
<label><strong>Choose Batch:</strong></label>
|
<label><strong>Choose Batch:</strong></label>
|
||||||
<select class='selectpicker' id='batch' name='batch[]' multiple= "multiple" >
|
<select class='selectpicker' id='batch' name='batch[]' multiple= "multiple" >
|
||||||
<% @batches.each do |batch| %>
|
<!--<% @batches.each do |batch| %>
|
||||||
<option value="<%= batch.id %>"><%= batch.order_ref %></option>
|
<option value="<%= batch.id %>"><%= batch.order_ref %></option>
|
||||||
<% end %>
|
<% end %> -->
|
||||||
</select>
|
</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" %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="row content">
|
<div class="row content">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
@@ -58,9 +69,33 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$('#batch').multiselect()
|
client_id=$("#client").val();
|
||||||
$("#batch").multiselect("refresh");
|
get_batch(client_id)
|
||||||
|
$('#client').on('change', function() {
|
||||||
|
client_id=$(this).val()
|
||||||
|
get_batch(client_id)
|
||||||
|
});
|
||||||
|
function get_batch(client_id){
|
||||||
|
$('#batch').multiselect('disable');
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: '<%= get_batch_path %>',
|
||||||
|
dataType: "json",
|
||||||
|
data : {'client_id':client_id },
|
||||||
|
success: function(result){
|
||||||
|
if (result.status){
|
||||||
|
$('#batch').multiselect('enable');
|
||||||
|
$("#batch").empty();
|
||||||
|
$("#batch").append("<option value='all'>ALL</option>")
|
||||||
|
$.each(result.data, function (i, item){
|
||||||
|
$("#batch").append("<option value="+item.id+">"+ item.order_ref +"</option>")
|
||||||
|
});
|
||||||
|
$('#batch').multiselect("refresh");
|
||||||
|
$("#batch").multiselect('rebuild');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@@ -15,7 +15,8 @@ Rails.application.routes.draw do
|
|||||||
get 'check_registered_email' => "users#check_registered_email"
|
get 'check_registered_email' => "users#check_registered_email"
|
||||||
#Encoder
|
#Encoder
|
||||||
match 'batch_line_items/export' => 'batch_line_items#export', :as => 'export', :via => :post
|
match 'batch_line_items/export' => 'batch_line_items#export', :as => 'export', :via => :post
|
||||||
|
|
||||||
|
get 'get_batch' => 'batch_line_items#get_batch',:as => 'get_batch'
|
||||||
namespace :api, defaults: {format: :json} do
|
namespace :api, defaults: {format: :json} do
|
||||||
#login
|
#login
|
||||||
post "auth/login" =>"auth#login"
|
post "auth/login" =>"auth#login"
|
||||||
@@ -31,6 +32,6 @@ Rails.application.routes.draw do
|
|||||||
get "batches/batch_progress_list" =>"batches#batch_progress_list"
|
get "batches/batch_progress_list" =>"batches#batch_progress_list"
|
||||||
|
|
||||||
#client
|
#client
|
||||||
get "clients/list" => 'clients#index'
|
get "clients" => 'clients#index'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user