Files
nemo_encoder/app/controllers/api/batch_line_items_controller.rb
2018-06-21 14:56:07 +06:30

165 lines
7.1 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]
card_account_no=params[:card_account_no]
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
if check_manufacture.asset_identity !=card_account_no
@out=true,check_manufacture.serial_no,check_manufacture.asset_identity
else
@out=false,'Manufacture UID is already registered!'
end
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
def generate_card_account_items
# Generate Code
batch_id=params[:id]
client_id=""
qty = params[:qty]
total_count=0
# 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?
arr = Array.new
# Generate with qty
qty.to_i.times do |i|
serial_no=BatchLineItem.generate_serial_no(client_id.to_s)
asset_identity=BatchLineItem.generate_account_no(location_code)
security_code=BatchLineItem.generate_security_code
out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,"","",security_code)
item = out[2]
total_count+=1
arr.push(item)
end
@out =true,'Success',arr
# Generate with qty
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
# Generate Code
end
def update_manufacture_uid
account_no = params[:account_no]
manufacture_uid = params[:manufacture_uid]
batch_line_item = BatchLineItem.find_by_asset_identity(account_no)
if !batch_line_item.nil?
puts 'he'
batch_line_item.manufacture_uid = manufacture_uid
batch_line_item.save
@out = true,"success"
else
@out = false,"error"
end
end
def get_item_by_batch
batch_id = params[:batch_id]
session_token = params[:session_token]
get_batch = BatchLineItem.where("batch_id=?",batch_id)
if !get_batch.nil?
@out = true,get_batch
else
@out = false,"no batch"
end
end
end