Compare commits
13 Commits
d1dfb1d262
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e7034374d | ||
|
|
48d37dd550 | ||
|
|
2a5f63331b | ||
|
|
1b619e8dc1 | ||
|
|
019902872b | ||
|
|
d2b9a9e61f | ||
|
|
ad312c15a5 | ||
|
|
2f34bb5aa8 | ||
|
|
087c4d92d3 | ||
|
|
9951351f2c | ||
|
|
5a13870b66 | ||
|
|
f211940225 | ||
|
|
323dd43dd2 |
42
Dockerfile
Normal file
42
Dockerfile
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
FROM ruby:2.6.10-slim-bullseye
|
||||||
|
|
||||||
|
RUN apt-get update -qq && \
|
||||||
|
apt-get install -y --no-install-recommends \
|
||||||
|
build-essential libpq-dev nodejs git curl libv8-dev && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN gem install bundler:1.17.2
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY Gemfile Gemfile.lock ./
|
||||||
|
RUN bundle install --without development test --jobs 4 --retry 3
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Create gitignored config files
|
||||||
|
RUN cat <<'DBEOF' > config/database.yml
|
||||||
|
production:
|
||||||
|
adapter: postgresql
|
||||||
|
encoding: utf8
|
||||||
|
pool: 5
|
||||||
|
database: <%= ENV.fetch('DATABASE_NAME', 'nemo_encoder') %>
|
||||||
|
username: <%= ENV.fetch('DATABASE_USER', 'nemo') %>
|
||||||
|
password: <%= ENV.fetch('DATABASE_PASSWORD', '') %>
|
||||||
|
host: <%= ENV.fetch('DATABASE_HOST', 'localhost') %>
|
||||||
|
port: <%= ENV.fetch('DATABASE_PORT', '5432') %>
|
||||||
|
DBEOF
|
||||||
|
|
||||||
|
RUN cat <<'SECEOF' > config/secrets.yml
|
||||||
|
production:
|
||||||
|
secret_key_base: <%= ENV.fetch('SECRET_KEY_BASE', '14f1c43bf96e14022f9e517b6b4909070398497c26fd062cb280dedcc44f25c5146444bdf49ff8bbbb98869e9d7bfeaea5b5c12128bdb6660aec9169963a4429') %>
|
||||||
|
SECEOF
|
||||||
|
|
||||||
|
RUN mkdir -p tmp/pids tmp/puma tmp/cache tmp/sockets log storage
|
||||||
|
|
||||||
|
RUN RAILS_ENV=production SECRET_KEY_BASE=dummy DATABASE_HOST=localhost \
|
||||||
|
bundle exec rake assets:precompile 2>/dev/null || true
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb", "-p", "3000"]
|
||||||
@@ -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,32 +136,50 @@ 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]
|
||||||
batch_line_item = BatchLineItem.find_by_asset_identity(account_no)
|
session_token = params[:session_token]
|
||||||
if !batch_line_item.nil?
|
|
||||||
batch_line_item.manufacture_uid = manufacture_uid
|
|
||||||
batch_line_item.barcode = barcode
|
|
||||||
batch_line_item.save
|
|
||||||
|
|
||||||
# update batch
|
find_user = Member.find_by_session_token(session_token)
|
||||||
batch = Batch.find_by_id(batch_line_item.batch_id)
|
if !find_user.nil?
|
||||||
card_qty=batch.qty_processing.to_i
|
if barcode.present?
|
||||||
success_qty=batch.qty_success
|
batch_line_item = BatchLineItem.find_by_barcode(barcode)
|
||||||
|
elsif account_no.present?
|
||||||
|
batch_line_item = BatchLineItem.find_by_asset_identity(account_no)
|
||||||
|
end
|
||||||
|
|
||||||
batch.qty_processing=card_qty+1
|
if !batch_line_item.nil?
|
||||||
batch.qty_success=success_qty+1
|
if batch_line_item.manufacture_uid.empty?
|
||||||
batch.save
|
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
|
||||||
|
|
||||||
@out = true,"success"
|
# update batch
|
||||||
|
batch = Batch.find_by_id(batch_line_item.batch_id)
|
||||||
|
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
|
||||||
|
|
||||||
|
@out = true,batch_line_item.asset_identity
|
||||||
|
else
|
||||||
|
@out = false,"Duplicate Manufacture UID"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@out = false,"Invalid Record"
|
||||||
|
end
|
||||||
else
|
else
|
||||||
@out = false,"error"
|
@out = false,"Not Authorized"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_item_by_batch
|
def get_item_by_batch
|
||||||
batch_id = params[:batch_id]
|
batch_id = params[:batch_id]
|
||||||
@@ -178,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
|
||||||
@@ -193,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"
|
||||||
@@ -203,22 +221,41 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def update_barcode_and_account_no
|
||||||
|
session_token = params[:session_token]
|
||||||
|
barcode =params[:barcode]
|
||||||
|
user = Member.find_by_session_token(session_token)
|
||||||
|
if !user.nil?
|
||||||
|
user_id = user.user_id
|
||||||
|
find_barcode = BatchLineItem.find_by_barcode(barcode)
|
||||||
|
if !find_barcode.nil?
|
||||||
|
@out = true,find_barcode
|
||||||
|
|
||||||
|
else
|
||||||
|
@out = false,"Invalid"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@out = false, "Not Authorized"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# def check_ticket
|
# def check_ticket
|
||||||
# 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?
|
||||||
@@ -228,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)
|
||||||
|
|
||||||
@@ -262,4 +299,4 @@ class Api::BatchLineItemsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class BatchesController < ApplicationController
|
|||||||
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]
|
||||||
@batch = Batch.create_batch(date,order_ref,2,"adult_or_child",client_id,product_category_id)
|
@batch = Batch.create_batch(date,order_ref,current_member.id,"adult_or_child",client_id,product_category_id)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @batch.save
|
if @batch.save
|
||||||
|
|||||||
@@ -24,11 +24,10 @@ class ClientsController < ApplicationController
|
|||||||
# POST /clients
|
# POST /clients
|
||||||
# POST /clients.json
|
# POST /clients.json
|
||||||
def create
|
def create
|
||||||
@client = Client.new(client_params)
|
@client = Client.new(client_params)
|
||||||
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
||||||
key=cipher.random_key
|
secrect_key = cipher.random_key
|
||||||
secrect_key= Base64.encode64(key)
|
@client.secrect_key = secrect_key
|
||||||
@client.secrect_key=secrect_key
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @client.save
|
if @client.save
|
||||||
@@ -68,7 +67,7 @@ class ClientsController < ApplicationController
|
|||||||
# DELETE /clients/1.json
|
# DELETE /clients/1.json
|
||||||
def destroy
|
def destroy
|
||||||
message="Client was successfully destroyed."
|
message="Client was successfully destroyed."
|
||||||
|
|
||||||
find_batch=Batch.find_by_id(@client.id)
|
find_batch=Batch.find_by_id(@client.id)
|
||||||
if !find_batch.nil?
|
if !find_batch.nil?
|
||||||
message='Unable to delete client named '+ @client.name.to_s+'.'
|
message='Unable to delete client named '+ @client.name.to_s+'.'
|
||||||
@@ -90,6 +89,6 @@ class ClientsController < ApplicationController
|
|||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
def client_params
|
def client_params
|
||||||
params.require(:client).permit(:name,:email, :phone, :address,:location_code)
|
params.require(:client).permit(:name,:email, :phone, :address,:location_code)
|
||||||
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
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
class BatchLineItem < ApplicationRecord
|
class BatchLineItem < ApplicationRecord
|
||||||
belongs_to :batch
|
belongs_to :batch
|
||||||
attr_accessor :secret_token
|
attr_accessor :secret_token
|
||||||
attr_accessor :location
|
attr_accessor :location
|
||||||
attr_accessor :product_type
|
attr_accessor :product_type
|
||||||
require 'digest/md5'
|
require 'digest/md5'
|
||||||
|
|
||||||
|
|
||||||
CARD = "Card"
|
CARD = "Card"
|
||||||
WRISTBAND = "Wristband"
|
WRISTBAND = "Wristband"
|
||||||
ACCOUNT_CARD = "Account Card"
|
ACCOUNT_CARD = "Account Card"
|
||||||
|
|
||||||
def self.generate_account_no(location_code)
|
def self.generate_account_no(location_code)
|
||||||
super_merchant = "101"
|
super_merchant = "101"
|
||||||
account_type='1'
|
account_type='1'
|
||||||
@@ -20,12 +20,12 @@ class BatchLineItem < ApplicationRecord
|
|||||||
|
|
||||||
account_no = super_merchant+account_type+location+random_account_no
|
account_no = super_merchant+account_type+location+random_account_no
|
||||||
find_account_no = BatchLineItem.find_by_asset_identity(account_no)
|
find_account_no = BatchLineItem.find_by_asset_identity(account_no)
|
||||||
if !find_account_no.nil?
|
if !find_account_no.nil?
|
||||||
o = [('0'..'9')].map { |i| i.to_a }.flatten
|
o = [('0'..'9')].map { |i| i.to_a }.flatten
|
||||||
random_account_no = (0...9).map { o[rand(o.length)] }.join
|
random_account_no = (0...9).map { o[rand(o.length)] }.join
|
||||||
account_no = super_merchant+account_type+location+random_account_no
|
account_no = super_merchant+account_type+location+random_account_no
|
||||||
end
|
end
|
||||||
return account_no
|
return account_no
|
||||||
end
|
end
|
||||||
def self.generate_security_code
|
def self.generate_security_code
|
||||||
|
|
||||||
@@ -33,11 +33,11 @@ class BatchLineItem < ApplicationRecord
|
|||||||
security_code = (0...8).map { o[rand(o.length)] }.join
|
security_code = (0...8).map { o[rand(o.length)] }.join
|
||||||
|
|
||||||
find_account_no = BatchLineItem.find_by_security_code(security_code)
|
find_account_no = BatchLineItem.find_by_security_code(security_code)
|
||||||
if !find_account_no.nil?
|
if !find_account_no.nil?
|
||||||
o = [('0'..'8')].map { |i| i.to_a }.flatten
|
o = [('0'..'8')].map { |i| i.to_a }.flatten
|
||||||
security_code = (0...8).map { o[rand(o.length)] }.join
|
security_code = (0...8).map { o[rand(o.length)] }.join
|
||||||
end
|
end
|
||||||
return security_code
|
return security_code
|
||||||
end
|
end
|
||||||
def self.generate_barcode
|
def self.generate_barcode
|
||||||
|
|
||||||
@@ -45,12 +45,12 @@ class BatchLineItem < ApplicationRecord
|
|||||||
# barcode = (0...8).map { o[rand(o.length)] }.join
|
# barcode = (0...8).map { o[rand(o.length)] }.join
|
||||||
barcode= rand(1_000_000_0..9_999_999_9)
|
barcode= rand(1_000_000_0..9_999_999_9)
|
||||||
find_account_no = BatchLineItem.find_by_barcode(barcode)
|
find_account_no = BatchLineItem.find_by_barcode(barcode)
|
||||||
if !find_account_no.nil?
|
if !find_account_no.nil?
|
||||||
# o = [('0'..'9')].map { |i| i.to_a }.flatten
|
# o = [('0'..'9')].map { |i| i.to_a }.flatten
|
||||||
# barcode = (0...8).map { o[rand(o.length)] }.join
|
# barcode = (0...8).map { o[rand(o.length)] }.join
|
||||||
barcode = rand(1_000_000_0..9_999_999_9)
|
barcode = rand(1_000_000_0..9_999_999_9)
|
||||||
end
|
end
|
||||||
return barcode
|
return barcode
|
||||||
end
|
end
|
||||||
def self.generate_serial_no(client_id)
|
def self.generate_serial_no(client_id)
|
||||||
find_lookup=Lookup.find_by_name('generate_serial_no')
|
find_lookup=Lookup.find_by_name('generate_serial_no')
|
||||||
@@ -58,52 +58,52 @@ class BatchLineItem < ApplicationRecord
|
|||||||
max_value=find_lookup.max_value
|
max_value=find_lookup.max_value
|
||||||
max_value=max_value +1
|
max_value=max_value +1
|
||||||
prefix=find_lookup.prefix
|
prefix=find_lookup.prefix
|
||||||
max_length=find_lookup.max_length
|
max_length=find_lookup.max_length
|
||||||
sufix_len=max_length-prefix.length
|
sufix_len=max_length-prefix.length
|
||||||
sufix_str="0" * sufix_len
|
sufix_str="0" * sufix_len
|
||||||
value_len= max_value.to_s.length
|
value_len= max_value.to_s.length
|
||||||
|
|
||||||
start=0
|
start=0
|
||||||
ends=sufix_len-value_len-1
|
ends=sufix_len-value_len-1
|
||||||
sufix_str= sufix_str[start..ends]
|
sufix_str= sufix_str[start..ends]
|
||||||
|
|
||||||
prefix_len=prefix.to_s.length
|
prefix_len=prefix.to_s.length
|
||||||
client_len= client_id.to_s.length
|
client_len= client_id.to_s.length
|
||||||
ends= prefix_len -client_len -1
|
ends= prefix_len -client_len -1
|
||||||
prefix=prefix[start..ends]
|
prefix=prefix[start..ends]
|
||||||
|
|
||||||
prefix_str=prefix.to_s + client_id.to_s
|
prefix_str=prefix.to_s + client_id.to_s
|
||||||
|
|
||||||
serial_no=prefix_str.to_s+sufix_str+max_value.to_s
|
serial_no=prefix_str.to_s+sufix_str+max_value.to_s
|
||||||
return serial_no
|
return serial_no
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def self.to_csv(client_id,location_code)
|
def self.to_csv(client_id,location_code)
|
||||||
encrypt_key=""
|
encrypt_key=""
|
||||||
|
|
||||||
find_client=Client.find_by_id(client_id)
|
find_client=Client.find_by_id(client_id)
|
||||||
if !find_client.nil?
|
if !find_client.nil?
|
||||||
encrypt_key=find_client.secrect_key
|
encrypt_key=find_client.secrect_key
|
||||||
end
|
end
|
||||||
attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token location}
|
attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token location}
|
||||||
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
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
elsif encoder.product_type_id == 3
|
elsif encoder.product_type_id == 3
|
||||||
|
|
||||||
attributes = attributes+ %w{security_code}
|
attributes = attributes+ %w{security_code}
|
||||||
str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s+"&security_code="+encoder.security_code.to_s
|
str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s+"&security_code="+encoder.security_code.to_s
|
||||||
else
|
else
|
||||||
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
|
||||||
|
|
||||||
encryptd_data=BatchLineItem.encrypted(str,encrypt_key)
|
encryptd_data=BatchLineItem.encrypted(str,encrypt_key)
|
||||||
encoder.secret_token=encryptd_data
|
encoder.secret_token=encryptd_data
|
||||||
encoder.location=location_code
|
encoder.location=location_code
|
||||||
csv << attributes.map{ |attr| encoder.send(attr)}
|
csv << attributes.map{ |attr| encoder.send(attr)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -111,50 +111,47 @@ class BatchLineItem < ApplicationRecord
|
|||||||
|
|
||||||
def self.to_csv_seller(client_id,location_code)
|
def self.to_csv_seller(client_id,location_code)
|
||||||
encrypt_key=""
|
encrypt_key=""
|
||||||
|
|
||||||
find_client=Client.find_by_id(client_id)
|
find_client=Client.find_by_id(client_id)
|
||||||
if !find_client.nil?
|
if !find_client.nil?
|
||||||
encrypt_key=find_client.secrect_key
|
encrypt_key=find_client.secrect_key
|
||||||
end
|
end
|
||||||
attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token location barcode}
|
attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token location barcode}
|
||||||
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
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
elsif encoder.product_type_id == 3
|
elsif encoder.product_type_id == 3
|
||||||
|
|
||||||
attributes = attributes+ %w{security_code}
|
attributes = attributes+ %w{security_code}
|
||||||
str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s+"&security_code="+encoder.security_code.to_s
|
str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s+"&security_code="+encoder.security_code.to_s
|
||||||
else
|
else
|
||||||
str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s+"&barcode="+encoder.barcode.to_s
|
str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s+"&barcode="+encoder.barcode.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
encryptd_data=BatchLineItem.encrypted(str,encrypt_key)
|
encryptd_data=BatchLineItem.encrypted(str,encrypt_key)
|
||||||
encoder.secret_token=encryptd_data
|
encoder.secret_token=encryptd_data
|
||||||
encoder.location=location_code
|
encoder.location=location_code
|
||||||
csv << attributes.map{ |attr| encoder.send(attr)}
|
csv << attributes.map{ |attr| encoder.send(attr)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def self.encrypted(message,encrypt_key)
|
def self.encrypted(message,encrypt_key)
|
||||||
cipher = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
|
cipher = OpenSSL::Cipher.new("aes-256-cbc")
|
||||||
cipher.encrypt
|
cipher.encrypt
|
||||||
|
|
||||||
key = Digest::SHA1.hexdigest(encrypt_key)
|
|
||||||
iv =encrypt_key
|
|
||||||
|
|
||||||
cipher.key = encrypt_key
|
cipher.key = encrypt_key
|
||||||
cipher.iv = encrypt_key
|
cipher.iv = encrypt_key[0,16]
|
||||||
|
|
||||||
encrypted = cipher.update(message)
|
encrypted = cipher.update(message)
|
||||||
encrypted << cipher.final
|
encrypted << cipher.final
|
||||||
|
|
||||||
encrypted=Base64.encode64(encrypted)
|
encrypted=Base64.encode64(encrypted)
|
||||||
|
|
||||||
return encrypted
|
return encrypted
|
||||||
end
|
end
|
||||||
def self.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type,security_code=nil)
|
def self.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type,security_code=nil)
|
||||||
batchLineItem=BatchLineItem.new
|
batchLineItem=BatchLineItem.new
|
||||||
@@ -175,7 +172,7 @@ class BatchLineItem < ApplicationRecord
|
|||||||
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
|
card_qty=batch.qty_processing.to_i
|
||||||
success_qty=batch.qty_success
|
success_qty=batch.qty_success
|
||||||
|
|
||||||
@@ -190,15 +187,15 @@ class BatchLineItem < ApplicationRecord
|
|||||||
batch.save
|
batch.save
|
||||||
|
|
||||||
@result=false,'Error occurs in registration encoder!'
|
@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..100).each do |i|
|
(1..100).each do |i|
|
||||||
str= SecureRandom.hex
|
str= SecureRandom.hex
|
||||||
uid=str[0..13]
|
uid=str[0..13]
|
||||||
arr.push(uid)
|
arr.push(uid)
|
||||||
end
|
end
|
||||||
@arr=arr
|
@arr=arr
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
class Client < ApplicationRecord
|
class Client < ApplicationRecord
|
||||||
validates :name, presence: { message: "Please enter client name." }
|
validates :name, presence: { message: "Please enter client name." }
|
||||||
validates :name, :uniqueness => {:message =>"This client name is already taken." } ,on: :create
|
validates :name, :uniqueness => {:message =>"This client name is already taken." } ,on: :create
|
||||||
validates :location_code ,presence: { message: "Please enter client location code." }
|
validates :location_code ,presence: { message: "Please enter client location code." }
|
||||||
validates :location_code, :uniqueness => {:message =>"This location code is already taken." } ,on: :create
|
validates :location_code, :uniqueness => {:message =>"This location code is already taken." } ,on: :create
|
||||||
|
|
||||||
|
def secrect_key
|
||||||
|
Base64.decode64(super)
|
||||||
|
end
|
||||||
|
|
||||||
|
def secrect_key=(value)
|
||||||
|
super(Base64.encode64(value))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
if @out[0] == true
|
||||||
|
json.set! :status, @out[0]
|
||||||
|
json.set! :message, @out[1]
|
||||||
|
else
|
||||||
|
json.set! :status, @out[0]
|
||||||
|
json.set! :message, @out[1]
|
||||||
|
end
|
||||||
3
app/views/api/batches/get_ticket_settings.json.jbuilder
Normal file
3
app/views/api/batches/get_ticket_settings.json.jbuilder
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
json.set! :status, @out[0]
|
||||||
|
json.set! :message, @out[1]
|
||||||
@@ -53,6 +53,7 @@ Rails.application.routes.draw do
|
|||||||
#batch_line_items
|
#batch_line_items
|
||||||
post "generate_card_account_items" =>"batch_line_items#generate_card_account_items"
|
post "generate_card_account_items" =>"batch_line_items#generate_card_account_items"
|
||||||
post "update_manufacture_uid" => "batch_line_items#update_manufacture_uid"
|
post "update_manufacture_uid" => "batch_line_items#update_manufacture_uid"
|
||||||
|
post "update_barcode_and_account_no" => "batch_line_items#update_barcode_and_account_no"
|
||||||
post "code_activate" => "batch_line_items#code_activate"
|
post "code_activate" => "batch_line_items#code_activate"
|
||||||
get "activated_list" => "batch_line_items#activated_list"
|
get "activated_list" => "batch_line_items#activated_list"
|
||||||
get "seller_info" => "batch_line_items#seller_info"
|
get "seller_info" => "batch_line_items#seller_info"
|
||||||
|
|||||||
9
db/migrate/20180810041316_create_setting.rb
Normal file
9
db/migrate/20180810041316_create_setting.rb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
class CreateSetting < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
create_table :settings do |t|
|
||||||
|
t.string :key
|
||||||
|
t.string :value
|
||||||
|
t.string :name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user