export to seller csv
This commit is contained in:
@@ -198,7 +198,7 @@ class BatchLineItemsController < ApplicationController
|
|||||||
filename=client_name.to_s+"_"+product_name.to_s+"_"+datestr
|
filename=client_name.to_s+"_"+product_name.to_s+"_"+datestr
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,37 @@ class BatchLineItem < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
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)
|
def self.encrypted(message,encrypt_key)
|
||||||
cipher = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
|
cipher = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
|
||||||
cipher.encrypt
|
cipher.encrypt
|
||||||
|
|||||||
Reference in New Issue
Block a user