This commit is contained in:
Sunandar
2017-02-10 10:56:47 +06:30
parent a3bd5dc1b7
commit 9931152796
7 changed files with 63 additions and 78 deletions

View File

@@ -1,10 +1,9 @@
class Api::BatchLineItemsController < ApplicationController
skip_before_filter :verify_authenticity_token
def register
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=""
@@ -26,61 +25,36 @@ class Api::BatchLineItemsController < ApplicationController
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?
arr=Array.new
arr=BatchLineItem.get_array
str_dup=""
str_wb=""
dup_count=0
wb_count=0
arr=arr.as_json
arr.each do |item|
manufacture_uid=item
check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid)
if check_manufacture.nil?
serial_no=BatchLineItem.generate_serial_no(client_id.to_s)
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,"")
elsif product_type==2
str="manufacture_uid="+manufacture_uid.to_s+"&serial_no="+serial_no.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]
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!'
str_wb=str_wb+asset_identity.to_s+","
wb_count=wb_count+1
end
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
else
@out=false,'Manufacture UID is already registered!'
put @out
str_dup=str_dup+manufacture_uid.to_s+","
dup_count=dup_count+1
end
end
puts str_dup
puts dup_count
puts str_wb
puts wb_count
puts 'Asset Identity duplicat' + wb_count.to_s
puts 'Manufacture UID '+ dup_count.to_s
end
else
@out=false,'Manufacture UID is already registered!'
end
else
@out=false,'Invalid User!'
end
@@ -96,6 +70,5 @@ class Api::BatchLineItemsController < ApplicationController
else
@out=false,'Sorry!Unauthorized user!'
end
end
end
end