prefix encoded times to manufacture_uid

This commit is contained in:
Thein Lin Kyaw
2023-08-28 14:37:04 +06:30
parent 019902872b
commit 1b619e8dc1
2 changed files with 64 additions and 63 deletions

View File

@@ -1,68 +1,68 @@
class Api::BatchLineItemsController < ApplicationController
skip_before_filter :verify_authenticity_token
def register
batch_id=params[:batch_id]
batch_id=params[:batch_id]
session_token=params[:session_token]
manufacture_uid = params[:card_manufacture]
manufacture_uid = params[:card_manufacture]
card_account_no=params[:card_account_no]
client_id=""
client_id=""
check_member= Member.authenticate_session_token(session_token)
if !check_member.nil?
if !check_member.nil?
encrypt_key=""
asset_identity=""
find_batch = Batch.find_by_id(batch_id)
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
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
find_user=Client.find_by_id(find_batch.client_id)
if !find_user.nil?
encrypt_key=find_user.secrect_key
location_code=find_user.location_code
encrypt_key=find_user.secrect_key
location_code=find_user.location_code
client_id=find_user.id
if !encrypt_key.nil?
check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid)
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 #CARD
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
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)
hex_data=digest_data.hex
digest_data= Digest::MD5.hexdigest(str)
hex_data=digest_data.hex
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)
if check_asset.nil?
@out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
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!'
@out=false,'Asset Identity is already registered!'
end
end
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
else
@out=false,'Manufacture UID is already registered!'
end
@out=false,'Manufacture UID is already registered!'
end
end
else
@out=false,'Invalid User!'
@out=false,'Invalid User!'
end
else
@out=false,"Client doesn't exist!"
@out=false,"Client doesn't exist!"
end
else
@out=false,"Product Category doesn't exist!"
@@ -73,16 +73,16 @@ class Api::BatchLineItemsController < ApplicationController
else
@out=false,'Sorry!Unauthorized user!'
end
end
end
def generate_card_account_items
# Generate Code
batch_id=params[:id]
batch_id=params[:id]
client_id=""
qty = params[:qty]
total_count=0
qty = params[:qty]
total_count=0
# check_member= Member.authenticate_session_token(session_token)
# if !check_member.nil?
# if !check_member.nil?
encrypt_key=""
asset_identity=""
@@ -90,21 +90,21 @@ class Api::BatchLineItemsController < ApplicationController
if !find_batch.nil?
find_batch.generated_qty = qty
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
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
find_user=Client.find_by_id(find_batch.client_id)
if !find_user.nil?
encrypt_key=find_user.secrect_key
location_code=find_user.location_code
encrypt_key=find_user.secrect_key
location_code=find_user.location_code
client_id=find_user.id
if !encrypt_key.nil?
if !encrypt_key.nil?
arr = Array.new
# Generate with qty
qty.to_i.times do |i|
@@ -112,19 +112,19 @@ class Api::BatchLineItemsController < ApplicationController
asset_identity=BatchLineItem.generate_account_no(location_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]
total_count+=1
arr.push(item)
end
@out =true,'Success',arr
# Generate with qty
# Generate with qty
else
@out=false,'Invalid User!'
@out=false,'Invalid User!'
end
else
@out=false,"Client doesn't exist!"
@out=false,"Client doesn't exist!"
end
else
@out=false,"Product Category doesn't exist!"
@@ -136,25 +136,26 @@ class Api::BatchLineItemsController < ApplicationController
# @out=false,'Sorry!Unauthorized user!'
# end
# Generate Code
end
end
def update_manufacture_uid
account_no = params[:account_no]
account_no = params[:account_no]
barcode = params[:barcode]
manufacture_uid = params[:manufacture_uid]
session_token = params[:session_token]
find_user = Member.find_by_session_token(session_token)
if !find_user.nil?
if !find_user.nil?
if barcode.present?
batch_line_item = BatchLineItem.find_by_barcode(barcode)
elsif account_no.present?
batch_line_item = BatchLineItem.find_by_asset_identity(account_no)
end
if !batch_line_item.nil?
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
# update batch
@@ -176,7 +177,7 @@ class Api::BatchLineItemsController < ApplicationController
else
@out = false,"Not Authorized"
end
end
end
@@ -195,10 +196,10 @@ class Api::BatchLineItemsController < ApplicationController
session_token = params[:session_token]
barcode =params[:barcode]
find_seller = Member.find_by_session_token(session_token)
if !find_seller.nil?
if !find_seller.nil?
seller_id = find_seller.user_id
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)
if find_batch.export_to_seller_id == seller_id
if find_barcode.is_activated == false
@@ -210,7 +211,7 @@ class Api::BatchLineItemsController < ApplicationController
@out = false,"This is already activated!"
end
else
@out = false,"Not Authorized Seller"
@out = false,"Not Authorized Seller"
end
else
@out = false,"Fail"
@@ -225,12 +226,12 @@ class Api::BatchLineItemsController < ApplicationController
session_token = params[:session_token]
barcode =params[:barcode]
user = Member.find_by_session_token(session_token)
if !user.nil?
if !user.nil?
user_id = user.user_id
find_barcode = BatchLineItem.find_by_barcode(barcode)
if !find_barcode.nil?
if !find_barcode.nil?
@out = true,find_barcode
else
@out = false,"Invalid"
end
@@ -243,18 +244,18 @@ class Api::BatchLineItemsController < ApplicationController
# session_token = params[:session_token]
# barcode =params[:barcode]
# find_seller = Member.find_by_session_token(session_token)
# if !find_seller.nil?
# if !find_seller.nil?
# seller_id = find_seller.user_id
# find_barcode = BatchLineItem.find_by_barcode(barcode)
# if !find_barcode.nil?
# if !find_barcode.nil?
# @out = true,"valid"
# end
# else
# else
# @out = false, "Not Authorized"
# end
# end
def activated_list
def activated_list
session_token = params[:session_token]
find_seller = Member.find_by_session_token(session_token)
if !find_seller.nil?
@@ -264,7 +265,7 @@ class Api::BatchLineItemsController < ApplicationController
offset = (page_no.to_i - 1 ) * 10
else
offset = 0
end
end
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)
@@ -298,4 +299,4 @@ class Api::BatchLineItemsController < ApplicationController
end
end
end
end

View File

@@ -3,7 +3,7 @@ class Batch < ApplicationRecord
belongs_to :client
belongs_to :product_category
belongs_to :user
def self.create_batch(date,order_ref,user_id,adult_or_child,client_id,product_category_id)
batch = Batch.new
batch.exported_by=""
@@ -19,7 +19,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