This commit is contained in:
Sunandar
2017-02-08 17:35:37 +06:30
parent 0b4e69d1be
commit 26d42631c7
14 changed files with 140 additions and 95 deletions

View File

@@ -4,7 +4,8 @@ class Api::BatchLineItemsController < ApplicationController
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]
product_category_id=params[:product_category_id]
client_id="" client_id=""
check_member= Member.authenticate_session_token(session_token) check_member= Member.authenticate_session_token(session_token)
@@ -14,69 +15,58 @@ class Api::BatchLineItemsController < ApplicationController
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
find_user=Client.find_by_id(find_batch.client_id) find_product_category=ProductCategory.find_by_id(product_category_id)
if !find_user.nil? if !find_product_category.nil?
encrypt_key=find_user.secrect_key product_type=find_product_category.product_type_id
product_type=find_user.product_type
client_id=find_user.id
if !encrypt_key.nil? find_user=Client.find_by_id(find_batch.client_id)
check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid) if !find_user.nil?
if check_manufacture.nil? encrypt_key=find_user.secrect_key
serial_no=BatchLineItem.generate_serial_no(client_id.to_s) # product_type=find_user.product_type
if product_type.downcase=="ticket" client_id=find_user.id
str="manufacture_uid="+manufacture_uid.to_s+"&serial_no="+serial_no.to_s
if !encrypt_key.nil?
digest_data= Digest::MD5.hexdigest(str) check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid)
hex_data=digest_data.hex if check_manufacture.nil?
hex_str=hex_data.to_s serial_no=BatchLineItem.generate_serial_no(client_id.to_s)
asset_identity=hex_str[0..15]
check_asset=BatchLineItem.find_by_asset_identity(asset_identity) if product_type ==1
asset_identity=BatchLineItem.generate_account_no
if check_asset.nil? @out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
@out=create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type) elsif product_type==2
else str="manufacture_uid="+manufacture_uid.to_s+"&serial_no="+serial_no.to_s
@out=false,'Asset Identity is already registered!'
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 end
elsif product_type=="card" else
@out=create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type) @out=false,'Manufacture UID is already registered!'
end end
else else
@out=false,'Manufacture UID is already registered!' @out=false,'Invalid User!'
end end
else else
@out=false,'Invalid User!' @out=false,"Client doesn't exist!"
end end
else else
@out=false,'Client does not exist!' @out=false,"Product Category doesn't exist!"
end end
else else
@out=false,'Batch does not exist!' @out=false,"Batch doesn't exist!"
end end
else else
@out=false,'Sorry!Unauthorized user!' @out=false,'Sorry!Unauthorized user!'
end end
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 end

View File

@@ -15,5 +15,5 @@ class Api::ClientsController < ApplicationController
else else
@out=false,"Sorry!Unauthorized user!" @out=false,"Sorry!Unauthorized user!"
end end
end end
end end

View File

@@ -6,8 +6,8 @@ class BatchLineItemsController < ApplicationController
def index def index
user_id=current_member.user_id user_id=current_member.user_id
@clients=Client.all.order('id desc') @clients=Client.all.order('id asc')
find_client=Client.select(:id).order('id desc').first find_client=Client.select(:id).order('id asc').first
if !find_client.nil? if !find_client.nil?
client_id=find_client.id 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) .select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page]).per(10)
end end
end end
def search def search
user_id=current_member.user_id user_id=current_member.user_id
batch_list=params[:batch] batch_list=params[:batch]
client_id=params[:client] 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') @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').page(params[:page])
end end
# if @batchLineItems.nil? # if @batchLineItems.nil?
# @message="No search found!" # @message="No search found!"
# end # end
@@ -68,7 +70,7 @@ class BatchLineItemsController < ApplicationController
if !batch_list.empty? if !batch_list.empty?
Batch.where("client_id=? and id in (?)",client_id,batch_list).update_all("export_count = export_count + 1") 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 else
Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1") 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+")" 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" } format.csv { send_data @batchLineItems.to_csv(client_id), filename: "encoder-#{Date.today}.csv" }
end end
else else
flash[:notice] = "No data to export." flash[:message] = "No data to export."
redirect_to batch_line_items_path redirect_to batch_line_items_path
end end
end end

