add new field

This commit is contained in:
Sunandar
2017-02-09 18:01:50 +06:30
parent 9dc6fd3cbe
commit 07477f1a06
7 changed files with 132 additions and 91 deletions

View File

@@ -4,7 +4,7 @@ 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]
# product_category_id=params[:product_category_id]
client_id=""
@@ -16,7 +16,9 @@ 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_product_category=ProductCategory.find_by_id(product_category_id)
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
@@ -27,32 +29,58 @@ class Api::BatchLineItemsController < ApplicationController
# 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
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)
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!'
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
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
end
end
else
@out=false,'Manufacture UID 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
else
@out=false,'Invalid User!'
end