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

@@ -1,11 +1,13 @@
class BatchLineItem < ApplicationRecord
belongs_to :batch
attr_accessor :secret_token
attr_accessor :location
def self.generate_account_no
def self.generate_account_no(location_code)
super_merchant = "101"
account_type='1'
location='101'
location=location_code
o = [('0'..'9')].map { |i| i.to_a }.flatten
random_account_no = (0...9).map { o[rand(o.length)] }.join
@@ -41,20 +43,21 @@ class BatchLineItem < ApplicationRecord
end
end
def self.to_csv(client_id)
def self.to_csv(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}
attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token location}
CSV.generate(headers: true) do |csv|
csv << attributes
all.each do |encoder|
str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
encryptd_data=BatchLineItem.encrypted(str,encrypt_key)
encoder.secret_token=encryptd_data
encoder.location=location_code
csv << attributes.map{ |attr| encoder.send(attr)}
end
@@ -98,7 +101,15 @@ class BatchLineItem < ApplicationRecord
@result=false,'Error occurs in registration encoder!'
end
end
def self.get_array
arr=Array.new
str= SecureRandom.hex(13)
uid=str[0..14]
arr=[
]
end
# def self.encrypted(data,encrypt_key)
# crypt = ActiveSupport::MessageEncryptor.new(encrypt_key)
# encrypted_data = crypt.encrypt_and_sign(data)

View File

@@ -1,4 +1,6 @@
class Client < ApplicationRecord
validates :name, presence: { message: "Please enter client name." }
validates :name, :uniqueness => {:message =>"This client name is already taken." } ,on: :create
validates :location_code ,presence: { message: "Please enter client location code." }
validates :location_code, :uniqueness => {:message =>"This location code is already taken." } ,on: :create
end