prefix encoded times to manufacture_uid
This commit is contained in:
@@ -1,68 +1,68 @@
|
|||||||
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]
|
||||||
card_account_no=params[:card_account_no]
|
card_account_no=params[:card_account_no]
|
||||||
client_id=""
|
client_id=""
|
||||||
|
|
||||||
check_member= Member.authenticate_session_token(session_token)
|
check_member= Member.authenticate_session_token(session_token)
|
||||||
if !check_member.nil?
|
if !check_member.nil?
|
||||||
encrypt_key=""
|
encrypt_key=""
|
||||||
asset_identity=""
|
asset_identity=""
|
||||||
|
|
||||||
find_batch = Batch.find_by_id(batch_id)
|
find_batch = Batch.find_by_id(batch_id)
|
||||||
if !find_batch.nil?
|
if !find_batch.nil?
|
||||||
card_type=find_batch.adult_or_child.upcase
|
card_type=find_batch.adult_or_child.upcase
|
||||||
product_category_id=find_batch.product_category_id
|
product_category_id=find_batch.product_category_id
|
||||||
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?
|
||||||
product_type=find_product_category.product_type_id
|
product_type=find_product_category.product_type_id
|
||||||
|
|
||||||
find_user=Client.find_by_id(find_batch.client_id)
|
find_user=Client.find_by_id(find_batch.client_id)
|
||||||
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
|
||||||
|
|
||||||
client_id=find_user.id
|
client_id=find_user.id
|
||||||
if !encrypt_key.nil?
|
if !encrypt_key.nil?
|
||||||
check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid)
|
check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid)
|
||||||
if check_manufacture.nil?
|
if check_manufacture.nil?
|
||||||
serial_no=BatchLineItem.generate_serial_no(client_id.to_s)
|
serial_no=BatchLineItem.generate_serial_no(client_id.to_s)
|
||||||
|
|
||||||
if product_type ==1 #CARD
|
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 #TICKET
|
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!'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if check_manufacture.asset_identity !=card_account_no
|
if check_manufacture.asset_identity != card_account_no
|
||||||
@out=true,check_manufacture.serial_no,check_manufacture.asset_identity
|
@out=true,check_manufacture.serial_no,check_manufacture.asset_identity
|
||||||
else
|
else
|
||||||
@out=false,'Manufacture UID is already registered!'
|
@out=false,'Manufacture UID is already registered!'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@out=false,'Invalid User!'
|
@out=false,'Invalid User!'
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@out=false,"Client doesn't exist!"
|
@out=false,"Client doesn't exist!"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@out=false,"Product Category doesn't exist!"
|
@out=false,"Product Category doesn't exist!"
|
||||||
@@ -73,16 +73,16 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
else
|
else
|
||||||
@out=false,'Sorry!Unauthorized user!'
|
@out=false,'Sorry!Unauthorized user!'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_card_account_items
|
def generate_card_account_items
|
||||||
# Generate Code
|
# Generate Code
|
||||||
batch_id=params[:id]
|
batch_id=params[:id]
|
||||||
client_id=""
|
client_id=""
|
||||||
qty = params[:qty]
|
qty = params[:qty]
|
||||||
total_count=0
|
total_count=0
|
||||||
# check_member= Member.authenticate_session_token(session_token)
|
# check_member= Member.authenticate_session_token(session_token)
|
||||||
# if !check_member.nil?
|
# if !check_member.nil?
|
||||||
encrypt_key=""
|
encrypt_key=""
|
||||||
asset_identity=""
|
asset_identity=""
|
||||||
|
|
||||||
@@ -90,21 +90,21 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
if !find_batch.nil?
|
if !find_batch.nil?
|
||||||
find_batch.generated_qty = qty
|
find_batch.generated_qty = qty
|
||||||
find_batch.save
|
find_batch.save
|
||||||
card_type=find_batch.adult_or_child.upcase
|
card_type=find_batch.adult_or_child.upcase
|
||||||
product_category_id=find_batch.product_category_id
|
product_category_id=find_batch.product_category_id
|
||||||
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?
|
||||||
product_type=find_product_category.product_type_id
|
product_type=find_product_category.product_type_id
|
||||||
|
|
||||||
find_user=Client.find_by_id(find_batch.client_id)
|
find_user=Client.find_by_id(find_batch.client_id)
|
||||||
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
|
||||||
|
|
||||||
client_id=find_user.id
|
client_id=find_user.id
|
||||||
|
|
||||||
if !encrypt_key.nil?
|
if !encrypt_key.nil?
|
||||||
arr = Array.new
|
arr = Array.new
|
||||||
# Generate with qty
|
# Generate with qty
|
||||||
qty.to_i.times do |i|
|
qty.to_i.times do |i|
|
||||||
@@ -112,19 +112,19 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
|
|
||||||
asset_identity=BatchLineItem.generate_account_no(location_code)
|
asset_identity=BatchLineItem.generate_account_no(location_code)
|
||||||
security_code=BatchLineItem.generate_security_code
|
security_code=BatchLineItem.generate_security_code
|
||||||
out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,"","",security_code)
|
out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,"","",security_code)
|
||||||
item = out[2]
|
item = out[2]
|
||||||
total_count+=1
|
total_count+=1
|
||||||
arr.push(item)
|
arr.push(item)
|
||||||
end
|
end
|
||||||
@out =true,'Success',arr
|
@out =true,'Success',arr
|
||||||
# Generate with qty
|
# Generate with qty
|
||||||
|
|
||||||
else
|
else
|
||||||
@out=false,'Invalid User!'
|
@out=false,'Invalid User!'
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@out=false,"Client doesn't exist!"
|
@out=false,"Client doesn't exist!"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@out=false,"Product Category doesn't exist!"
|
@out=false,"Product Category doesn't exist!"
|
||||||
@@ -136,25 +136,26 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
# @out=false,'Sorry!Unauthorized user!'
|
# @out=false,'Sorry!Unauthorized user!'
|
||||||
# end
|
# end
|
||||||
# Generate Code
|
# Generate Code
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_manufacture_uid
|
def update_manufacture_uid
|
||||||
account_no = params[:account_no]
|
account_no = params[:account_no]
|
||||||
barcode = params[:barcode]
|
barcode = params[:barcode]
|
||||||
manufacture_uid = params[:manufacture_uid]
|
manufacture_uid = params[:manufacture_uid]
|
||||||
session_token = params[:session_token]
|
session_token = params[:session_token]
|
||||||
|
|
||||||
find_user = Member.find_by_session_token(session_token)
|
find_user = Member.find_by_session_token(session_token)
|
||||||
if !find_user.nil?
|
if !find_user.nil?
|
||||||
if barcode.present?
|
if barcode.present?
|
||||||
batch_line_item = BatchLineItem.find_by_barcode(barcode)
|
batch_line_item = BatchLineItem.find_by_barcode(barcode)
|
||||||
elsif account_no.present?
|
elsif account_no.present?
|
||||||
batch_line_item = BatchLineItem.find_by_asset_identity(account_no)
|
batch_line_item = BatchLineItem.find_by_asset_identity(account_no)
|
||||||
end
|
end
|
||||||
|
|
||||||
if !batch_line_item.nil?
|
if !batch_line_item.nil?
|
||||||
if batch_line_item.manufacture_uid.empty?
|
if batch_line_item.manufacture_uid.empty?
|
||||||
batch_line_item.manufacture_uid = manufacture_uid
|
issue_count = BatchLineItem.where("manufacture_uid LIKE ?", "#{manufacture_uid}%").count
|
||||||
|
batch_line_item.manufacture_uid = "#{manufacture_uid}#{issue_count > 0 ? "-#{issue_count}" : ""}"
|
||||||
batch_line_item.save
|
batch_line_item.save
|
||||||
|
|
||||||
# update batch
|
# update batch
|
||||||
@@ -176,7 +177,7 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
else
|
else
|
||||||
@out = false,"Not Authorized"
|
@out = false,"Not Authorized"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -195,10 +196,10 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
session_token = params[:session_token]
|
session_token = params[:session_token]
|
||||||
barcode =params[:barcode]
|
barcode =params[:barcode]
|
||||||
find_seller = Member.find_by_session_token(session_token)
|
find_seller = Member.find_by_session_token(session_token)
|
||||||
if !find_seller.nil?
|
if !find_seller.nil?
|
||||||
seller_id = find_seller.user_id
|
seller_id = find_seller.user_id
|
||||||
find_barcode = BatchLineItem.find_by_barcode(barcode)
|
find_barcode = BatchLineItem.find_by_barcode(barcode)
|
||||||
if !find_barcode.nil?
|
if !find_barcode.nil?
|
||||||
find_batch = Batch.find_by_id(find_barcode.batch_id)
|
find_batch = Batch.find_by_id(find_barcode.batch_id)
|
||||||
if find_batch.export_to_seller_id == seller_id
|
if find_batch.export_to_seller_id == seller_id
|
||||||
if find_barcode.is_activated == false
|
if find_barcode.is_activated == false
|
||||||
@@ -210,7 +211,7 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
@out = false,"This is already activated!"
|
@out = false,"This is already activated!"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@out = false,"Not Authorized Seller"
|
@out = false,"Not Authorized Seller"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@out = false,"Fail"
|
@out = false,"Fail"
|
||||||
@@ -225,12 +226,12 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
session_token = params[:session_token]
|
session_token = params[:session_token]
|
||||||
barcode =params[:barcode]
|
barcode =params[:barcode]
|
||||||
user = Member.find_by_session_token(session_token)
|
user = Member.find_by_session_token(session_token)
|
||||||
if !user.nil?
|
if !user.nil?
|
||||||
user_id = user.user_id
|
user_id = user.user_id
|
||||||
find_barcode = BatchLineItem.find_by_barcode(barcode)
|
find_barcode = BatchLineItem.find_by_barcode(barcode)
|
||||||
if !find_barcode.nil?
|
if !find_barcode.nil?
|
||||||
@out = true,find_barcode
|
@out = true,find_barcode
|
||||||
|
|
||||||
else
|
else
|
||||||
@out = false,"Invalid"
|
@out = false,"Invalid"
|
||||||
end
|
end
|
||||||
@@ -243,18 +244,18 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
# session_token = params[:session_token]
|
# session_token = params[:session_token]
|
||||||
# barcode =params[:barcode]
|
# barcode =params[:barcode]
|
||||||
# find_seller = Member.find_by_session_token(session_token)
|
# find_seller = Member.find_by_session_token(session_token)
|
||||||
# if !find_seller.nil?
|
# if !find_seller.nil?
|
||||||
# seller_id = find_seller.user_id
|
# seller_id = find_seller.user_id
|
||||||
# find_barcode = BatchLineItem.find_by_barcode(barcode)
|
# find_barcode = BatchLineItem.find_by_barcode(barcode)
|
||||||
# if !find_barcode.nil?
|
# if !find_barcode.nil?
|
||||||
# @out = true,"valid"
|
# @out = true,"valid"
|
||||||
# end
|
# end
|
||||||
# else
|
# else
|
||||||
# @out = false, "Not Authorized"
|
# @out = false, "Not Authorized"
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
def activated_list
|
def activated_list
|
||||||
session_token = params[:session_token]
|
session_token = params[:session_token]
|
||||||
find_seller = Member.find_by_session_token(session_token)
|
find_seller = Member.find_by_session_token(session_token)
|
||||||
if !find_seller.nil?
|
if !find_seller.nil?
|
||||||
@@ -264,7 +265,7 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
offset = (page_no.to_i - 1 ) * 10
|
offset = (page_no.to_i - 1 ) * 10
|
||||||
else
|
else
|
||||||
offset = 0
|
offset = 0
|
||||||
end
|
end
|
||||||
seller_id = find_seller.user_id
|
seller_id = find_seller.user_id
|
||||||
get_list = BatchLineItem.select("batch_line_items.id,batch_line_items.barcode,batch_line_items.activated_date").joins("join batches on batches.id=batch_line_items.batch_id").where("batch_line_items.is_activated=? and batches.export_to_seller_id=?",true,seller_id).limit(10).offset(offset)
|
get_list = BatchLineItem.select("batch_line_items.id,batch_line_items.barcode,batch_line_items.activated_date").joins("join batches on batches.id=batch_line_items.batch_id").where("batch_line_items.is_activated=? and batches.export_to_seller_id=?",true,seller_id).limit(10).offset(offset)
|
||||||
|
|
||||||
@@ -298,4 +299,4 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class Batch < ApplicationRecord
|
|||||||
belongs_to :client
|
belongs_to :client
|
||||||
belongs_to :product_category
|
belongs_to :product_category
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
def self.create_batch(date,order_ref,user_id,adult_or_child,client_id,product_category_id)
|
def self.create_batch(date,order_ref,user_id,adult_or_child,client_id,product_category_id)
|
||||||
batch = Batch.new
|
batch = Batch.new
|
||||||
batch.exported_by=""
|
batch.exported_by=""
|
||||||
@@ -19,7 +19,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
|
||||||
|
|||||||
Reference in New Issue
Block a user