Merge branch 'master' of bitbucket.org:code2lab/nemo_encoder
This commit is contained in:
@@ -2,9 +2,10 @@ 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
|
# respond_to :json, :html,:csv
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|
||||||
user_id=current_member.user_id
|
user_id=current_member.user_id
|
||||||
|
|
||||||
@clients=Client.all
|
@clients=Client.all
|
||||||
@@ -18,33 +19,33 @@ class BatchLineItemsController < ApplicationController
|
|||||||
client_id=params[:client_id]
|
client_id=params[:client_id]
|
||||||
batches=Batch.where('client_id=?',client_id)
|
batches=Batch.where('client_id=?',client_id)
|
||||||
if !batches.nil?
|
if !batches.nil?
|
||||||
respond_with(data: batches,status: true)
|
render :json => { :data => batches,:status => true }
|
||||||
|
# respond_with(data: batches,status: true)
|
||||||
else
|
else
|
||||||
respond_with(data: nil,status: false)
|
# respond_with(data: nil,status: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def export
|
def export
|
||||||
batch_list=""
|
batch_list=""
|
||||||
|
@batchLineItems=""
|
||||||
|
user_id=current_member.user_id
|
||||||
|
|
||||||
|
@clients=Client.all
|
||||||
|
@batches=Batch.where('user_id=?',user_id)
|
||||||
|
|
||||||
if params[:batch].present?
|
if params[:batch].present?
|
||||||
batch_list=params[:batch]
|
batch_list=params[:batch]
|
||||||
end
|
end
|
||||||
client_id=params[:client]
|
client_id=params[:client]
|
||||||
|
|
||||||
user_id=current_member.user_id
|
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")
|
||||||
if batch_list=="ALL"
|
@batchLineItems = BatchLineItem.where('batch_id in (?)',batch_list).select("*,'' as secret_token")
|
||||||
Batch.where("client_id=?",client_id).update_all("export_count = export_count + 1")
|
|
||||||
@batchLineItems = BatchLineItem.where('client_id=?',client_id).select('serial_no,wristband_code,batch_id,manufacture_uid,card_type')
|
|
||||||
else
|
|
||||||
Batch.where("client_id=? and batch_id in (?)",client_id,batch_list).update_all("export_count = export_count + 1")
|
|
||||||
@batchLineItems = BatchLineItem.where('client_id=? and batch_id in (?)',client_id,batch_list).select('*')
|
|
||||||
end
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
format.csv { send_data @batchLineItems.to_csv(user_id), filename: "encoder-#{Date.today}.csv" }
|
format.csv { send_data @batchLineItems.to_csv(client_id), filename: "encoder-#{Date.today}.csv" }
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
redirect_to batch_line_items_path, notice: 'No batch to export for this client.'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -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, :nrc, :email, :phone, :address,:product_type)
|
params.require(:client).permit(:name,:email, :phone, :address,:product_type)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
class BatchLineItem < ApplicationRecord
|
class BatchLineItem < ApplicationRecord
|
||||||
belongs_to :batch
|
belongs_to :batch
|
||||||
attr_accessor :wristband_token
|
attr_accessor :secret_token
|
||||||
|
|
||||||
def self.generate_account_no
|
def self.generate_account_no
|
||||||
super_merchant = "101"
|
super_merchant = "101"
|
||||||
account_type='1'
|
account_type='1'
|
||||||
location='101'
|
location='101'
|
||||||
@@ -41,21 +41,20 @@ class BatchLineItem < ApplicationRecord
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def self.to_csv(user_id)
|
def self.to_csv(client_id)
|
||||||
encrypt_key=""
|
encrypt_key=""
|
||||||
|
|
||||||
find_user=User.find_by_id(user_id)
|
find_client=Client.find_by_id(client_id)
|
||||||
if !find_user.nil?
|
if !find_client.nil?
|
||||||
encrypt_key=find_user.secrect_key
|
encrypt_key=find_client.secrect_key
|
||||||
end
|
end
|
||||||
attributes = %w{serial_no wristband_code batch_id manufacture_uid card_type wristband_token}
|
attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token}
|
||||||
CSV.generate(headers: true) do |csv|
|
CSV.generate(headers: true) do |csv|
|
||||||
csv << attributes
|
csv << attributes
|
||||||
all.each do |encoder|
|
all.each do |encoder|
|
||||||
str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
|
str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
|
||||||
|
|
||||||
encryptd_data=BatchLineItem.encrypted(str,encrypt_key)
|
encryptd_data=BatchLineItem.encrypted(str,encrypt_key)
|
||||||
encoder.wristband_token=encryptd_data
|
encoder.secret_token=encryptd_data
|
||||||
|
|
||||||
csv << attributes.map{ |attr| encoder.send(attr)}
|
csv << attributes.map{ |attr| encoder.send(attr)}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
class Client < ApplicationRecord
|
class Client < ApplicationRecord
|
||||||
validates :name, presence: { message: "Please enter client name." }
|
validates :name, presence: { message: "Please enter client name." }
|
||||||
validates :name, :uniqueness => {:message =>"This client name is already taken." } ,on: :create
|
validates :name, :uniqueness => {:message =>"This client name is already taken." } ,on: :create
|
||||||
validates :email, presence: { message: "Please enter client email." }
|
|
||||||
validates :phone, presence: { message: "Please enter client phone." }
|
|
||||||
validates :address, presence: { message: "Please enter client address." }
|
|
||||||
end
|
end
|
||||||
|
|||||||
60
app/views/batch_line_items/export.html.erb
Normal file
60
app/views/batch_line_items/export.html.erb
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<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>
|
||||||
|
<%= 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>
|
||||||
@@ -5,32 +5,7 @@
|
|||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row top-content">
|
|
||||||
<% flash.each do |name, msg| %>
|
|
||||||
<div class="alert alert-danger">
|
|
||||||
<a class="close" data-dismiss="alert">×</a>
|
|
||||||
<%= msg %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
<br><br>
|
|
||||||
<%= form_tag export_path(:format => :csv),:method => :post do%>
|
|
||||||
<div class="col-lg-4">
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-3">
|
|
||||||
<%= select_tag "client", options_from_collection_for_select(@clients, "id", "name"),:class => 'form-control'%>
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-5">
|
|
||||||
<label><strong>Choose Batch:</strong></label>
|
|
||||||
<select class='selectpicker' id='batch' name='batch[]' multiple= "multiple" >
|
|
||||||
<!--<% @batches.each do |batch| %>
|
|
||||||
<option value="<%= batch.id %>"><%= batch.order_ref %></option>
|
|
||||||
<% end %> -->
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<%= button_tag "Export CSV",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<div class="row content">
|
<div class="row content">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
@@ -68,34 +43,3 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</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();
|
|
||||||
$("#batch").append("<option value='all'>ALL</option>")
|
|
||||||
$.each(result.data, function (i, item){
|
|
||||||
$("#batch").append("<option value="+item.id+">"+ item.order_ref +"</option>")
|
|
||||||
});
|
|
||||||
$('#batch').multiselect("refresh");
|
|
||||||
$("#batch").multiselect('rebuild');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
@@ -16,25 +16,18 @@
|
|||||||
<label for="name" class="string optional control-label">Name:</label>
|
<label for="name" class="string optional control-label">Name:</label>
|
||||||
<%= f.input :name ,:label =>false,:error => false,:placeholder =>'Please enter client name',input_html: { class: "form-control" } %>
|
<%= f.input :name ,:label =>false,:error => false,:placeholder =>'Please enter client name',input_html: { class: "form-control" } %>
|
||||||
<%= f.error :name ,style: 'color: red' %>
|
<%= f.error :name ,style: 'color: red' %>
|
||||||
</div>
|
</div>
|
||||||
<div class ="form-group" >
|
|
||||||
<label for="nrc" class="string optional control-label">NRC:</label>
|
|
||||||
<%= f.input :nrc ,:error=>false,:label =>false,:placeholder =>'Please enter client NRC',input_html: { class: "form-control" } %>
|
|
||||||
</div>
|
|
||||||
<div class ="form-group" >
|
<div class ="form-group" >
|
||||||
<label for="email" class="string optional control-label">Email:</label>
|
<label for="email" class="string optional control-label">Email:</label>
|
||||||
<%= f.input :email ,:error=>false,:label =>false ,:placeholder =>'Please enter client email',input_html: { class: "form-control" } %>
|
<%= f.input :email ,:error=>false,:label =>false ,:placeholder =>'Please enter client email',input_html: { class: "form-control" } %>
|
||||||
<%= f.error :email ,style: 'color: red' %>
|
|
||||||
</div>
|
</div>
|
||||||
<div class ="form-group" >
|
<div class ="form-group" >
|
||||||
<label for="phone" class="string optional control-label">Phone:</label>
|
<label for="phone" class="string optional control-label">Phone:</label>
|
||||||
<%= f.input :phone,:error=>false,:label =>false,:placeholder =>'Please enter client phone',input_html: { class: "form-control" } %>
|
<%= f.input :phone,:error=>false,:label =>false,:placeholder =>'Please enter client phone',input_html: { class: "form-control" } %>
|
||||||
<%= f.error :phone ,style: 'color: red' %>
|
|
||||||
</div>
|
</div>
|
||||||
<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" } %>
|
||||||
<%= f.error :address ,style: 'color: red' %>
|
|
||||||
</div>
|
</div>
|
||||||
<div class ="form-group" >
|
<div class ="form-group" >
|
||||||
<label for="product_type" class="string optional control-label">Product Type:</label>
|
<label for="product_type" class="string optional control-label">Product Type:</label>
|
||||||
|
|||||||
@@ -18,8 +18,7 @@
|
|||||||
<table class="table" style="border-top:none">
|
<table class="table" style="border-top:none">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Nrc</th>
|
|
||||||
<th>Email</th>
|
<th>Email</th>
|
||||||
<th>Phone</th>
|
<th>Phone</th>
|
||||||
<th>Address</th>
|
<th>Address</th>
|
||||||
@@ -31,8 +30,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<% @clients.each do |client| %>
|
<% @clients.each do |client| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= client.name rescue '' %></td>
|
<td><%= client.name rescue '' %></td>
|
||||||
<td><%= client.nrc 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>
|
||||||
|
|||||||
@@ -10,11 +10,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-4"><strong>Name:</strong></div>
|
<div class="col-lg-4"><strong>Name:</strong></div>
|
||||||
<div class="col-lg-8 uppercase"><%= @client.name %></div>
|
<div class="col-lg-8 uppercase"><%= @client.name %></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-4"><strong>NRC:</strong></div>
|
|
||||||
<div class="col-lg-8"><%= @client.nrc %></div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-4"><strong>Email:</strong></div>
|
<div class="col-lg-4"><strong>Email:</strong></div>
|
||||||
<div class="col-lg-8"><%= @client.email %></div>
|
<div class="col-lg-8"><%= @client.email %></div>
|
||||||
|
|||||||
@@ -12,14 +12,22 @@
|
|||||||
<%= 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">
|
||||||
<%= link_to "Issued Batch Item",batch_line_items_path, :class => "nav-link" %>
|
<li class="nav-item dropdown">
|
||||||
</li>
|
<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 class="nav-item">
|
<li class="nav-item">
|
||||||
<%= link_to "User",users_path, :class => "nav-link" %>
|
<%= link_to "User",users_path, :class => "nav-link" %>
|
||||||
</li>
|
</li>
|
||||||
<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">
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Rails.application.routes.draw do
|
|||||||
#users
|
#users
|
||||||
get 'check_registered_email' => "users#check_registered_email"
|
get 'check_registered_email' => "users#check_registered_email"
|
||||||
#Encoder
|
#Encoder
|
||||||
match 'batch_line_items/export' => 'batch_line_items#export', :as => 'export', :via => :post
|
match 'batch_line_items/export' => 'batch_line_items#export', :as => 'export', :via => [:post ,:get]
|
||||||
|
|
||||||
get 'get_batch' => 'batch_line_items#get_batch',:as => 'get_batch'
|
get 'get_batch' => 'batch_line_items#get_batch',:as => 'get_batch'
|
||||||
namespace :api, defaults: {format: :json} do
|
namespace :api, defaults: {format: :json} do
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
class CreateClients < ActiveRecord::Migration[5.0]
|
class CreateClients < ActiveRecord::Migration[5.0]
|
||||||
def change
|
def change
|
||||||
create_table :clients do |t|
|
create_table :clients do |t|
|
||||||
t.string :name,:null => false
|
t.string :name,:null => false
|
||||||
t.string :nrc
|
|
||||||
t.string :email
|
t.string :email
|
||||||
t.string :phone
|
t.string :phone
|
||||||
t.string :address
|
t.string :address
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ ActiveRecord::Schema.define(version: 20170203091136) do
|
|||||||
|
|
||||||
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 "nrc"
|
|
||||||
t.string "email"
|
t.string "email"
|
||||||
t.string "phone"
|
t.string "phone"
|
||||||
t.string "address"
|
t.string "address"
|
||||||
|
|||||||
Reference in New Issue
Block a user