This commit is contained in:
Sunandar
2017-02-07 18:04:06 +06:30
parent 6fa89a9e75
commit 264debf89a
13 changed files with 185 additions and 117 deletions

BIN
app/.DS_Store vendored

Binary file not shown.

BIN
app/assets/.DS_Store vendored

Binary file not shown.

View File

@@ -257,4 +257,7 @@ hr
.container ul.nav>.nav-item:first-child{ .container ul.nav>.nav-item:first-child{
padding-left: 80px; padding-left: 80px;
} }
.show_image{
padding-top: 30px;
}

View File

@@ -8,9 +8,9 @@ class Api::BatchLineItemsController < ApplicationController
client_id="" client_id=""
check_member= Member.authenticate_session_token(session_token) check_member= Member.authenticate_session_token(session_token)
if !check_member.nil? if !check_member.nil?
encrypt_key="" encrypt_key=""
wristband_code="" asset_identity=""
find_batch = Batch.find_by_id(batch_id) find_batch = Batch.find_by_id(batch_id)
if !find_batch.nil? if !find_batch.nil?
@@ -21,7 +21,7 @@ class Api::BatchLineItemsController < ApplicationController
product_type=find_user.product_type product_type=find_user.product_type
client_id=find_user.id client_id=find_user.id
if !encrypt_key.nil? if !encrypt_key.nil?
check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid) check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid)
if check_manufacture.nil? if check_manufacture.nil?
serial_no=BatchLineItem.generate_serial_no(client_id.to_s) serial_no=BatchLineItem.generate_serial_no(client_id.to_s)
@@ -31,20 +31,20 @@ class Api::BatchLineItemsController < ApplicationController
digest_data= Digest::MD5.hexdigest(str) digest_data= Digest::MD5.hexdigest(str)
hex_data=digest_data.hex hex_data=digest_data.hex
hex_str=hex_data.to_s hex_str=hex_data.to_s
wristband_code=hex_str[0..15] asset_identity=hex_str[0..15]
check_wirstband=BatchLineItem.find_by_asset_identity(wristband_code) check_asset=BatchLineItem.find_by_asset_identity(asset_identity)
if check_wirstband.nil? if check_asset.nil?
@out=create_product(wristband_code,serial_no,batch_id,manufacture_uid,card_type) @out=create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
else else
@out=false,'Wristband is already registered!' @out=false,'Asset Identity is already registered!'
end end
elsif product_type=="card" elsif product_type=="card"
@out=create_product(wristband_code,serial_no,batch_id,manufacture_uid,card_type) @out=create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
end end
else else
@out=false,'Wristband is already registered!' @out=false,'Manufacture UID is already registered!'
end end
else else
@out=false,'Invalid User!' @out=false,'Invalid User!'
end end
@@ -58,9 +58,9 @@ class Api::BatchLineItemsController < ApplicationController
@out=false,'Sorry!Unauthorized user!' @out=false,'Sorry!Unauthorized user!'
end end
end end
def create_product(wristband_code,serial_no,batch_id,manufacture_uid,card_type) def create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type)
batchLineItem=BatchLineItem.new batchLineItem=BatchLineItem.new
batchLineItem.asset_identity=wristband_code batchLineItem.asset_identity=asset_identity
batchLineItem.serial_no=serial_no batchLineItem.serial_no=serial_no
batchLineItem.batch_id=batch_id batchLineItem.batch_id=batch_id
batchLineItem.manufacture_uid = manufacture_uid batchLineItem.manufacture_uid = manufacture_uid

View File

@@ -11,18 +11,23 @@ class Api::BatchesController < ApplicationController
adult_or_child=params[:adult_or_child] adult_or_child=params[:adult_or_child]
client_id=params[:client_id] client_id=params[:client_id]
user_id=check_member.user_id find_client=Client.find_by_id(client_id)
batch = Batch.create_batch(created_by,date,order_ref,card_qty,user_id,adult_or_child,client_id) if !find_client.nil?
if !batch.nil? user_id=check_member.user_id
@out=true,batch.id batch = Batch.create_batch(created_by,date,order_ref,card_qty,user_id,adult_or_child,client_id)
else if !batch.nil?
@out=false,'Error occurs in creating batch!' @out=true,batch.id
end else
else @out=false,'Error occurs in creating batch!'
@out = false, "Sorry!Unauthorized user!" end
else
@out = false, "Client does not exist!"
end
else
@out = false, "Sorry!Unauthorized user!"
end end
end end
def batch_end def batch_end
session_token=params[:session_token] session_token=params[:session_token]
batch_id=params[:batch_id] batch_id=params[:batch_id]
@@ -66,8 +71,7 @@ class Api::BatchesController < ApplicationController
session_token=params[:session_token] session_token=params[:session_token]
created_by=params[:created_by] created_by=params[:created_by]
check_member= Member.authenticate_session_token(session_token)
check_member= Member.authenticate_session_token(session_token)
if !check_member.nil? if !check_member.nil?
if !created_by.nil? if !created_by.nil?
batches = Batch.where('batch_end is null and created_by=?', created_by) batches = Batch.where('batch_end is null and created_by=?', created_by)

