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
|
||||
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
|
||||
@@ -4,20 +4,21 @@ class Api::BatchesController < ApplicationController
|
||||
session_token=params[:session_token]
|
||||
check_member= Member.authenticate_session_token(session_token)
|
||||
if !check_member.nil?
|
||||
date = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
|
||||
created_by = params[:created_by]
|
||||
order_ref = params[:order_ref]
|
||||
card_qty = params[:card_qty]
|
||||
date = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
|
||||
order_ref = params[:order_ref]
|
||||
adult_or_child=params[:adult_or_child]
|
||||
client_id=params[:client_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)
|
||||
if !find_client.nil?
|
||||
find_product_category=ProductCategory.find_by_id(product_category_id)
|
||||
if !find_product_category.nil?
|
||||
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)
|
||||
user_id=check_member.user_id
|
||||
|
||||
batch = Batch.create_batch(date,order_ref,user_id,created_by,adult_or_child,client_id,product_category_id)
|
||||
if !batch.nil?
|
||||
@out=true,batch.id
|
||||
else
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
class Batch < ApplicationRecord
|
||||
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.created_by = created_by
|
||||
batch.created_by=created_by
|
||||
batch.order_ref = order_ref
|
||||
batch.date = date
|
||||
batch.batch_start = true
|
||||
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_fail = 0
|
||||
batch.user_id=user_id
|
||||
@@ -16,6 +16,7 @@ class Batch < ApplicationRecord
|
||||
batch.client_id=client_id
|
||||
batch.product_category_id=product_category_id
|
||||
batch.adult_or_child=adult_or_child.upcase
|
||||
|
||||
if batch.save
|
||||
return batch
|
||||
else
|
||||
|
||||
@@ -53,11 +53,9 @@ class BatchLineItem < ApplicationRecord
|
||||
CSV.generate(headers: true) do |csv|
|
||||
csv << attributes
|
||||
all.each do |encoder|
|
||||
if encoder.product_type_id ==1
|
||||
puts 'Card'
|
||||
if encoder.product_type_id ==1
|
||||
str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
|
||||
else
|
||||
puts 'Tickets'
|
||||
else
|
||||
str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
|
||||
end
|
||||
|
||||
@@ -96,20 +94,33 @@ class BatchLineItem < ApplicationRecord
|
||||
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")
|
||||
|
||||
batch=Batch.find_by_id(batch_id)
|
||||
|
||||
if batchLineItem.save
|
||||
lookup=Lookup.find_by_name('generate_serial_no')
|
||||
max_serail_no=lookup.max_value
|
||||
lookup.max_value=max_serail_no.to_i+1
|
||||
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
|
||||
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
|
||||
def self.get_array
|
||||
arr=Array.new
|
||||
(1..50).each do |i|
|
||||
(1..1000).each do |i|
|
||||
str= SecureRandom.hex
|
||||
uid=str[0..13]
|
||||
arr.push(uid)
|
||||
|
||||
@@ -41,14 +41,13 @@
|
||||
<table class="table" style="border-top:none">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Serail No</th>
|
||||
<th>Asset Identity</th>
|
||||
<th>Manufacture UID</th>
|
||||
<th>Batch No</th>
|
||||
<th>Asset Type</th>
|
||||
<th>Created At </th>
|
||||
<th>Update At </th>
|
||||
|
||||
<th>Serail No</th>
|
||||
<th>Asset Identity</th>
|
||||
<th>Manufacture UID</th>
|
||||
<th>Batch No</th>
|
||||
<th>Asset Type</th>
|
||||
<th>Created At </th>
|
||||
<th>Update At </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -60,7 +59,7 @@
|
||||
<td><%= item.batch_name rescue '' %></td>
|
||||
<td><%= item.asset_type rescue '' %></td>
|
||||
<td><%= item.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
|
||||
<td><%= item.updated_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
|
||||
<td><%= item.updated_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user