qr code generate
This commit is contained in:
@@ -3,6 +3,7 @@ class BatchLineItem < ApplicationRecord
|
||||
attr_accessor :secret_token
|
||||
attr_accessor :location
|
||||
attr_accessor :product_type
|
||||
require 'digest/md5'
|
||||
|
||||
def self.generate_account_no(location_code)
|
||||
super_merchant = "101"
|
||||
@@ -21,6 +22,18 @@ class BatchLineItem < ApplicationRecord
|
||||
end
|
||||
return account_no
|
||||
end
|
||||
def self.generate_security_code
|
||||
|
||||
o = [('0'..'8')].map { |i| i.to_a }.flatten
|
||||
security_code = (0...8).map { o[rand(o.length)] }.join
|
||||
|
||||
find_account_no = BatchLineItem.find_by_security_code(security_code)
|
||||
if !find_account_no.nil?
|
||||
o = [('0'..'8')].map { |i| i.to_a }.flatten
|
||||
security_code = (0...8).map { o[rand(o.length)] }.join
|
||||
end
|
||||
return security_code
|
||||
end
|
||||
def self.generate_serial_no(client_id)
|
||||
find_lookup=Lookup.find_by_name('generate_serial_no')
|
||||
if !find_lookup.nil?
|
||||
@@ -54,16 +67,22 @@ class BatchLineItem < ApplicationRecord
|
||||
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}
|
||||
attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token location security_code}
|
||||
CSV.generate(headers: true) do |csv|
|
||||
csv << attributes
|
||||
all.each do |encoder|
|
||||
if encoder.product_type_id ==1
|
||||
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
|
||||
else
|
||||
str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
|
||||
end
|
||||
|
||||
security_code = encoder.security_code
|
||||
digest = Digest::MD5.hexdigest(security_code)
|
||||
puts 'digest............'
|
||||
puts digest
|
||||
|
||||
encryptd_data=BatchLineItem.encrypted(str,encrypt_key)
|
||||
encoder.secret_token=encryptd_data
|
||||
encoder.location=location_code
|
||||
@@ -89,7 +108,7 @@ class BatchLineItem < ApplicationRecord
|
||||
|
||||
return encrypted
|
||||
end
|
||||
def self.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
|
||||
def self.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type,security_code=nil)
|
||||
batchLineItem=BatchLineItem.new
|
||||
batchLineItem.asset_identity=asset_identity
|
||||
batchLineItem.serial_no=serial_no
|
||||
@@ -98,7 +117,10 @@ class BatchLineItem < ApplicationRecord
|
||||
batchLineItem.asset_type = card_type
|
||||
batchLineItem.encoded_at = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
|
||||
batchLineItem.verified_at =DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
|
||||
|
||||
if !security_code.nil?
|
||||
batchLineItem.security_code = security_code
|
||||
puts 'security_code;fksdfklsdjfklsdfklsdjfklsdjfklsdjflskd'
|
||||
end
|
||||
batch=Batch.find_by_id(batch_id)
|
||||
|
||||
if batchLineItem.save
|
||||
|
||||
Reference in New Issue
Block a user