View File

@@ -2,19 +2,47 @@ class BatchLineItemsController < ApplicationController
require "csv" require "csv"
skip_before_filter :verify_authenticity_token skip_before_filter :verify_authenticity_token
before_action :authenticate_member! before_action :authenticate_member!
# respond_to :json, :html,:csv
def index def index
user_id=current_member.user_id
@clients=Client.all.order('id desc')
find_client=Client.select(:id).order('id desc').first
if !find_client.nil?
client_id=find_client.id
user_id=current_member.user_id 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')
@clients=Client.all .select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page]).per(10)
else
@batches=Batch.where('user_id=?',user_id) sub_query="(select * from batches where user_id="+user_id.to_s+")"
@batchLineItems=BatchLineItem.joins('inner join 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')
.where('batches.user_id=?',user_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').page(params[:page]) end
end end
def search
user_id=current_member.user_id
batch_list=params[:batch]
client_id=params[:client]
@batchLineItems=nil
if !batch_list.empty?
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])
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])
end
# if @batchLineItems.nil?
# @message="No search found!"
# end
end
def get_batch def get_batch
client_id=params[:client_id] client_id=params[:client_id]
batches=Batch.where('client_id=?',client_id) batches=Batch.where('client_id=?',client_id)
@@ -27,25 +55,34 @@ class BatchLineItemsController < ApplicationController
end end
def export def export
batch_list="" batch_list=""
@batchLineItems="" @batchLineItems=nil
user_id=current_member.user_id user_id=current_member.user_id
@clients=Client.all @clients=Client.all
@batches=Batch.where('user_id=?',user_id) @batches=Batch.where('user_id=?',user_id)
client_id=params[:client]
if params[:batch].present? if params[:batch].present?
batch_list=params[:batch] batch_list=params[:batch]
end end
client_id=params[:client]
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
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")
end
if !@batchLineItems.empty?
respond_to do |format| respond_to do |format|
format.html format.html
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
end else
flash[:notice] = "No data to export."
redirect_to batch_line_items_path
end
end end
end end

View File

@@ -77,6 +77,7 @@ class BatchLineItem < ApplicationRecord
return encrypted return encrypted
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)
# encrypted_data = crypt.encrypt_and_sign(data) # encrypted_data = crypt.encrypt_and_sign(data)

View File

@@ -12,7 +12,7 @@ class Member < ApplicationRecord
else else
mem = Member.find_by_session_token(token) mem = Member.find_by_session_token(token)
if mem.nil? if mem.nil?
return false return nil
else else
return mem return mem
end end

View File

@@ -1,60 +0,0 @@
<div class="row ">
<nav class="breadcrumb">
<a class="breadcrumb-item active" href="<%= dashboard_path %>">Home</a>
<a class="breadcrumb-item active" href="#">Batch Line Item List</a>
<a class="breadcrumb-item active" href="#">Export CSV</a>
</nav>
</div>
<div class="row content">
<div class="card">
<div class="card-header">
<strong>Export CSV</strong>
</div>
<div class="card-block">
<%= form_tag export_path(:format => :csv),:method => :post do%>
<div class="col-lg-4">
<label><strong>Select Client:</strong></label>
<%= select_tag "client", options_from_collection_for_select(@clients, "id", "name"),:class => 'form-control'%>
</div>
<div class="col-lg-6">
<label><strong>Select Batch:</strong></label><br>
<select class='selectpicker' id='batch' name='batch[]' multiple= "multiple"></select> &nbsp; &nbsp;
<%= button_tag "Export CSV",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %>
</div>
<% end %>
</div>
<div class="spacer-30"></div>
</div>
</div>
<script>
$(document).ready(function(){
client_id=$("#client").val();
get_batch(client_id)
$('#client').on('change', function() {
client_id=$(this).val()
get_batch(client_id)
});
function get_batch(client_id){
$('#batch').multiselect('disable');
$.ajax({
type: "GET",
url: '<%= get_batch_path %>',
dataType: "json",
data : {'client_id':client_id },
success: function(result){
if (result.status){
$('#batch').multiselect('enable');
$("#batch").empty();
$.each(result.data, function (i, item){
$("#batch").append("<option value="+item.id+">"+ item.order_ref +"</option>")
});
$('#batch').multiselect("refresh");
$("#batch").multiselect('rebuild');
}
}
});
}
})
</script>

