From 21b58c4bcf744c206afd55811c230e1ce9bb86c5 Mon Sep 17 00:00:00 2001 From: nandar Date: Wed, 1 Aug 2018 18:45:27 +0630 Subject: [PATCH] export to seller csv --- .../batch_line_items_controller.rb | 2 +- app/models/batch_line_item.rb | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/controllers/batch_line_items_controller.rb b/app/controllers/batch_line_items_controller.rb index 63ac3a7..577fc6c 100644 --- a/app/controllers/batch_line_items_controller.rb +++ b/app/controllers/batch_line_items_controller.rb @@ -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 diff --git a/app/models/batch_line_item.rb b/app/models/batch_line_item.rb index b107461..da85753 100644 --- a/app/models/batch_line_item.rb +++ b/app/models/batch_line_item.rb @@ -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