edit api
This commit is contained in:
@@ -4,7 +4,8 @@ class Api::BatchLineItemsController < ApplicationController
|
||||
batch_id=params[:batch_id]
|
||||
session_token=params[:session_token]
|
||||
manufacture_uid = params[:card_manufacture]
|
||||
|
||||
product_category_id=params[:product_category_id]
|
||||
|
||||
client_id=""
|
||||
|
||||
check_member= Member.authenticate_session_token(session_token)
|
||||
@@ -14,69 +15,58 @@ class Api::BatchLineItemsController < ApplicationController
|
||||
|
||||
find_batch = Batch.find_by_id(batch_id)
|
||||
if !find_batch.nil?
|
||||
card_type=find_batch.adult_or_child.upcase
|
||||
find_user=Client.find_by_id(find_batch.client_id)
|
||||
if !find_user.nil?
|
||||
encrypt_key=find_user.secrect_key
|
||||
product_type=find_user.product_type
|
||||
client_id=find_user.id
|
||||
card_type=find_batch.adult_or_child.upcase
|
||||
find_product_category=ProductCategory.find_by_id(product_category_id)
|
||||
if !find_product_category.nil?
|
||||
product_type=find_product_category.product_type_id
|
||||
|
||||
if !encrypt_key.nil?
|
||||
check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid)
|
||||
if check_manufacture.nil?
|
||||
serial_no=BatchLineItem.generate_serial_no(client_id.to_s)
|
||||
if product_type.downcase=="ticket"
|
||||
str="manufacture_uid="+manufacture_uid.to_s+"&serial_no="+serial_no.to_s
|
||||
|
||||
digest_data= Digest::MD5.hexdigest(str)
|
||||
hex_data=digest_data.hex
|
||||
hex_str=hex_data.to_s
|
||||
asset_identity=hex_str[0..15]
|
||||
check_asset=BatchLineItem.find_by_asset_identity(asset_identity)
|
||||
|
||||
if check_asset.nil?
|
||||
@out=create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
|
||||
else
|
||||
@out=false,'Asset Identity is already registered!'
|
||||
find_user=Client.find_by_id(find_batch.client_id)
|
||||
if !find_user.nil?
|
||||
encrypt_key=find_user.secrect_key
|
||||
# product_type=find_user.product_type
|
||||
client_id=find_user.id
|
||||
|
||||
if !encrypt_key.nil?
|
||||
check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid)
|
||||
if check_manufacture.nil?
|
||||
serial_no=BatchLineItem.generate_serial_no(client_id.to_s)
|
||||
|
||||
if product_type ==1
|
||||
asset_identity=BatchLineItem.generate_account_no
|
||||
@out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
|
||||
elsif product_type==2
|
||||
str="manufacture_uid="+manufacture_uid.to_s+"&serial_no="+serial_no.to_s
|
||||
|
||||
digest_data= Digest::MD5.hexdigest(str)
|
||||
hex_data=digest_data.hex
|
||||
hex_str=hex_data.to_s
|
||||
asset_identity=hex_str[0..15]
|
||||
check_asset=BatchLineItem.find_by_asset_identity(asset_identity)
|
||||
|
||||
if check_asset.nil?
|
||||
@out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
|
||||
else
|
||||
@out=false,'Asset Identity is already registered!'
|
||||
end
|
||||
end
|
||||
elsif product_type=="card"
|
||||
@out=create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
|
||||
end
|
||||
else
|
||||
@out=false,'Manufacture UID is already registered!'
|
||||
end
|
||||
else
|
||||
@out=false,'Manufacture UID is already registered!'
|
||||
end
|
||||
@out=false,'Invalid User!'
|
||||
end
|
||||
else
|
||||
@out=false,'Invalid User!'
|
||||
@out=false,"Client doesn't exist!"
|
||||
end
|
||||
else
|
||||
@out=false,'Client does not exist!'
|
||||
@out=false,"Product Category doesn't exist!"
|
||||
end
|
||||
else
|
||||
@out=false,'Batch does not exist!'
|
||||
@out=false,"Batch doesn't exist!"
|
||||
end
|
||||
else
|
||||
@out=false,'Sorry!Unauthorized user!'
|
||||
end
|
||||
end
|
||||
def 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
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user