This commit is contained in:
Sunandar
2017-02-08 18:11:45 +06:30
parent 43ada02033
commit 9dc6fd3cbe
8 changed files with 46 additions and 23 deletions

View File

@@ -22,7 +22,8 @@ class Api::BatchLineItemsController < ApplicationController
find_user=Client.find_by_id(find_batch.client_id)
if !find_user.nil?
encrypt_key=find_user.secrect_key
encrypt_key=find_user.secrect_key
location_code=find_user.location_code
# product_type=find_user.product_type
client_id=find_user.id
@@ -32,7 +33,7 @@ class Api::BatchLineItemsController < ApplicationController
serial_no=BatchLineItem.generate_serial_no(client_id.to_s)
if product_type ==1
asset_identity=BatchLineItem.generate_account_no
asset_identity=BatchLineItem.generate_account_no(location_code)
@out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
elsif product_type==2
str="manufacture_uid="+manufacture_uid.to_s+"&serial_no="+serial_no.to_s

View File

@@ -62,7 +62,9 @@ class BatchLineItemsController < ApplicationController
@clients=Client.all
@batches=Batch.where('user_id=?',user_id)
client_id=params[:client]
client_id=params[:client]
find_client=Client.find_by_id(client_id)
location_code=find_client.location_code
if params[:batch].present?
batch_list=params[:batch]
@@ -70,17 +72,17 @@ 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,'' as location")
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+")"
@batchLineItems = BatchLineItem.joins('inner join '+sub_query+' as batches on batches.id=batch_line_items.batch_id').select("*,'' as secret_token")
@batchLineItems = BatchLineItem.joins('inner join '+sub_query+' as batches on batches.id=batch_line_items.batch_id').select("*,'' as secret_token,'' as location")
end
if !@batchLineItems.empty?
respond_to do |format|
format.html
format.csv { send_data @batchLineItems.to_csv(client_id), filename: "encoder-#{Date.today}.csv" }
format.csv { send_data @batchLineItems.to_csv(client_id,location_code), filename: "encoder-#{Date.today}.csv" }
end
else
flash[:message] = "No data to export."

View File

@@ -90,6 +90,6 @@ class ClientsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def client_params
params.require(:client).permit(:name,:email, :phone, :address)
params.require(:client).permit(:name,:email, :phone, :address,:location_code)
end
end