export to seller csv

This commit is contained in:
nandar
2018-08-01 18:45:27 +06:30
parent b885b658f6
commit 21b58c4bcf
2 changed files with 32 additions and 1 deletions

View File

@@ -198,7 +198,7 @@ class BatchLineItemsController < ApplicationController
filename=client_name.to_s+"_"+product_name.to_s+"_"+datestr
respond_to do |format|
format.html
format.csv { send_data @batchLineItems.to_csv(client_id,location_code), filename: "#{filename}.csv" }
format.csv { send_data @batchLineItems.to_csv_seller(client_id,location_code), filename: "#{filename}.csv" }
end
end

View File

@@ -106,6 +106,37 @@ class BatchLineItem < ApplicationRecord
end
end
end
def self.to_csv_seller(client_id,location_code)
encrypt_key=""
find_client=Client.find_by_id(client_id)
if !find_client.nil?
encrypt_key=find_client.secrect_key
end
attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token location barcode}
CSV.generate(headers: true) do |csv|
csv << attributes
all.each do |encoder|
if encoder.product_type_id ==1
str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
elsif encoder.product_type_id == 3
attributes = attributes+ %w{security_code}
str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s+"&security_code="+encoder.security_code.to_s
else
str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s+"&barcode="+encoder.barcode.to_s
end
encryptd_data=BatchLineItem.encrypted(str,encrypt_key)
encoder.secret_token=encryptd_data
encoder.location=location_code
csv << attributes.map{ |attr| encoder.send(attr)}
end
end
end
def self.encrypted(message,encrypt_key)
cipher = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
cipher.encrypt