edit api
This commit is contained in:
@@ -4,7 +4,8 @@ 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]
|
||||
|
||||
client_id=""
|
||||
|
||||
check_member= Member.authenticate_session_token(session_token)
|
||||
@@ -14,69 +15,58 @@ class Api::BatchLineItemsController < ApplicationController
|
||||
|
||||
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
|
||||
card_type=find_batch.adult_or_child.upcase
|
||||
find_product_category=ProductCategory.find_by_id(product_category_id)
|
||||
if !find_product_category.nil?
|
||||
product_type=find_product_category.product_type_id
|
||||
|
||||
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
|
||||
asset_identity=hex_str[0..15]
|
||||
check_asset=BatchLineItem.find_by_asset_identity(asset_identity)
|
||||
|
||||
if check_asset.nil?
|
||||
@out=create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
|
||||
else
|
||||
@out=false,'Asset Identity is already registered!'
|
||||
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
|
||||
|
||||
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
|
||||
asset_identity=BatchLineItem.generate_account_no
|
||||
@out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
|
||||
elsif product_type==2
|
||||
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
|
||||
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!'
|
||||
end
|
||||
end
|
||||
elsif product_type=="card"
|
||||
@out=create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
|
||||
end
|
||||
else
|
||||
@out=false,'Manufacture UID is already registered!'
|
||||
end
|
||||
else
|
||||
@out=false,'Manufacture UID is already registered!'
|
||||
end
|
||||
@out=false,'Invalid User!'
|
||||
end
|
||||
else
|
||||
@out=false,'Invalid User!'
|
||||
@out=false,"Client doesn't exist!"
|
||||
end
|
||||
else
|
||||
@out=false,'Client does not exist!'
|
||||
@out=false,"Product Category doesn't exist!"
|
||||
end
|
||||
else
|
||||
@out=false,'Batch does not exist!'
|
||||
@out=false,"Batch doesn't exist!"
|
||||
end
|
||||
else
|
||||
@out=false,'Sorry!Unauthorized user!'
|
||||
end
|
||||
end
|
||||
def create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
|
||||
batchLineItem=BatchLineItem.new
|
||||
batchLineItem.asset_identity=asset_identity
|
||||
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
|
||||
@@ -15,5 +15,5 @@ class Api::ClientsController < ApplicationController
|
||||
else
|
||||
@out=false,"Sorry!Unauthorized user!"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -6,8 +6,8 @@ class BatchLineItemsController < ApplicationController
|
||||
|
||||
def index
|
||||
user_id=current_member.user_id
|
||||
@clients=Client.all.order('id desc')
|
||||
find_client=Client.select(:id).order('id desc').first
|
||||
@clients=Client.all.order('id asc')
|
||||
find_client=Client.select(:id).order('id asc').first
|
||||
if !find_client.nil?
|
||||
client_id=find_client.id
|
||||
|
||||
@@ -20,7 +20,8 @@ class BatchLineItemsController < ApplicationController
|
||||
.select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page]).per(10)
|
||||
end
|
||||
end
|
||||
def search
|
||||
def search
|
||||
|
||||
user_id=current_member.user_id
|
||||
batch_list=params[:batch]
|
||||
client_id=params[:client]
|
||||
@@ -38,7 +39,8 @@ class BatchLineItemsController < ApplicationController
|
||||
@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])
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# if @batchLineItems.nil?
|
||||
# @message="No search found!"
|
||||
# end
|
||||
@@ -68,7 +70,7 @@ class BatchLineItemsController < ApplicationController
|
||||
|
||||
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")
|
||||
@batchLineItems = BatchLineItem.where('batch_id in (?)',batch_list).select("*,'' as secret_token")
|
||||
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+")"
|
||||
@@ -81,7 +83,7 @@ class BatchLineItemsController < ApplicationController
|
||||
format.csv { send_data @batchLineItems.to_csv(client_id), filename: "encoder-#{Date.today}.csv" }
|
||||
end
|
||||
else
|
||||
flash[:notice] = "No data to export."
|
||||
flash[:message] = "No data to export."
|
||||
redirect_to batch_line_items_path
|
||||
end
|
||||
end
|
||||
|
||||
@@ -90,6 +90,6 @@ class ClientsController < ApplicationController
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def client_params
|
||||
params.require(:client).permit(:name,:email, :phone, :address,:product_type)
|
||||
params.require(:client).permit(:name,:email, :phone, :address)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ class BatchLineItem < ApplicationRecord
|
||||
random_account_no = (0...9).map { o[rand(o.length)] }.join
|
||||
|
||||
account_no = super_merchant+account_type+location+random_account_no
|
||||
find_account_no = BatchLineItem.find_by_wristband_code(account_no)
|
||||
find_account_no = BatchLineItem.find_by_asset_identity(account_no)
|
||||
if !find_account_no.nil?
|
||||
o = [('0'..'9')].map { |i| i.to_a }.flatten
|
||||
random_account_no = (0...9).map { o[rand(o.length)] }.join
|
||||
@@ -77,6 +77,27 @@ class BatchLineItem < ApplicationRecord
|
||||
|
||||
return encrypted
|
||||
end
|
||||
def self.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
|
||||
batchLineItem=BatchLineItem.new
|
||||
batchLineItem.asset_identity=asset_identity
|
||||
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
|
||||
|
||||
# def self.encrypted(data,encrypt_key)
|
||||
# crypt = ActiveSupport::MessageEncryptor.new(encrypt_key)
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Serail No</th>
|
||||
<th>Wristband Code</th>
|
||||
<th>Asset Identity</th>
|
||||
<th>Manufacture UID</th>
|
||||
<th>Batch No</th>
|
||||
<th>Card Type</th>
|
||||
<th>Asset Type</th>
|
||||
<th>Created At </th>
|
||||
<th>Update At </th>
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
<% @batchLineItems.each do |item| %>
|
||||
<tr>
|
||||
<td><%= item.serial_no rescue '' %></td>
|
||||
<td><%= item.wristband_code rescue '' %></td>
|
||||
<td><%= item.asset_identity rescue '' %></td>
|
||||
<td><%= item.manufacture_uid rescue '' %></td>
|
||||
<td><%= item.batch_name rescue '' %></td>
|
||||
<td><%= item.card_type rescue '' %></td>
|
||||
<td><%= item.asset_type rescue '' %></td>
|
||||
<td><%= item.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
|
||||
<td><%= item.updated_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
|
||||
</tr>
|
||||
|
||||
@@ -29,10 +29,12 @@
|
||||
<strong>Batch Line Item List</strong>
|
||||
</div>
|
||||
<div class="card-block">
|
||||
<% flash.each do |key, value| %>
|
||||
<% flash.each do |key, value| %>
|
||||
<% if key =='message' %>
|
||||
<div class="alert alert-danger center">
|
||||
<a class="close" data-dismiss="alert">×</a>
|
||||
<%= value %>
|
||||
<%= value %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div id ="filterrific_results">
|
||||
@@ -40,10 +42,10 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Serail No</th>
|
||||
<th>Wristband Code</th>
|
||||
<th>Asset Identity</th>
|
||||
<th>Manufacture UID</th>
|
||||
<th>Batch No</th>
|
||||
<th>Card Type</th>
|
||||
<th>Asset Type</th>
|
||||
<th>Created At </th>
|
||||
<th>Update At </th>
|
||||
|
||||
@@ -53,10 +55,10 @@
|
||||
<% @batchLineItems.each do |item| %>
|
||||
<tr>
|
||||
<td><%= item.serial_no rescue '' %></td>
|
||||
<td><%= item.wristband_code rescue '' %></td>
|
||||
<td><%= item.asset_identity rescue '' %></td>
|
||||
<td><%= item.manufacture_uid rescue '' %></td>
|
||||
<td><%= item.batch_name rescue '' %></td>
|
||||
<td><%= item.card_type rescue '' %></td>
|
||||
<td><%= item.asset_type rescue '' %></td>
|
||||
<td><%= item.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
|
||||
<td><%= item.updated_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
|
||||
</tr>
|
||||
@@ -108,7 +110,7 @@ $(document).ready(function(){
|
||||
batch=$(this).val();
|
||||
filter(client,batch);
|
||||
|
||||
});
|
||||
});
|
||||
function filter(client,batch){
|
||||
if (batch==null){
|
||||
batch=""
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
|
||||
render(partial: 'batch_line_items/search', locals: { batchLineItems: @batchLineItems })
|
||||
) %>
|
||||
$("#filterrific_results").html("<%= js %>");
|
||||
$("#filterrific_results").html("<%= js %>");
|
||||
$('.pagination a').attr('data-remote', 'true');
|
||||
@@ -28,13 +28,7 @@
|
||||
<div class ="form-group" >
|
||||
<label for="address" class="string optional control-label">Address:</label>
|
||||
<%= f.input :address,:error=>false,:label =>false,:placeholder =>'Please enter client address',input_html: { class: "form-control" } %>
|
||||
</div>
|
||||
<div class ="form-group" >
|
||||
<label for="product_type" class="string optional control-label">Product Type:</label>
|
||||
<%= f.select :product_type,options_for_select([['CARD','card'],['TICKET','ticket']], params[:product_type]),
|
||||
{}, { :class => 'form-control' } %>
|
||||
<%= f.error :product_type ,style: 'color: red' %>
|
||||
</div>
|
||||
</div>
|
||||
<div class ="form-group" >
|
||||
<label></label>
|
||||
<div class="actions">
|
||||
|
||||
@@ -21,8 +21,7 @@
|
||||
<th>Name</th>
|
||||
<th>Email</th>
|
||||
<th>Phone</th>
|
||||
<th>Address</th>
|
||||
<th>Product Type</th>
|
||||
<th>Address</th>
|
||||
<th>Created At </th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
@@ -33,15 +32,14 @@
|
||||
<td><%= client.name rescue '' %></td>
|
||||
<td><%= client.email rescue '' %></td>
|
||||
<td><%= client.phone rescue '' %></td>
|
||||
<td><%= client.address rescue '' %></td>
|
||||
<td><%= client.product_type rescue '' %></td>
|
||||
<td><%= client.address rescue '' %></td>
|
||||
<td><%= client.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
|
||||
<td>
|
||||
<%= link_to 'Detail',
|
||||
client_path(client), :class => 'btn btn-primary btn-sm' %>
|
||||
<%= link_to 'Edit',
|
||||
edit_client_path(client), :class => 'btn btn-primary btn-sm' %>
|
||||
<%= link_to 'Delete', clients_path(client), method: :delete, data: { confirm: 'Are you sure?' },:class => 'btn btn-primary btn-sm' %>
|
||||
<%= link_to 'Delete', client_path(client), method: :delete, data: { confirm: 'Are you sure?' },:class => 'btn btn-primary btn-sm' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user