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,6 +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]
client_id=""
@@ -15,17 +16,25 @@ 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_product_category=ProductCategory.find_by_id(product_category_id)
if !find_product_category.nil?
product_type=find_product_category.product_type_id
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
# 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.downcase=="ticket"
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)
@@ -35,12 +44,10 @@ class Api::BatchLineItemsController < ApplicationController
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)
@out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
else
@out=false,'Asset Identity is already registered!'
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!'
@@ -49,34 +56,17 @@ class Api::BatchLineItemsController < ApplicationController
@out=false,'Invalid User!'
end
else
@out=false,'Client does not exist!'
@out=false,"Client doesn't exist!"
end
else
@out=false,'Batch does not exist!'
@out=false,"Product Category doesn't exist!"
end
else
@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

View File

@@ -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
@@ -21,6 +21,7 @@ class BatchLineItemsController < ApplicationController
end
end
def search
user_id=current_member.user_id
batch_list=params[:batch]
client_id=params[:client]
@@ -39,6 +40,7 @@ class BatchLineItemsController < ApplicationController
.select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page])
end
# if @batchLineItems.nil?
# @message="No search found!"
# end
@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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>

View File

@@ -30,9 +30,11 @@
</div>
<div class="card-block">
<% flash.each do |key, value| %>
<% if key =='message' %>
<div class="alert alert-danger center">
<a class="close" data-dismiss="alert">×</a>
<%= 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>

View File

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

View File

@@ -29,12 +29,6 @@
<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 class ="form-group" >
<label></label>
<div class="actions">

View File

@@ -22,7 +22,6 @@
<th>Email</th>
<th>Phone</th>
<th>Address</th>
<th>Product Type</th>
<th>Created At </th>
<th>Action</th>
</tr>
@@ -34,14 +33,13 @@
<td><%= client.email rescue '' %></td>
<td><%= client.phone 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>
<%= 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 %>

View File

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

View File

@@ -5,10 +5,8 @@ class CreateClients < ActiveRecord::Migration[5.0]
t.string :email
t.string :phone
t.string :address
t.string :product_type
t.string :secrect_key
t.timestamps null: false
t.timestamps
end
end
end

View File

@@ -10,7 +10,7 @@
#
# 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
enable_extension "plpgsql"
@@ -55,7 +55,6 @@ ActiveRecord::Schema.define(version: 20170203091136) do
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
@@ -101,6 +100,16 @@ ActiveRecord::Schema.define(version: 20170203091136) do
t.index ["user_id"], name: "index_members_on_user_id", using: :btree
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|
t.string "name", null: false
t.string "nrc"

View File

@@ -11,4 +11,31 @@ namespace :setup do
lookup.save
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