Files
nemo_encoder/app/controllers/batch_line_items_controller.rb
2017-02-03 17:56:27 +06:30

41 lines
1.3 KiB
Ruby

class BatchLineItemsController < ApplicationController
require "csv"
skip_before_filter :verify_authenticity_token
before_action :authenticate_member!
def index
user_id=current_member.user_id
@batches=Batch.where('user_id=?',user_id)
@batchLineItems=BatchLineItem.joins('inner join batches on batches.id=batch_line_items.batch_id')
.where('batches.user_id=?',user_id)
.select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page])
end
def export
batch_list=params[:batch]
user_id=current_member.user_id
if !batch_list.nil?
batch_list.each do |batch|
find_batch=Batch.find_by_id(batch)
if !find_batch.nil?
export_count=find_batch.export_count
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