View File

@@ -4,14 +4,38 @@
<a class="breadcrumb-item active" href="#">Batch Line Item List</a> <a class="breadcrumb-item active" href="#">Batch Line Item List</a>
</nav> </nav>
</div> </div>
<div class="row content">
<%= form_tag export_path(:format => :csv),:method => :post do%>
<div class="col-lg-4">
<label><strong>Select Client:</strong></label>
<%= select_tag "client", options_from_collection_for_select(@clients, "id", "name"), :class => 'form-control'%>
</div>
<div class="col-lg-6">
<label><strong>Select Batch:</strong></label><br>
<select class='selectpicker' id='batch' name='batch[]' multiple= "multiple"></select> &nbsp; &nbsp;
<%= button_tag "Export csv?",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %>
</div>
<% end %>
</div>
<div class="row show_image">
<div class="col-lg-6"></div>
<div class="col-lg-4" id="loading">
<img src="<%= asset_path( 'spinner.gif' ) %>" />
</div>
</div>
<div class="row content"> <div class="row content">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<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| %>
<div class="alert alert-danger center">
<a class="close" data-dismiss="alert">×</a>
<%= value %>
</div>
<% end %>
<div id ="filterrific_results">
<table class="table" style="border-top:none"> <table class="table" style="border-top:none">
<thead> <thead>
<tr> <tr>
@@ -39,7 +63,72 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<%=paginate @batchLineItems %> <%=paginate @batchLineItems %>
<div>
</div> </div>
</div> </div>
</div> </div>
<script>
$(document).ready(function(){
$('#loading').hide();
client_id=$("#client").val();
get_batch(client_id)
$('#client').on('change', function() {
client_id=$(this).val()
get_batch(client_id)
});
function get_batch(client_id){
$('#batch').multiselect('disable');
$.ajax({
type: "GET",
url: '<%= get_batch_path %>',
dataType: "json",
data : {'client_id':client_id },
success: function(result){
if (result.status){
$('#batch').multiselect('enable');
$("#batch").empty();
$.each(result.data, function (i, item){
$("#batch").append("<option value="+item.id+">"+ item.order_ref +"</option>")
});
$('#batch').multiselect("refresh");
$("#batch").multiselect('rebuild');
}
}
});
}
$("#client" ).on('change', function(){
client=$(this).val();
batch=$("#batch").val();
filter(client,batch);
})
$('#batch').change(function(){
client=$("#client").val();
batch=$(this).val();
filter(client,batch);
});
function filter(client,batch){
if (batch==null){
batch=""
}
paramlist='client='+client+"&batch="+batch
$.ajax({
type:'GET',
url: '<%= filter_path %>',
data:paramlist,
beforeSend: function(){
$('#loading').show();
},
complete: function(){
$('#loading').hide();
},
success: function(data) {
}
});
}
})
</script>

View File

@@ -12,14 +12,7 @@
<%= link_to "Batches",batches_path, :class => "nav-link" %> <%= link_to "Batches",batches_path, :class => "nav-link" %>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<li class="nav-item dropdown"> <%= link_to "Batch Line Item", batch_line_items_path, :class => "nav-link" %>
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Batch Line Item</a>
<div class="dropdown-menu">
<%= link_to "List", batch_line_items_path, :class => "dropdown-item" %>
<%= link_to "Export CSV", export_path, :class => "dropdown-item" %>
</div>
</li>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<%= link_to "User",users_path, :class => "nav-link" %> <%= link_to "User",users_path, :class => "nav-link" %>
@@ -27,7 +20,6 @@
<li class="nav-item"> <li class="nav-item">
<%= link_to "Client",clients_path, :class => "nav-link" %> <%= link_to "Client",clients_path, :class => "nav-link" %>
</li> </li>
</ul> </ul>
<div class="float-xs-right"> <div class="float-xs-right">
<ul class="nav navbar-nav right"> <ul class="nav navbar-nav right">

View File

@@ -8,9 +8,11 @@ Rails.application.routes.draw do
resources :batches,:only =>[:index] resources :batches,:only =>[:index]
devise_for :members devise_for :members
resources :batch_line_items,:only =>[:index,:create] resources :batch_line_items,:only =>[:index]
resources :users resources :users
# #batchlineitems
get "batch_line_items/search" =>'batch_line_items#search',:as =>'filter'
#users #users
get 'check_registered_email' => "users#check_registered_email" get 'check_registered_email' => "users#check_registered_email"
#Encoder #Encoder