edit
This commit is contained in:
BIN
app/assets/.DS_Store
vendored
BIN
app/assets/.DS_Store
vendored
Binary file not shown.
@@ -1,10 +1,9 @@
|
|||||||
class Api::BatchLineItemsController < ApplicationController
|
class Api::BatchLineItemsController < ApplicationController
|
||||||
skip_before_filter :verify_authenticity_token
|
skip_before_filter :verify_authenticity_token
|
||||||
def register
|
def register
|
||||||
batch_id=params[:batch_id]
|
batch_id=params[:batch_id]
|
||||||
session_token=params[:session_token]
|
session_token=params[:session_token]
|
||||||
manufacture_uid = params[:card_manufacture]
|
manufacture_uid = params[:card_manufacture]
|
||||||
# product_category_id=params[:product_category_id]
|
|
||||||
|
|
||||||
client_id=""
|
client_id=""
|
||||||
|
|
||||||
@@ -26,61 +25,36 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
if !find_user.nil?
|
if !find_user.nil?
|
||||||
encrypt_key=find_user.secrect_key
|
encrypt_key=find_user.secrect_key
|
||||||
location_code=find_user.location_code
|
location_code=find_user.location_code
|
||||||
# product_type=find_user.product_type
|
|
||||||
client_id=find_user.id
|
client_id=find_user.id
|
||||||
|
|
||||||
if !encrypt_key.nil?
|
if !encrypt_key.nil?
|
||||||
arr=Array.new
|
check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid)
|
||||||
arr=BatchLineItem.get_array
|
if check_manufacture.nil?
|
||||||
|
serial_no=BatchLineItem.generate_serial_no(client_id.to_s)
|
||||||
|
|
||||||
str_dup=""
|
if product_type ==1 #CARD
|
||||||
str_wb=""
|
asset_identity=BatchLineItem.generate_account_no(location_code)
|
||||||
dup_count=0
|
@out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,"")
|
||||||
wb_count=0
|
elsif product_type==2 #TICKET
|
||||||
arr=arr.as_json
|
str="manufacture_uid="+manufacture_uid.to_s+"&serial_no="+serial_no.to_s
|
||||||
|
|
||||||
arr.each do |item|
|
digest_data= Digest::MD5.hexdigest(str)
|
||||||
manufacture_uid=item
|
hex_data=digest_data.hex
|
||||||
|
hex_str=hex_data.to_s
|
||||||
|
asset_identity=hex_str[0..15]
|
||||||
|
|
||||||
check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid)
|
check_asset=BatchLineItem.find_by_asset_identity(asset_identity)
|
||||||
if check_manufacture.nil?
|
|
||||||
serial_no=BatchLineItem.generate_serial_no(client_id.to_s)
|
|
||||||
|
|
||||||
if product_type ==1
|
if check_asset.nil?
|
||||||
asset_identity=BatchLineItem.generate_account_no(location_code)
|
@out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
|
||||||
@out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,"")
|
else
|
||||||
elsif product_type==2
|
@out=false,'Asset Identity is already registered!'
|
||||||
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!'
|
|
||||||
put @out
|
|
||||||
str_dup=str_dup+manufacture_uid.to_s+","
|
|
||||||
dup_count=dup_count+1
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
@out=false,'Manufacture UID is already registered!'
|
||||||
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
|
else
|
||||||
@out=false,'Invalid User!'
|
@out=false,'Invalid User!'
|
||||||
end
|
end
|
||||||
@@ -97,5 +71,4 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
@out=false,'Sorry!Unauthorized user!'
|
@out=false,'Sorry!Unauthorized user!'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -5,19 +5,20 @@ class Api::BatchesController < ApplicationController
|
|||||||
check_member= Member.authenticate_session_token(session_token)
|
check_member= Member.authenticate_session_token(session_token)
|
||||||
if !check_member.nil?
|
if !check_member.nil?
|
||||||
date = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
|
date = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
|
||||||
created_by = params[:created_by]
|
|
||||||
order_ref = params[:order_ref]
|
order_ref = params[:order_ref]
|
||||||
card_qty = params[:card_qty]
|
|
||||||
adult_or_child=params[:adult_or_child]
|
adult_or_child=params[:adult_or_child]
|
||||||
client_id=params[:client_id]
|
client_id=params[:client_id]
|
||||||
product_category_id=params[:product_category_id]
|
product_category_id=params[:product_category_id]
|
||||||
|
|
||||||
|
find_user=User.find_by_id(check_member.user_id)
|
||||||
|
created_by=find_user.name
|
||||||
find_client=Client.find_by_id(client_id)
|
find_client=Client.find_by_id(client_id)
|
||||||
if !find_client.nil?
|
if !find_client.nil?
|
||||||
find_product_category=ProductCategory.find_by_id(product_category_id)
|
find_product_category=ProductCategory.find_by_id(product_category_id)
|
||||||
if !find_product_category.nil?
|
if !find_product_category.nil?
|
||||||
user_id=check_member.user_id
|
user_id=check_member.user_id
|
||||||
batch = Batch.create_batch(created_by,date,order_ref,card_qty,user_id,adult_or_child,client_id,product_category_id)
|
|
||||||
|
batch = Batch.create_batch(date,order_ref,user_id,created_by,adult_or_child,client_id,product_category_id)
|
||||||
if !batch.nil?
|
if !batch.nil?
|
||||||
@out=true,batch.id
|
@out=true,batch.id
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
class Batch < ApplicationRecord
|
class Batch < ApplicationRecord
|
||||||
has_many :batch_line_item
|
has_many :batch_line_item
|
||||||
|
|
||||||
def self.create_batch(created_by,date,order_ref, card_qty,user_id,adult_or_child,client_id,product_category_id)
|
def self.create_batch(date,order_ref,user_id,created_by,adult_or_child,client_id,product_category_id)
|
||||||
batch = Batch.new
|
batch = Batch.new
|
||||||
batch.created_by = created_by
|
batch.created_by=created_by
|
||||||
batch.order_ref = order_ref
|
batch.order_ref = order_ref
|
||||||
batch.date = date
|
batch.date = date
|
||||||
batch.batch_start = true
|
batch.batch_start = true
|
||||||
batch.batch_start_time=DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
|
batch.batch_start_time=DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
|
||||||
batch.qty_processing = card_qty.to_i
|
batch.qty_processing = 0
|
||||||
batch.qty_success = 0
|
batch.qty_success = 0
|
||||||
batch.qty_fail = 0
|
batch.qty_fail = 0
|
||||||
batch.user_id=user_id
|
batch.user_id=user_id
|
||||||
@@ -16,6 +16,7 @@ class Batch < ApplicationRecord
|
|||||||
batch.client_id=client_id
|
batch.client_id=client_id
|
||||||
batch.product_category_id=product_category_id
|
batch.product_category_id=product_category_id
|
||||||
batch.adult_or_child=adult_or_child.upcase
|
batch.adult_or_child=adult_or_child.upcase
|
||||||
|
|
||||||
if batch.save
|
if batch.save
|
||||||
return batch
|
return batch
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -54,10 +54,8 @@ class BatchLineItem < ApplicationRecord
|
|||||||
csv << attributes
|
csv << attributes
|
||||||
all.each do |encoder|
|
all.each do |encoder|
|
||||||
if encoder.product_type_id ==1
|
if encoder.product_type_id ==1
|
||||||
puts 'Card'
|
|
||||||
str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
|
str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
|
||||||
else
|
else
|
||||||
puts 'Tickets'
|
|
||||||
str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
|
str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -96,20 +94,33 @@ class BatchLineItem < ApplicationRecord
|
|||||||
batchLineItem.encoded_at = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
|
batchLineItem.encoded_at = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
|
||||||
batchLineItem.verified_at =DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
|
batchLineItem.verified_at =DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
batch=Batch.find_by_id(batch_id)
|
||||||
|
|
||||||
if batchLineItem.save
|
if batchLineItem.save
|
||||||
lookup=Lookup.find_by_name('generate_serial_no')
|
lookup=Lookup.find_by_name('generate_serial_no')
|
||||||
max_serail_no=lookup.max_value
|
max_serail_no=lookup.max_value
|
||||||
lookup.max_value=max_serail_no.to_i+1
|
lookup.max_value=max_serail_no.to_i+1
|
||||||
lookup.save
|
lookup.save
|
||||||
|
|
||||||
|
card_qty=batch.qty_processing.to_i
|
||||||
|
success_qty=batch.qty_success
|
||||||
|
|
||||||
|
batch.qty_processing=card_qty+1
|
||||||
|
batch.qty_success=success_qty+1
|
||||||
|
batch.save
|
||||||
|
|
||||||
@result = true,batchLineItem.serial_no,batchLineItem.asset_identity
|
@result = true,batchLineItem.serial_no,batchLineItem.asset_identity
|
||||||
else
|
else
|
||||||
@result=false,'Error occurs in registration encoder!'
|
qty_fail=batch.qty_fail
|
||||||
|
batch.qty_fail=qty_fail+1
|
||||||
|
batch.save
|
||||||
|
|
||||||
|
@result=false,'Error occurs in registration encoder!'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def self.get_array
|
def self.get_array
|
||||||
arr=Array.new
|
arr=Array.new
|
||||||
(1..50).each do |i|
|
(1..1000).each do |i|
|
||||||
str= SecureRandom.hex
|
str= SecureRandom.hex
|
||||||
uid=str[0..13]
|
uid=str[0..13]
|
||||||
arr.push(uid)
|
arr.push(uid)
|
||||||
|
|||||||
@@ -41,14 +41,13 @@
|
|||||||
<table class="table" style="border-top:none">
|
<table class="table" style="border-top:none">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Serail No</th>
|
<th>Serail No</th>
|
||||||
<th>Asset Identity</th>
|
<th>Asset Identity</th>
|
||||||
<th>Manufacture UID</th>
|
<th>Manufacture UID</th>
|
||||||
<th>Batch No</th>
|
<th>Batch No</th>
|
||||||
<th>Asset Type</th>
|
<th>Asset Type</th>
|
||||||
<th>Created At </th>
|
<th>Created At </th>
|
||||||
<th>Update At </th>
|
<th>Update At </th>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user