This commit is contained in:
Sunandar
2017-02-08 17:35:37 +06:30
parent 0b4e69d1be
commit 26d42631c7
14 changed files with 140 additions and 95 deletions

View File

@@ -11,7 +11,7 @@ class BatchLineItem < ApplicationRecord
random_account_no = (0...9).map { o[rand(o.length)] }.join
account_no = super_merchant+account_type+location+random_account_no
find_account_no = BatchLineItem.find_by_wristband_code(account_no)
find_account_no = BatchLineItem.find_by_asset_identity(account_no)
if !find_account_no.nil?
o = [('0'..'9')].map { |i| i.to_a }.flatten
random_account_no = (0...9).map { o[rand(o.length)] }.join
@@ -77,6 +77,27 @@ class BatchLineItem < ApplicationRecord
return encrypted
end
def self.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
batchLineItem=BatchLineItem.new
batchLineItem.asset_identity=asset_identity
batchLineItem.serial_no=serial_no
batchLineItem.batch_id=batch_id
batchLineItem.manufacture_uid = manufacture_uid
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 batchLineItem.save
lookup=Lookup.find_by_name('generate_serial_no')
max_serail_no=lookup.max_value
lookup.max_value=max_serail_no.to_i+1
lookup.save
@result = true,batchLineItem.serial_no,batchLineItem.asset_identity
else
@result=false,'Error occurs in registration encoder!'
end
end
# def self.encrypted(data,encrypt_key)
# crypt = ActiveSupport::MessageEncryptor.new(encrypt_key)