add new field
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class Batch < ApplicationRecord
|
||||
has_many :batch_line_item
|
||||
|
||||
def self.create_batch(created_by,date,order_ref, card_qty,user_id,adult_or_child,client_id)
|
||||
def self.create_batch(created_by,date,order_ref, card_qty,user_id,adult_or_child,client_id,product_category_id)
|
||||
batch = Batch.new
|
||||
batch.created_by = created_by
|
||||
batch.order_ref = order_ref
|
||||
@@ -14,6 +14,7 @@ class Batch < ApplicationRecord
|
||||
batch.user_id=user_id
|
||||
batch.export_count=0
|
||||
batch.client_id=client_id
|
||||
batch.product_category_id=product_category_id
|
||||
batch.adult_or_child=adult_or_child.upcase
|
||||
if batch.save
|
||||
return batch
|
||||
|
||||
@@ -2,12 +2,12 @@ class BatchLineItem < ApplicationRecord
|
||||
belongs_to :batch
|
||||
attr_accessor :secret_token
|
||||
attr_accessor :location
|
||||
attr_accessor :product_type
|
||||
|
||||
def self.generate_account_no(location_code)
|
||||
super_merchant = "101"
|
||||
account_type='1'
|
||||
location=location_code
|
||||
|
||||
super_merchant = "101"
|
||||
account_type='1'
|
||||
location=location_code
|
||||
|
||||
o = [('0'..'9')].map { |i| i.to_a }.flatten
|
||||
random_account_no = (0...9).map { o[rand(o.length)] }.join
|
||||
@@ -15,14 +15,13 @@ class BatchLineItem < ApplicationRecord
|
||||
account_no = super_merchant+account_type+location+random_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
|
||||
account_no = super_merchant+account_type+location+random_account_no
|
||||
end
|
||||
o = [('0'..'9')].map { |i| i.to_a }.flatten
|
||||
random_account_no = (0...9).map { o[rand(o.length)] }.join
|
||||
account_no = super_merchant+account_type+location+random_account_no
|
||||
end
|
||||
return account_no
|
||||
end
|
||||
|
||||
def self.generate_serial_no(client_id)
|
||||
end
|
||||
def self.generate_serial_no(client_id)
|
||||
find_lookup=Lookup.find_by_name('generate_serial_no')
|
||||
if !find_lookup.nil?
|
||||
max_value=find_lookup.max_value
|
||||
@@ -47,17 +46,24 @@ class BatchLineItem < ApplicationRecord
|
||||
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}
|
||||
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}
|
||||
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
|
||||
all.each do |encoder|
|
||||
if encoder.product_type_id ==1
|
||||
puts 'Card'
|
||||
str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
|
||||
else
|
||||
puts 'Tickets'
|
||||
str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
|
||||
end
|
||||
|
||||
encryptd_data=BatchLineItem.encrypted(str,encrypt_key)
|
||||
encoder.secret_token=encryptd_data
|
||||
encoder.location=location_code
|
||||
encoder.secret_token=encryptd_data
|
||||
encoder.location=location_code
|
||||
|
||||
csv << attributes.map{ |attr| encoder.send(attr)}
|
||||
end
|
||||
@@ -102,22 +108,12 @@ class BatchLineItem < ApplicationRecord
|
||||
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)
|
||||
# encrypted_data=Digest::MD5.hexdigest(encrypted_data)
|
||||
|
||||
# data=encrypted_data.hex
|
||||
# data=data.to_s
|
||||
|
||||
# return data[0..15]
|
||||
# end
|
||||
arr=Array.new
|
||||
(1..50).each do |i|
|
||||
str= SecureRandom.hex
|
||||
uid=str[0..13]
|
||||
arr.push(uid)
|
||||
end
|
||||
@arr=arr
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user