add new file
This commit is contained in:
@@ -2,9 +2,10 @@ class BatchLineItemsController < ApplicationController
|
||||
require "csv"
|
||||
skip_before_filter :verify_authenticity_token
|
||||
before_action :authenticate_member!
|
||||
respond_to :json, :html
|
||||
# respond_to :json, :html,:csv
|
||||
|
||||
def index
|
||||
|
||||
user_id=current_member.user_id
|
||||
|
||||
@clients=Client.all
|
||||
@@ -18,33 +19,33 @@ class BatchLineItemsController < ApplicationController
|
||||
client_id=params[:client_id]
|
||||
batches=Batch.where('client_id=?',client_id)
|
||||
if !batches.nil?
|
||||
respond_with(data: batches,status: true)
|
||||
render :json => { :data => batches,:status => true }
|
||||
# respond_with(data: batches,status: true)
|
||||
else
|
||||
respond_with(data: nil,status: false)
|
||||
# respond_with(data: nil,status: false)
|
||||
end
|
||||
end
|
||||
def export
|
||||
def export
|
||||
batch_list=""
|
||||
@batchLineItems=""
|
||||
user_id=current_member.user_id
|
||||
|
||||
@clients=Client.all
|
||||
@batches=Batch.where('user_id=?',user_id)
|
||||
|
||||
if params[:batch].present?
|
||||
batch_list=params[:batch]
|
||||
end
|
||||
client_id=params[:client]
|
||||
|
||||
user_id=current_member.user_id
|
||||
if !batch_list.empty?
|
||||
if batch_list=="ALL"
|
||||
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
|
||||
|
||||
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")
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.csv { send_data @batchLineItems.to_csv(user_id), filename: "encoder-#{Date.today}.csv" }
|
||||
end
|
||||
else
|
||||
redirect_to batch_line_items_path, notice: 'No batch to export for this client.'
|
||||
end
|
||||
format.html
|
||||
format.csv { send_data @batchLineItems.to_csv(client_id), filename: "encoder-#{Date.today}.csv" }
|
||||
end
|
||||
end
|
||||
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, :nrc, :email, :phone, :address,:product_type)
|
||||
params.require(:client).permit(:name,:email, :phone, :address,:product_type)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class BatchLineItem < ApplicationRecord
|
||||
belongs_to :batch
|
||||
attr_accessor :wristband_token
|
||||
|
||||
def self.generate_account_no
|
||||
attr_accessor :secret_token
|
||||
|
||||
def self.generate_account_no
|
||||
super_merchant = "101"
|
||||
account_type='1'
|
||||
location='101'
|
||||
@@ -41,21 +41,20 @@ class BatchLineItem < ApplicationRecord
|
||||
|
||||
end
|
||||
end
|
||||
def self.to_csv(user_id)
|
||||
def self.to_csv(client_id)
|
||||
encrypt_key=""
|
||||
|
||||
find_user=User.find_by_id(user_id)
|
||||
if !find_user.nil?
|
||||
encrypt_key=find_user.secrect_key
|
||||
find_client=Client.find_by_id(client_id)
|
||||
if !find_client.nil?
|
||||
encrypt_key=find_client.secrect_key
|
||||
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 << attributes
|
||||
all.each do |encoder|
|
||||
str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
|
||||
|
||||
encryptd_data=BatchLineItem.encrypted(str,encrypt_key)
|
||||
encoder.wristband_token=encryptd_data
|
||||
encoder.secret_token=encryptd_data
|
||||
|
||||
csv << attributes.map{ |attr| encoder.send(attr)}
|
||||
end
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
class Client < ApplicationRecord
|
||||
validates :name, presence: { message: "Please enter client name." }
|
||||
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." }
|
||||
validates :name, :uniqueness => {:message =>"This client name is already taken." } ,on: :create
|
||||
end
|
||||
|
||||
@@ -5,32 +5,7 @@
|
||||
</nav>
|
||||
</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="card">
|
||||
<div class="card-header">
|
||||
@@ -68,34 +43,3 @@
|
||||
</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>
|
||||
<%= f.input :name ,:label =>false,:error => false,:placeholder =>'Please enter client name',input_html: { class: "form-control" } %>
|
||||
<%= f.error :name ,style: 'color: red' %>
|
||||
</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>
|
||||
<div class ="form-group" >
|
||||
<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.error :email ,style: 'color: red' %>
|
||||
<%= f.input :email ,:error=>false,:label =>false ,:placeholder =>'Please enter client email',input_html: { class: "form-control" } %>
|
||||
</div>
|
||||
<div class ="form-group" >
|
||||
<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.error :phone ,style: 'color: red' %>
|
||||
<%= f.input :phone,:error=>false,:label =>false,:placeholder =>'Please enter client phone',input_html: { class: "form-control" } %>
|
||||
</div>
|
||||
<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" } %>
|
||||
<%= f.error :address ,style: 'color: red' %>
|
||||
<%= 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>
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
<table class="table" style="border-top:none">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Nrc</th>
|
||||
<th>Name</th>
|
||||
<th>Email</th>
|
||||
<th>Phone</th>
|
||||
<th>Address</th>
|
||||
@@ -31,8 +30,7 @@
|
||||
<tbody>
|
||||
<% @clients.each do |client| %>
|
||||
<tr>
|
||||
<td><%= client.name rescue '' %></td>
|
||||
<td><%= client.nrc rescue '' %></td>
|
||||
<td><%= client.name rescue '' %></td>
|
||||
<td><%= client.email rescue '' %></td>
|
||||
<td><%= client.phone rescue '' %></td>
|
||||
<td><%= client.address rescue '' %></td>
|
||||
|
||||
@@ -10,11 +10,7 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-4"><strong>Name:</strong></div>
|
||||
<div class="col-lg-8 uppercase"><%= @client.name %></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-4"><strong>NRC:</strong></div>
|
||||
<div class="col-lg-8"><%= @client.nrc %></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-4"><strong>Email:</strong></div>
|
||||
<div class="col-lg-8"><%= @client.email %></div>
|
||||
|
||||
@@ -12,14 +12,22 @@
|
||||
<%= link_to "Batches",batches_path, :class => "nav-link" %>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<%= link_to "Issued Batch Item",batch_line_items_path, :class => "nav-link" %>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<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">
|
||||
<%= link_to "User",users_path, :class => "nav-link" %>
|
||||
</li>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<%= link_to "Client",clients_path, :class => "nav-link" %>
|
||||
</li>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
<div class="float-xs-right">
|
||||
<ul class="nav navbar-nav right">
|
||||
|
||||
Reference in New Issue
Block a user