Files
nemo_encoder/app/controllers/api/batch_line_items_controller.rb
Sunandar 9931152796 edit
2017-02-10 10:56:47 +06:30

74 lines
3.5 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]
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
product_category_id=find_batch.product_category_id
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
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 #CARD
asset_identity=BatchLineItem.generate_account_no(location_code)
@out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,"")
elsif product_type==2 #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=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