View File

@@ -90,6 +90,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,:product_type) params.require(:client).permit(:name,:email, :phone, :address)
end end
end end

View File

@@ -11,7 +11,7 @@ class BatchLineItem < ApplicationRecord
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
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? 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
@@ -77,6 +77,27 @@ class BatchLineItem < ApplicationRecord
return encrypted return encrypted
end 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) # def self.encrypted(data,encrypt_key)
# crypt = ActiveSupport::MessageEncryptor.new(encrypt_key) # crypt = ActiveSupport::MessageEncryptor.new(encrypt_key)

View File

@@ -2,10 +2,10 @@
<thead> <thead>
<tr> <tr>
<th>Serail No</th> <th>Serail No</th>
<th>Wristband Code</th> <th>Asset Identity</th>
<th>Manufacture UID</th> <th>Manufacture UID</th>
<th>Batch No</th> <th>Batch No</th>
<th>Card Type</th> <th>Asset Type</th>
<th>Created At </th> <th>Created At </th>
<th>Update At </th> <th>Update At </th>
@@ -15,10 +15,10 @@
<% @batchLineItems.each do |item| %> <% @batchLineItems.each do |item| %>
<tr> <tr>
<td><%= item.serial_no rescue '' %></td> <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.manufacture_uid rescue '' %></td>
<td><%= item.batch_name 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.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
<td><%= item.updated_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td> <td><%= item.updated_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
</tr> </tr>

View File

