This commit is contained in:
Sunandar
2017-02-08 17:35:37 +06:30
parent 0b4e69d1be
commit 26d42631c7
14 changed files with 140 additions and 95 deletions

View File

@@ -6,8 +6,8 @@ class BatchLineItemsController < ApplicationController
def index
user_id=current_member.user_id
@clients=Client.all.order('id desc')
find_client=Client.select(:id).order('id desc').first
@clients=Client.all.order('id asc')
find_client=Client.select(:id).order('id asc').first
if !find_client.nil?
client_id=find_client.id
@@ -20,7 +20,8 @@ class BatchLineItemsController < ApplicationController
.select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page]).per(10)
end
end
def search
def search
user_id=current_member.user_id
batch_list=params[:batch]
client_id=params[:client]
@@ -38,7 +39,8 @@ class BatchLineItemsController < ApplicationController
@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').page(params[:page])
end
end
# if @batchLineItems.nil?
# @message="No search found!"
# end
@@ -68,7 +70,7 @@ class BatchLineItemsController < ApplicationController
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")
@batchLineItems = BatchLineItem.where('batch_id in (?)',batch_list).select("*,'' as secret_token")
else
Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1")
sub_query="(select * from batches where client_id ="+client_id+" and user_id="+user_id.to_s+")"
@@ -81,7 +83,7 @@ class BatchLineItemsController < ApplicationController
format.csv { send_data @batchLineItems.to_csv(client_id), filename: "encoder-#{Date.today}.csv" }
end
else
flash[:notice] = "No data to export."
flash[:message] = "No data to export."
redirect_to batch_line_items_path
end
end