add new api
This commit is contained in:
@@ -1,67 +1,82 @@
|
||||
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]
|
||||
user_id=""
|
||||
manufacture_uid = params[:card_manufacture]
|
||||
|
||||
client_id=""
|
||||
|
||||
check_member= Member.authenticate_session_token(session_token)
|
||||
if !check_member.nil?
|
||||
if !check_member.nil?
|
||||
encrypt_key=""
|
||||
find_user=User.find_by_id(check_member.user_id)
|
||||
if !find_user.nil?
|
||||
encrypt_key=find_user.secrect_key
|
||||
user_id=find_user.id
|
||||
end
|
||||
wristband_code=""
|
||||
|
||||
if !encrypt_key.nil?
|
||||
check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid)
|
||||
if check_manufacture.nil?
|
||||
serial_no=BatchLineItem.generate_serial_no(user_id.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
|
||||
hex_str=hex_data.to_s
|
||||
wristband_code=hex_str[0..15]
|
||||
check_wirstband=BatchLineItem.find_by_wristband_code(wristband_code)
|
||||
|
||||
if check_wirstband.nil?
|
||||
puts 'Check Wristband'
|
||||
card_type=""
|
||||
find_batch= Batch.find_by_id(batch_id)
|
||||
if !find_batch.nil?
|
||||
card_type=find_batch.adult_or_child.upcase
|
||||
end
|
||||
batchLineItem=BatchLineItem.new
|
||||
batchLineItem.wristband_code=wristband_code
|
||||
batchLineItem.serial_no=serial_no
|
||||
batchLineItem.batch_id=batch_id
|
||||
batchLineItem.manufacture_uid = manufacture_uid
|
||||
batchLineItem.card_type = card_type
|
||||
|
||||
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
|
||||
find_batch = Batch.find_by_id(batch_id)
|
||||
if !find_batch.nil?
|
||||
card_type=find_batch.adult_or_child.upcase
|
||||
find_user=Client.find_by_id(find_batch.client_id)
|
||||
if !find_user.nil?
|
||||
encrypt_key=find_user.secrect_key
|
||||
product_type=find_user.product_type
|
||||
client_id=find_user.id
|
||||
|
||||
@out = true,batchLineItem.serial_no,batchLineItem.wristband_code
|
||||
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.downcase=="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
|
||||
wristband_code=hex_str[0..15]
|
||||
check_wirstband=BatchLineItem.find_by_asset_identity(wristband_code)
|
||||
|
||||
if check_wirstband.nil?
|
||||
@out=create_product(wristband_code,serial_no,batch_id,manufacture_uid,card_type)
|
||||
else
|
||||
@out=false,'Wristband is already registered!'
|
||||
end
|
||||
elsif product_type=="card"
|
||||
@out=create_product(wristband_code,serial_no,batch_id,manufacture_uid,card_type)
|
||||
end
|
||||
else
|
||||
@out=false,'Error occurs in registration encoder!'
|
||||
end
|
||||
@out=false,'Wristband is already registered!'
|
||||
end
|
||||
else
|
||||
@out=false,'Wristband is already registered!'
|
||||
@out=false,'Invalid User!'
|
||||
end
|
||||
else
|
||||
@out=false,'Wristband is already registered!'
|
||||
@out=false,'Client does not exist!'
|
||||
end
|
||||
else
|
||||
@out=false,'Invalid User!'
|
||||
@out=false,'Batch does not exist!'
|
||||
end
|
||||
else
|
||||
else
|
||||
@out=false,'Sorry!Unauthorized user!'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
def create_product(wristband_code,serial_no,batch_id,manufacture_uid,card_type)
|
||||
batchLineItem=BatchLineItem.new
|
||||
batchLineItem.asset_identity=wristband_code
|
||||
batchLineItem.serial_no=serial_no
|
||||
batchLineItem.batch_id=batch_id
|
||||
batchLineItem.manufacture_uid = manufacture_uid
|
||||
batchLineItem.asset_type = card_type
|
||||
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")
|
||||
|
||||
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
|
||||
|
||||
@result = true,batchLineItem.serial_no,batchLineItem.asset_identity
|
||||
else
|
||||
@result=false,'Error occurs in registration encoder!'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -9,9 +9,10 @@ class Api::BatchesController < ApplicationController
|
||||
order_ref = params[:order_ref]
|
||||
card_qty = params[:card_qty]
|
||||
adult_or_child=params[:adult_or_child]
|
||||
client_id=params[:client_id]
|
||||
|
||||
user_id=check_member.user_id
|
||||
batch = Batch.create_batch(created_by,date,order_ref,card_qty,user_id,adult_or_child)
|
||||
batch = Batch.create_batch(created_by,date,order_ref,card_qty,user_id,adult_or_child,client_id)
|
||||
if !batch.nil?
|
||||
@out=true,batch.id
|
||||
else
|
||||
|
||||
@@ -8,7 +8,7 @@ class BatchLineItemsController < ApplicationController
|
||||
@batches=Batch.where('user_id=?',user_id)
|
||||
@batchLineItems=BatchLineItem.joins('inner join batches on batches.id=batch_line_items.batch_id')
|
||||
.where('batches.user_id=?',user_id)
|
||||
.select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page]).per(2)
|
||||
.select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page])
|
||||
end
|
||||
def export
|
||||
batch_list=params[:batch]
|
||||
|
||||
@@ -29,10 +29,10 @@ class UsersController < ApplicationController
|
||||
@user = User.new(user_params)
|
||||
email=params[:registered_email]
|
||||
@user.is_active=true
|
||||
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
||||
key=cipher.random_key
|
||||
secrect_key= Base64.encode64(key)
|
||||
@user.secrect_key=secrect_key
|
||||
# cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
||||
# key=cipher.random_key
|
||||
# secrect_key= Base64.encode64(key)
|
||||
# @user.secrect_key=secrect_key
|
||||
@email=email
|
||||
respond_to do |format|
|
||||
if @user.save
|
||||
@@ -100,6 +100,6 @@ class UsersController < ApplicationController
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def user_params
|
||||
params.require(:user).permit(:name, :nrc, :email, :phone, :address,:is_active,:secrect_key)
|
||||
params.require(:user).permit(:name, :nrc, :email, :phone, :address,:is_active)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Batch < ApplicationRecord
|
||||
has_many :batch_line_item
|
||||
|
||||
def self.create_batch(created_by,date,order_ref, card_qty,user_id,adult_or_child)
|
||||
def self.create_batch(created_by,date,order_ref, card_qty,user_id,adult_or_child,client_id)
|
||||
batch = Batch.new
|
||||
batch.created_by = created_by
|
||||
batch.order_ref = order_ref
|
||||
@@ -13,6 +13,7 @@ class Batch < ApplicationRecord
|
||||
batch.qty_fail = 0
|
||||
batch.user_id=user_id
|
||||
batch.export_count=0
|
||||
batch.client_id=client_id
|
||||
batch.adult_or_child=adult_or_child.upcase
|
||||
if batch.save
|
||||
return batch
|
||||
|
||||
@@ -20,7 +20,7 @@ class BatchLineItem < ApplicationRecord
|
||||
return account_no
|
||||
end
|
||||
|
||||
def self.generate_serial_no(user_id)
|
||||
def self.generate_serial_no(client_id)
|
||||
find_lookup=Lookup.find_by_name('generate_serial_no')
|
||||
if !find_lookup.nil?
|
||||
max_value=find_lookup.max_value
|
||||
@@ -34,10 +34,11 @@ class BatchLineItem < ApplicationRecord
|
||||
ends=sufix_len-value_len-1
|
||||
sufix_str= sufix_str[start..ends]
|
||||
prefix=prefix[start..2]
|
||||
prefix_str=prefix.to_s + user_id.to_s
|
||||
prefix_str=prefix.to_s + client_id.to_s
|
||||
|
||||
serial_no=prefix_str.to_s+sufix_str+max_value.to_s
|
||||
return serial_no
|
||||
return serial_no
|
||||
|
||||
end
|
||||
end
|
||||
def self.to_csv(user_id)
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
<li class="nav-item">
|
||||
<%= link_to "User",users_path, :class => "nav-link" %>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<%= link_to "Client",clients_path, :class => "nav-link" %>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="float-xs-right">
|
||||
<ul class="nav navbar-nav right">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
Rails.application.routes.draw do
|
||||
|
||||
|
||||
resources :clients
|
||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||
root :to => 'home#index'
|
||||
get "dashboard", to: "home#dashboard", as: "dashboard"
|
||||
@@ -28,5 +29,8 @@ Rails.application.routes.draw do
|
||||
post "batches/end" => "batches#batch_end"
|
||||
get "batches/resume_batch" =>"batches#resume_batch"
|
||||
get "batches/batch_progress_list" =>"batches#batch_progress_list"
|
||||
|
||||
#client
|
||||
get "clients/list" => 'clients#index'
|
||||
end
|
||||
end
|
||||
@@ -3,6 +3,7 @@ class CreateBatches < ActiveRecord::Migration[5.0]
|
||||
create_table :batches do |t|
|
||||
t.datetime :date,:null => false
|
||||
t.references :user
|
||||
t.references :client
|
||||
t.string :order_ref,:null => false
|
||||
t.boolean :batch_start
|
||||
t.boolean :batch_end
|
||||
|
||||
@@ -2,11 +2,13 @@ class CreateBatchLineItems < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :batch_line_items do |t|
|
||||
t.references :batch
|
||||
t.string :serial_no , null: false
|
||||
t.string :wristband_code , null: false
|
||||
t.string :manufacture_uid ,null:false
|
||||
t.string :card_type,:default => "child"
|
||||
t.timestamps null: false
|
||||
t.string :serial_no , null: false
|
||||
t.string :asset_identity , null: false
|
||||
t.string :manufacture_uid ,null:false
|
||||
t.string :asset_type,:default => "child"
|
||||
t.datetime :encoded_at
|
||||
t.datetime :verified_at
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -6,8 +6,7 @@ class CreateUser < ActiveRecord::Migration[5.0]
|
||||
t.string :email
|
||||
t.boolean :is_active,:default =>false
|
||||
t.string :phone
|
||||
t.string :address
|
||||
t.string :secrect_key
|
||||
t.string :address
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
|
||||
31
db/schema.rb
31
db/schema.rb
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170126074122) do
|
||||
ActiveRecord::Schema.define(version: 20170203091136) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -18,9 +18,11 @@ ActiveRecord::Schema.define(version: 20170126074122) do
|
||||
create_table "batch_line_items", force: :cascade do |t|
|
||||
t.integer "batch_id"
|
||||
t.string "serial_no", null: false
|
||||
t.string "wristband_code", null: false
|
||||
t.string "asset_identity", null: false
|
||||
t.string "manufacture_uid", null: false
|
||||
t.string "card_type", default: "child"
|
||||
t.string "asset_type", default: "child"
|
||||
t.datetime "encoded_at"
|
||||
t.datetime "verified_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["batch_id"], name: "index_batch_line_items_on_batch_id", using: :btree
|
||||
@@ -29,6 +31,7 @@ ActiveRecord::Schema.define(version: 20170126074122) do
|
||||
create_table "batches", force: :cascade do |t|
|
||||
t.datetime "date", null: false
|
||||
t.integer "user_id"
|
||||
t.integer "client_id"
|
||||
t.string "order_ref", null: false
|
||||
t.boolean "batch_start"
|
||||
t.boolean "batch_end"
|
||||
@@ -43,9 +46,22 @@ ActiveRecord::Schema.define(version: 20170126074122) do
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "adult_or_child", default: "CHILD"
|
||||
t.index ["client_id"], name: "index_batches_on_client_id", using: :btree
|
||||
t.index ["user_id"], name: "index_batches_on_user_id", using: :btree
|
||||
end
|
||||
|
||||
create_table "clients", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "nrc"
|
||||
t.string "email"
|
||||
t.string "phone"
|
||||
t.string "address"
|
||||
t.string "product_type"
|
||||
t.string "secrect_key"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "lookups", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.integer "max_value"
|
||||
@@ -87,15 +103,14 @@ ActiveRecord::Schema.define(version: 20170126074122) do
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "name", null: false
|
||||
t.string "nrc"
|
||||
t.string "email"
|
||||
t.boolean "is_active", default: false
|
||||
t.boolean "is_active", default: false
|
||||
t.string "phone"
|
||||
t.string "address"
|
||||
t.string "secrect_key"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user