73 lines
3.6 KiB
Ruby
73 lines
3.6 KiB
Ruby
class Api::BatchLineItemsController < ApplicationController
|
|
skip_before_filter :verify_authenticity_token
|
|
def register
|
|
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)
|
|
if !check_member.nil?
|
|
encrypt_key=""
|
|
asset_identity=""
|
|
|
|
find_batch = Batch.find_by_id(batch_id)
|
|
if !find_batch.nil?
|
|
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
|
|
|
|
find_user=Client.find_by_id(find_batch.client_id)
|
|
if !find_user.nil?
|
|
encrypt_key=find_user.secrect_key
|
|
location_code=find_user.location_code
|
|
# 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(location_code)
|
|
@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
|
|
else
|
|
@out=false,'Manufacture UID is already registered!'
|
|
end
|
|
else
|
|
@out=false,'Invalid User!'
|
|
end
|
|
else
|
|
@out=false,"Client doesn't exist!"
|
|
end
|
|
else
|
|
@out=false,"Product Category doesn't exist!"
|
|
end
|
|
else
|
|
@out=false,"Batch doesn't exist!"
|
|
end
|
|
else
|
|
@out=false,'Sorry!Unauthorized user!'
|
|
end
|
|
end
|
|
|
|
end |