add new file

This commit is contained in:
Sunandar
2017-02-06 18:32:22 +06:30
parent 90eeb2ea1c
commit 5c78a2ca8a
13 changed files with 54 additions and 120 deletions

View File

@@ -2,9 +2,10 @@ class BatchLineItemsController < ApplicationController
require "csv"
skip_before_filter :verify_authenticity_token
before_action :authenticate_member!
respond_to :json, :html
# respond_to :json, :html,:csv
def index
user_id=current_member.user_id
@clients=Client.all
@@ -18,33 +19,33 @@ class BatchLineItemsController < ApplicationController
client_id=params[:client_id]
batches=Batch.where('client_id=?',client_id)
if !batches.nil?
respond_with(data: batches,status: true)
render :json => { :data => batches,:status => true }
# respond_with(data: batches,status: true)
else
respond_with(data: nil,status: false)
# respond_with(data: nil,status: false)
end
end
def export
def export
batch_list=""
@batchLineItems=""
user_id=current_member.user_id
@clients=Client.all
@batches=Batch.where('user_id=?',user_id)
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
if !batch_list.empty?
Batch.where("client_id=? and id in (?)",client_id,batch_list).update_all("export_count = export_count + 1")
@batchLineItems = BatchLineItem.where('batch_id in (?)',batch_list).select("*,'' as secret_token")
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
format.html
format.csv { send_data @batchLineItems.to_csv(client_id), filename: "encoder-#{Date.today}.csv" }
end
end
end
end