add new file

This commit is contained in:
Sunandar
2017-02-06 18:32:22 +06:30
parent 90eeb2ea1c
commit 5c78a2ca8a
13 changed files with 54 additions and 120 deletions

View File

@@ -1,8 +1,8 @@
class BatchLineItem < ApplicationRecord
belongs_to :batch
attr_accessor :wristband_token
def self.generate_account_no
attr_accessor :secret_token
def self.generate_account_no
super_merchant = "101"
account_type='1'
location='101'
@@ -41,21 +41,20 @@ class BatchLineItem < ApplicationRecord
end
end
def self.to_csv(user_id)
def self.to_csv(client_id)
encrypt_key=""
find_user=User.find_by_id(user_id)
if !find_user.nil?
encrypt_key=find_user.secrect_key
find_client=Client.find_by_id(client_id)
if !find_client.nil?
encrypt_key=find_client.secrect_key
end
attributes = %w{serial_no wristband_code batch_id manufacture_uid card_type wristband_token}
attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token}
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.wristband_token=encryptd_data
encoder.secret_token=encryptd_data
csv << attributes.map{ |attr| encoder.send(attr)}
end

View File

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