add new field
This commit is contained in:
@@ -4,7 +4,7 @@ class Api::BatchLineItemsController < ApplicationController
|
||||
batch_id=params[:batch_id]
|
||||
session_token=params[:session_token]
|
||||
manufacture_uid = params[:card_manufacture]
|
||||
product_category_id=params[:product_category_id]
|
||||
# product_category_id=params[:product_category_id]
|
||||
|
||||
client_id=""
|
||||
|
||||
@@ -16,7 +16,9 @@ class Api::BatchLineItemsController < ApplicationController
|
||||
find_batch = Batch.find_by_id(batch_id)
|
||||
if !find_batch.nil?
|
||||
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)
|
||||
|
||||
if !find_product_category.nil?
|
||||
product_type=find_product_category.product_type_id
|
||||
|
||||
@@ -28,13 +30,25 @@ class Api::BatchLineItemsController < ApplicationController
|
||||
client_id=find_user.id
|
||||
|
||||
if !encrypt_key.nil?
|
||||
arr=Array.new
|
||||
arr=BatchLineItem.get_array
|
||||
|
||||
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
|
||||
asset_identity=BatchLineItem.generate_account_no(location_code)
|
||||
@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,"")
|
||||
elsif product_type==2
|
||||
str="manufacture_uid="+manufacture_uid.to_s+"&serial_no="+serial_no.to_s
|
||||
|
||||
@@ -42,17 +56,31 @@ class Api::BatchLineItemsController < ApplicationController
|
||||
hex_data=digest_data.hex
|
||||
hex_str=hex_data.to_s
|
||||
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)
|
||||
else
|
||||
@out=false,'Asset Identity is already registered!'
|
||||
|
||||
str_wb=str_wb+asset_identity.to_s+","
|
||||
wb_count=wb_count+1
|
||||
end
|
||||
end
|
||||
else
|
||||
@out=false,'Manufacture UID is already registered!'
|
||||
put @out
|
||||
str_dup=str_dup+manufacture_uid.to_s+","
|
||||
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
|
||||
@out=false,'Invalid User!'
|
||||
end
|
||||
|
||||
@@ -10,16 +10,22 @@ class Api::BatchesController < ApplicationController
|
||||
card_qty = params[:card_qty]
|
||||
adult_or_child=params[:adult_or_child]
|
||||
client_id=params[:client_id]
|
||||
product_category_id=params[:product_category_id]
|
||||
|
||||
find_client=Client.find_by_id(client_id)
|
||||
if !find_client.nil?
|
||||
find_product_category=ProductCategory.find_by_id(product_category_id)
|
||||
if !find_product_category.nil?
|
||||
user_id=check_member.user_id
|
||||
batch = Batch.create_batch(created_by,date,order_ref,card_qty,user_id,adult_or_child,client_id)
|
||||
batch = Batch.create_batch(created_by,date,order_ref,card_qty,user_id,adult_or_child,client_id,product_category_id)
|
||||
if !batch.nil?
|
||||
@out=true,batch.id
|
||||
else
|
||||
@out=false,'Error occurs in creating batch!'
|
||||
end
|
||||
else
|
||||
@out=false,'Product Category does not exists!'
|
||||
end
|
||||
else
|
||||
@out = false, "Client does not exist!"
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ class Api::ClientsController < ApplicationController
|
||||
clients =Client.all
|
||||
arr_client=Array.new
|
||||
clients.each do |client|
|
||||
str={:id => client.id,:name => client.name,:email => client.email,:phone => client.phone,:address => client.address,:product_type => client.product_type}
|
||||
str={:id => client.id,:name => client.name,:email => client.email,:phone => client.phone,:address => client.address}
|
||||
arr_client.push(str)
|
||||
end
|
||||
@out=true,arr_client
|
||||
|
||||
@@ -13,15 +13,14 @@ class BatchLineItemsController < ApplicationController
|
||||
|
||||
sub_query="(select * from batches where user_id="+user_id.to_s+" and client_id="+client_id.to_s+")"
|
||||
@batchLineItems=BatchLineItem.joins('inner join '+sub_query+' as batches on batches.id=batch_line_items.batch_id')
|
||||
.select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page]).per(10)
|
||||
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
|
||||
else
|
||||
sub_query="(select * from batches where user_id="+user_id.to_s+")"
|
||||
@batchLineItems=BatchLineItem.joins('inner join '+ sub_query + ' as batches on batches.id=batch_line_items.batch_id')
|
||||
.select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page]).per(10)
|
||||
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
|
||||
end
|
||||
end
|
||||
def search
|
||||
|
||||
user_id=current_member.user_id
|
||||
batch_list=params[:batch]
|
||||
client_id=params[:client]
|
||||
@@ -32,12 +31,12 @@ class BatchLineItemsController < ApplicationController
|
||||
sub_query="(select * from batches where id in ("+batch_list+") and user_id="+user_id.to_s+" and client_id="+client_id.to_s+")"
|
||||
|
||||
@batchLineItems=BatchLineItem.joins('inner join '+ sub_query +' as batches on batches.id=batch_line_items.batch_id')
|
||||
.select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page])
|
||||
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
|
||||
|
||||
else
|
||||
sub_query="(select * from batches where user_id="+user_id.to_s+" and client_id="+client_id.to_s+")"
|
||||
@batchLineItems=BatchLineItem.joins('inner join '+ sub_query +'as batches on batches.id=batch_line_items.batch_id')
|
||||
.select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page])
|
||||
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
|
||||
|
||||
end
|
||||
|
||||
@@ -71,12 +70,21 @@ class BatchLineItemsController < ApplicationController
|
||||
end
|
||||
|
||||
if !batch_list.empty?
|
||||
Batch.where("client_id=? and id in (?)",client_id,batch_list).update_all("export_count = export_count + 1")
|
||||
@batchLineItems = BatchLineItem.where('batch_id in (?)',batch_list).select("*,'' as secret_token,'' as location")
|
||||
res=Batch.where("client_id=? and id in (?)",client_id,batch_list).update_all("export_count = export_count + 1")
|
||||
|
||||
# sub_query=Batch.where('id in (?)',batch_list).select('*').to_sql
|
||||
sub_query= "(select * from batches where user_id="+user_id.to_s+" and client_id="+client_id.to_s+")"
|
||||
|
||||
@batchLineItems = BatchLineItem.joins('inner join '+sub_query +" as batches on batches.id=batch_line_items.batch_id")
|
||||
.joins('inner join product_categories product on product.id=batches.product_category_id')
|
||||
.where('batch_id in (?)',batch_list)
|
||||
.select("*,product.product_type_id ,product.name,'' as secret_token,'' as location")
|
||||
else
|
||||
Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1")
|
||||
sub_query="(select * from batches where client_id ="+client_id+" and user_id="+user_id.to_s+")"
|
||||
@batchLineItems = BatchLineItem.joins('inner join '+sub_query+' as batches on batches.id=batch_line_items.batch_id').select("*,'' as secret_token,'' as location")
|
||||
@batchLineItems = BatchLineItem.joins('inner join '+sub_query+' as batches on batches.id=batch_line_items.batch_id')
|
||||
.joins('inner join product_categories as product on product.id=batches.product_category_id')
|
||||
.select("*,product.product_type_id ,product.name,'' as secret_token,'' as location")
|
||||
end
|
||||
|
||||
if !@batchLineItems.empty?
|
||||
|
||||
@@ -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,client_id)
|
||||
def self.create_batch(created_by,date,order_ref, card_qty,user_id,adult_or_child,client_id,product_category_id)
|
||||
batch = Batch.new
|
||||
batch.created_by = created_by
|
||||
batch.order_ref = order_ref
|
||||
@@ -14,6 +14,7 @@ class Batch < ApplicationRecord
|
||||
batch.user_id=user_id
|
||||
batch.export_count=0
|
||||
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
|
||||
|
||||
@@ -2,13 +2,13 @@ class BatchLineItem < ApplicationRecord
|
||||
belongs_to :batch
|
||||
attr_accessor :secret_token
|
||||
attr_accessor :location
|
||||
attr_accessor :product_type
|
||||
|
||||
def self.generate_account_no(location_code)
|
||||
super_merchant = "101"
|
||||
account_type='1'
|
||||
location=location_code
|
||||
|
||||
|
||||
o = [('0'..'9')].map { |i| i.to_a }.flatten
|
||||
random_account_no = (0...9).map { o[rand(o.length)] }.join
|
||||
|
||||
@@ -21,7 +21,6 @@ class BatchLineItem < ApplicationRecord
|
||||
end
|
||||
return account_no
|
||||
end
|
||||
|
||||
def self.generate_serial_no(client_id)
|
||||
find_lookup=Lookup.find_by_name('generate_serial_no')
|
||||
if !find_lookup.nil?
|
||||
@@ -54,7 +53,14 @@ class BatchLineItem < ApplicationRecord
|
||||
CSV.generate(headers: true) do |csv|
|
||||
csv << attributes
|
||||
all.each do |encoder|
|
||||
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
|
||||
else
|
||||
puts 'Tickets'
|
||||
str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
|
||||
end
|
||||
|
||||
encryptd_data=BatchLineItem.encrypted(str,encrypt_key)
|
||||
encoder.secret_token=encryptd_data
|
||||
encoder.location=location_code
|
||||
@@ -103,21 +109,11 @@ class BatchLineItem < ApplicationRecord
|
||||
end
|
||||
def self.get_array
|
||||
arr=Array.new
|
||||
str= SecureRandom.hex(13)
|
||||
uid=str[0..14]
|
||||
|
||||
arr=[
|
||||
|
||||
]
|
||||
(1..50).each do |i|
|
||||
str= SecureRandom.hex
|
||||
uid=str[0..13]
|
||||
arr.push(uid)
|
||||
end
|
||||
@arr=arr
|
||||
end
|
||||
# def self.encrypted(data,encrypt_key)
|
||||
# crypt = ActiveSupport::MessageEncryptor.new(encrypt_key)
|
||||
# encrypted_data = crypt.encrypt_and_sign(data)
|
||||
# encrypted_data=Digest::MD5.hexdigest(encrypted_data)
|
||||
|
||||
# data=encrypted_data.hex
|
||||
# data=data.to_s
|
||||
|
||||
# return data[0..15]
|
||||
# end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170208111712) do
|
||||
ActiveRecord::Schema.define(version: 20170209102414) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -46,7 +46,9 @@ ActiveRecord::Schema.define(version: 20170208111712) do
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "adult_or_child", default: "CHILD"
|
||||
t.integer "product_category_id"
|
||||
t.index ["client_id"], name: "index_batches_on_client_id", using: :btree
|
||||
t.index ["product_category_id"], name: "index_batches_on_product_category_id", using: :btree
|
||||
t.index ["user_id"], name: "index_batches_on_user_id", using: :btree
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user