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

BIN
.DS_Store vendored

Binary file not shown.

BIN
app/assets/.DS_Store vendored

Binary file not shown.

View File

@@ -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=""
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)
if product_type ==1 if product_type ==1 #CARD
asset_identity=BatchLineItem.generate_account_no(location_code) asset_identity=BatchLineItem.generate_account_no(location_code)
@out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,"") @out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,"")
elsif product_type==2 elsif product_type==2 #TICKET
str="manufacture_uid="+manufacture_uid.to_s+"&serial_no="+serial_no.to_s str="manufacture_uid="+manufacture_uid.to_s+"&serial_no="+serial_no.to_s
digest_data= Digest::MD5.hexdigest(str) digest_data= Digest::MD5.hexdigest(str)
hex_data=digest_data.hex hex_data=digest_data.hex
hex_str=hex_data.to_s hex_str=hex_data.to_s
asset_identity=hex_str[0..15] asset_identity=hex_str[0..15]
check_asset=BatchLineItem.find_by_asset_identity(asset_identity) check_asset=BatchLineItem.find_by_asset_identity(asset_identity)
if check_asset.nil? if check_asset.nil?
@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,card_type)
else else
@out=false,'Asset Identity is already registered!' @out=false,'Asset Identity is already registered!'
str_wb=str_wb+asset_identity.to_s+","
wb_count=wb_count+1
end
end end
else end
@out=false,'Manufacture UID is already registered!' else
put @out @out=false,'Manufacture UID is already registered!'
str_dup=str_dup+manufacture_uid.to_s+"," end
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 else
@out=false,'Invalid User!' @out=false,'Invalid User!'
end end
@@ -96,6 +70,5 @@ class Api::BatchLineItemsController < ApplicationController
else else
@out=false,'Sorry!Unauthorized user!' @out=false,'Sorry!Unauthorized user!'
end end
end end
end end

View File

@@ -4,20 +4,21 @@ class Api::BatchesController < ApplicationController
session_token=params[:session_token] session_token=params[:session_token]
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

View File

@@ -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

View File

@@ -53,11 +53,9 @@ class BatchLineItem < ApplicationRecord
CSV.generate(headers: true) do |csv| CSV.generate(headers: true) do |csv|
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)

View File

@@ -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>
@@ -60,7 +59,7 @@
<td><%= item.batch_name rescue '' %></td> <td><%= item.batch_name rescue '' %></td>
<td><%= item.asset_type rescue '' %></td> <td><%= item.asset_type rescue '' %></td>
<td><%= item.created_at.strftime("%e,%b %Y %I:%M %p") 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> </tr>
<% end %> <% end %>
</tbody> </tbody>