@@ -29,10 +29,12 @@
<strong>Batch Line Item List</strong> <strong>Batch Line Item List</strong>
</div> </div>
<div class="card-block"> <div class="card-block">
<% flash.each do |key, value| %> <% flash.each do |key, value| %>
<% if key =='message' %>
<div class="alert alert-danger center"> <div class="alert alert-danger center">
<a class="close" data-dismiss="alert">×</a> <a class="close" data-dismiss="alert">×</a>
<%= value %> <%= value %>
<% end %>
</div> </div>
<% end %> <% end %>
<div id ="filterrific_results"> <div id ="filterrific_results">
@@ -40,10 +42,10 @@
<thead> <thead>
<tr> <tr>
<th>Serail No</th> <th>Serail No</th>
<th>Wristband Code</th> <th>Asset Identity</th>
<th>Manufacture UID</th> <th>Manufacture UID</th>
<th>Batch No</th> <th>Batch No</th>
<th>Card Type</th> <th>Asset Type</th>
<th>Created At </th> <th>Created At </th>
<th>Update At </th> <th>Update At </th>
@@ -53,10 +55,10 @@
<% @batchLineItems.each do |item| %> <% @batchLineItems.each do |item| %>
<tr> <tr>
<td><%= item.serial_no rescue '' %></td> <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.manufacture_uid rescue '' %></td>
<td><%= item.batch_name 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.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
<td><%= item.updated_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td> <td><%= item.updated_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
</tr> </tr>
@@ -108,7 +110,7 @@ $(document).ready(function(){
batch=$(this).val(); batch=$(this).val();
filter(client,batch); filter(client,batch);
}); });
function filter(client,batch){ function filter(client,batch){
if (batch==null){ if (batch==null){
batch="" batch=""

View File

@@ -2,4 +2,5 @@
render(partial: 'batch_line_items/search', locals: { batchLineItems: @batchLineItems }) render(partial: 'batch_line_items/search', locals: { batchLineItems: @batchLineItems })
) %> ) %>
$("#filterrific_results").html("<%= js %>"); $("#filterrific_results").html("<%= js %>");
$('.pagination a').attr('data-remote', 'true');

View File

@@ -28,13 +28,7 @@
<div class ="form-group" > <div class ="form-group" >
<label for="address" class="string optional control-label">Address:</label> <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" } %> <%= f.input :address,:error=>false,:label =>false,:placeholder =>'Please enter client address',input_html: { class: "form-control" } %>
</div> </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 class ="form-group" > <div class ="form-group" >
<label></label> <label></label>
<div class="actions"> <div class="actions">

View File

@@ -21,8 +21,7 @@
<th>Name</th> <th>Name</th>
<th>Email</th> <th>Email</th>
<th>Phone</th> <th>Phone</th>
<th>Address</th> <th>Address</th>
<th>Product Type</th>
<th>Created At </th> <th>Created At </th>
<th>Action</th> <th>Action</th>
</tr> </tr>
@@ -33,15 +32,14 @@
<td><%= client.name rescue '' %></td> <td><%= client.name rescue '' %></td>
<td><%= client.email rescue '' %></td> <td><%= client.email rescue '' %></td>
<td><%= client.phone rescue '' %></td> <td><%= client.phone rescue '' %></td>
<td><%= client.address rescue '' %></td> <td><%= client.address rescue '' %></td>
<td><%= client.product_type rescue '' %></td>
<td><%= client.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td> <td><%= client.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
<td> <td>
<%= link_to 'Detail', <%= link_to 'Detail',
client_path(client), :class => 'btn btn-primary btn-sm' %> client_path(client), :class => 'btn btn-primary btn-sm' %>
<%= link_to 'Edit', <%= link_to 'Edit',
edit_client_path(client), :class => 'btn btn-primary btn-sm' %> 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> </td>
</tr> </tr>
<% end %> <% end %>

View File

@@ -35,5 +35,8 @@ Rails.application.routes.draw do
#client #client
get "clients" => 'clients#index' get "clients" => 'clients#index'
#product
get "products" => "products#index"
end end
end end

View File

@@ -4,11 +4,9 @@ class CreateClients < ActiveRecord::Migration[5.0]
t.string :name,:null => false t.string :name,:null => false
t.string :email t.string :email
t.string :phone t.string :phone
t.string :address t.string :address
t.string :product_type
t.string :secrect_key t.string :secrect_key
t.timestamps null: false t.timestamps null: false
t.timestamps
end end
end end
end end

View File

@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170203091136) do ActiveRecord::Schema.define(version: 20170208065316) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -51,14 +51,13 @@ ActiveRecord::Schema.define(version: 20170203091136) do
end end
create_table "clients", force: :cascade do |t| create_table "clients", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "email" t.string "email"
t.string "phone" t.string "phone"
t.string "address" t.string "address"
t.string "product_type"
t.string "secrect_key" t.string "secrect_key"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end
create_table "lookups", force: :cascade do |t| create_table "lookups", force: :cascade do |t|
@@ -101,6 +100,16 @@ ActiveRecord::Schema.define(version: 20170203091136) do
t.index ["user_id"], name: "index_members_on_user_id", using: :btree t.index ["user_id"], name: "index_members_on_user_id", using: :btree
end end
create_table "product_categories", force: :cascade do |t|
t.string "name"
t.integer "product_type_id"
t.index ["product_type_id"], name: "index_product_categories_on_product_type_id", using: :btree
end
create_table "product_types", force: :cascade do |t|
t.string "name"
end
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "nrc" t.string "nrc"

View File

@@ -10,5 +10,32 @@ namespace :setup do
lookup.max_length=16 lookup.max_length=16
lookup.save lookup.save
end end
end
desc "Product Type"
task :set_product_type, [:name] => :environment do |t, args|
find_product_type=ProductType.find_by_name(args.name)
if find_product_type.nil?
product_type=ProductType.new
product_type.name=args.name
product_type.save
else
puts 'Product Type is already taken!'
end
end
desc "Product Categories"
task :set_product_category, [:name,:product_type] => :environment do |t, args|
find_product_type=ProductType.find_by_id(args.product_type)
if !find_product_type.nil?
find_product_category=ProductCategory.find_by_name(args.name)
if find_product_category.nil?
product_category=ProductCategory.new
product_category.name=args.name
product_category.product_type_id=args.product_type
product_category.save
end
else
puts 'Produt Type does not exist!'
end
end end
end end