qr code generate

This commit is contained in:
nandar
2018-03-05 11:07:59 +06:30
parent 55bf089d8d
commit b81a6dbc96
10 changed files with 190 additions and 15 deletions

View File

@@ -2,7 +2,7 @@ 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!
require 'digest/md5'
def index def index
# user_id=current_member.user_id # user_id=current_member.user_id
@@ -99,13 +99,13 @@ 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")
.joins('inner join product_categories product on product.id=batches.product_category_id') .joins('inner join product_categories product on product.id=batches.product_category_id')
.where('batch_id in (?)',batch_list) .where('batch_id in (?)',batch_list)
.select("*,product.product_type_id ,product.name,'' as secret_token,'' as location") .select("*,product.product_type_id ,product.name,'' as secret_token,'' as location_name")
else else
Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1,exported_by='"+exported_by+"'") Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1,exported_by='"+exported_by+"'")
sub_query="(select * from batches where client_id ="+client_id+" and product_category_id="+ product_category_id+")" sub_query="(select * from batches where client_id ="+client_id+" and product_category_id="+ product_category_id+")"
@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')
.joins('inner join product_categories as product on product.id=batches.product_category_id') .joins('inner join product_categories as product on product.id=batches.product_category_id')
.select("*,product.product_type_id ,product.name,'' as secret_token,'' as location") .select("*,product.product_type_id ,product.name,'' as secret_token,'' as location_name")
end end
datestr= Time.now.strftime("%Y/%m/%d %H:%M:%S") datestr= Time.now.strftime("%Y/%m/%d %H:%M:%S")
@@ -115,4 +115,71 @@ class BatchLineItemsController < ApplicationController
format.csv { send_data @batchLineItems.to_csv(client_id,location_code), filename: "#{filename}.csv" } format.csv { send_data @batchLineItems.to_csv(client_id,location_code), filename: "#{filename}.csv" }
end end
end end
def generate_cards
end
def generate_card_account_items
# Generate Code
batch_id=params[:id]
client_id=""
qty = params[:qty]
total_count=0
# check_member= Member.authenticate_session_token(session_token)
# if !check_member.nil?
encrypt_key=""
asset_identity=""
find_batch = Batch.find_by_id(batch_id)
if !find_batch.nil?
puts 'hkjfklasj'
card_type=find_batch.adult_or_child.upcase
product_category_id=find_batch.product_category_id
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
location_code=find_user.location_code
client_id=find_user.id
if !encrypt_key.nil?
# Generate with qty
qty.to_i.times do |i|
serial_no=BatchLineItem.generate_serial_no(client_id.to_s)
asset_identity=BatchLineItem.generate_account_no(location_code)
security_code=BatchLineItem.generate_security_code
out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,"","",security_code)
total_count+=1
end
respond_to do |format|
format.html { redirect_to batch_url(batch_id), notice: 'Successfully generated.' }
format.json { head :no_content }
end
# Generate with qty
else
@out=false,'Invalid User!'
end
else
@out=false,"Client doesn't exist!"
end
else
@out=false,"Product Category doesn't exist!"
end
else
@out=false,"Batch doesn't exist!"
end
# else
# @out=false,'Sorry!Unauthorized user!'
# end
# Generate Code
end
end end

View File

@@ -1,6 +1,7 @@
class BatchesController < ApplicationController class BatchesController < ApplicationController
skip_before_filter :verify_authenticity_token skip_before_filter :verify_authenticity_token
before_action :authenticate_member! # before_action :authenticate_member!
before_action :set_batch,:authenticate_member!, only: [:show, :edit, :update, :destroy]
def index def index
@product_category_id="" @product_category_id=""
@clients=Client.all.order('id desc') @clients=Client.all.order('id desc')
@@ -12,6 +13,63 @@ class BatchesController < ApplicationController
end end
def show
@batchLineItems=BatchLineItem.where("batch_id=?",params[:id]).page(params[:page]).per(10)
@result_count= @batchLineItems.total_count
end
def new
@batch = Batch.new
end
def edit
end
def create
date = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
order_ref = params[:batch][:order_ref]
puts order_ref
adult_or_child=params[:adult_or_child]
client_id=params[:client_id]
product_category_id=params[:product_category_id]
@batch = Batch.create_batch(date,order_ref,2,"adult_or_child",6,3)
puts @batch.order_ref
respond_to do |format|
if @batch.save
format.html { redirect_to @batch, notice: 'Batch was successfully created.' }
format.json { render :show, status: :created, location: @batch }
else
format.html { render :new }
format.json { render json: @batch.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @batch.update(batch_params)
format.html { redirect_to @batch, notice: 'Batch was successfully updated.' }
format.json { render :show, status: :ok, location: @batch }
else
format.html { render :edit }
format.json { render json: @batch.errors, status: :unprocessable_entity }
end
end
end
def destroy
@batch.destroy
respond_to do |format|
format.html { redirect_to batches_url, notice: 'Batch was successfully destroyed.' }
format.json { head :no_content }
end
end
def search def search
client_id=params[:client_id] client_id=params[:client_id]
product_category_id=params[:product_category_id] product_category_id=params[:product_category_id]
@@ -51,4 +109,14 @@ class BatchesController < ApplicationController
end end
end end
private
# Use callbacks to share common setup or constraints between actions.
def set_batch
@batch = Batch.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def batch_params
params.require(:batch).permit(:date,:user_id, :client_id, :order_ref,:batch_start,:batch_end,:exported_by,:qty_processing,:qty_success,:qty_fail,:batch_start_time,:batch_end_time,:export_count,:remark,:adult_or_child,:product_category_id)
end
end end

View File

@@ -1,5 +1,8 @@
class Batch < ApplicationRecord class Batch < ApplicationRecord
has_many :batch_line_item has_many :batch_line_item
belongs_to :client
belongs_to :product_category
belongs_to :user
def self.create_batch(date,order_ref,user_id,adult_or_child,client_id,product_category_id) def self.create_batch(date,order_ref,user_id,adult_or_child,client_id,product_category_id)
batch = Batch.new batch = Batch.new

View File

@@ -3,6 +3,7 @@ class BatchLineItem < ApplicationRecord
attr_accessor :secret_token attr_accessor :secret_token
attr_accessor :location attr_accessor :location
attr_accessor :product_type attr_accessor :product_type
require 'digest/md5'
def self.generate_account_no(location_code) def self.generate_account_no(location_code)
super_merchant = "101" super_merchant = "101"
@@ -21,6 +22,18 @@ class BatchLineItem < ApplicationRecord
end end
return account_no return account_no
end end
def self.generate_security_code
o = [('0'..'8')].map { |i| i.to_a }.flatten
security_code = (0...8).map { o[rand(o.length)] }.join
find_account_no = BatchLineItem.find_by_security_code(security_code)
if !find_account_no.nil?
o = [('0'..'8')].map { |i| i.to_a }.flatten
security_code = (0...8).map { o[rand(o.length)] }.join
end
return security_code
end
def self.generate_serial_no(client_id) def self.generate_serial_no(client_id)
find_lookup=Lookup.find_by_name('generate_serial_no') find_lookup=Lookup.find_by_name('generate_serial_no')
if !find_lookup.nil? if !find_lookup.nil?
@@ -54,16 +67,22 @@ class BatchLineItem < ApplicationRecord
if !find_client.nil? if !find_client.nil?
encrypt_key=find_client.secrect_key encrypt_key=find_client.secrect_key
end end
attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token location} attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token location security_code}
CSV.generate(headers: true) do |csv| CSV.generate(headers: true) do |csv|
csv << attributes csv << attributes
all.each do |encoder| all.each do |encoder|
if encoder.product_type_id ==1 if encoder.product_type_id ==1
str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s
else else
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
end end
security_code = encoder.security_code
digest = Digest::MD5.hexdigest(security_code)
puts 'digest............'
puts digest
encryptd_data=BatchLineItem.encrypted(str,encrypt_key) encryptd_data=BatchLineItem.encrypted(str,encrypt_key)
encoder.secret_token=encryptd_data encoder.secret_token=encryptd_data
encoder.location=location_code encoder.location=location_code
@@ -89,7 +108,7 @@ class BatchLineItem < ApplicationRecord
return encrypted return encrypted
end end
def self.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type) def self.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type,security_code=nil)
batchLineItem=BatchLineItem.new batchLineItem=BatchLineItem.new
batchLineItem.asset_identity=asset_identity batchLineItem.asset_identity=asset_identity
batchLineItem.serial_no=serial_no batchLineItem.serial_no=serial_no
@@ -98,7 +117,10 @@ class BatchLineItem < ApplicationRecord
batchLineItem.asset_type = card_type batchLineItem.asset_type = card_type
batchLineItem.encoded_at = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d") 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") batchLineItem.verified_at =DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
if !security_code.nil?
batchLineItem.security_code = security_code
puts 'security_code;fksdfklsdjfklsdfklsdjfklsdjfklsdjflskd'
end
batch=Batch.find_by_id(batch_id) batch=Batch.find_by_id(batch_id)
if batchLineItem.save if batchLineItem.save

BIN
app/views/.DS_Store vendored

Binary file not shown.

View File

@@ -4,6 +4,11 @@
<a class="breadcrumb-item active" href="#">Batches</a> <a class="breadcrumb-item active" href="#">Batches</a>
</nav> </nav>
</div> </div>
<div class="row top-content">
<span style="float: right">
<%= link_to t('.new', :default => t("helpers.links.new")),new_batch_path,:class => 'btn btn-primary' %>
</span>
</div>
<div class="row content"> <div class="row content">
<div class="col-lg-4"> <div class="col-lg-4">
<label><strong>Search:</strong></label> <label><strong>Search:</strong></label>
@@ -47,6 +52,7 @@
<th>Export Count</th> <th>Export Count</th>
<th>Exported By</th> <th>Exported By</th>
<th>Created At</th> <th>Created At</th>
<th>Action</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -60,6 +66,10 @@
<td><%= batch.export_count %></td> <td><%= batch.export_count %></td>
<td><%= batch.exported_by %></td> <td><%= batch.exported_by %></td>
<td><%= batch.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td> <td><%= batch.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
<td>
<%= link_to 'Detail',
batch_path(batch), :class => 'btn btn-primary btn-sm' %>
</td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>

View File

@@ -14,8 +14,8 @@ default: &default
development: development:
<<: *default <<: *default
database: nemo_all database: nemo_oct_31
username: postgres username: nda
default: &default default: &default

View File

@@ -6,7 +6,7 @@ Rails.application.routes.draw do
root :to => 'home#index' root :to => 'home#index'
get "dashboard", to: "home#dashboard", as: "dashboard" get "dashboard", to: "home#dashboard", as: "dashboard"
resources :batches,:only =>[:index] resources :batches
devise_for :members devise_for :members
resources :batch_line_items,:only =>[:index] resources :batch_line_items,:only =>[:index]
resources :users resources :users
@@ -22,6 +22,10 @@ Rails.application.routes.draw do
match 'batch_line_items/export' => 'batch_line_items#export', :as => 'export', :via => [:post ,:get] 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'
get 'generate_cards/:id' => 'batch_line_items#generate_cards',:as => 'generate_cards'
post "generate_card_account_items" =>"batch_line_items#generate_card_account_items"
namespace :api, defaults: {format: :json} do namespace :api, defaults: {format: :json} do
#login #login
post "auth/login" =>"auth#login" post "auth/login" =>"auth#login"

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: 20170210103359) do ActiveRecord::Schema.define(version: 20180226100816) 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"
@@ -26,6 +26,7 @@ ActiveRecord::Schema.define(version: 20170210103359) do
t.datetime "verified_at" t.datetime "verified_at"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "security_code"
t.index ["batch_id"], name: "index_batch_line_items_on_batch_id", using: :btree t.index ["batch_id"], name: "index_batch_line_items_on_batch_id", using: :btree
end end

View File

@@ -1 +1 @@
{"files":{"application-55570bc046304f178e10e45bec721268c8bf8e0a3bc8f2c1f69ff39df39dee3e.js":{"logical_path":"application.js","mtime":"2017-01-19T15:25:44+06:30","size":416216,"digest":"55570bc046304f178e10e45bec721268c8bf8e0a3bc8f2c1f69ff39df39dee3e","integrity":"sha256-VVcLwEYwTxeOEORb7HISaMi/jgo7yPLB9p/znfOd7j4="},"application-13eed745f8cdce49cda636dbb6e1d13489cce811adff36b761521f71e31214e9.css":{"logical_path":"application.css","mtime":"2017-01-19T15:25:44+06:30","size":735,"digest":"13eed745f8cdce49cda636dbb6e1d13489cce811adff36b761521f71e31214e9","integrity":"sha256-E+7XRfjNzknNpjbbtuHRNInM6BGt/za3YVIfceMSFOk="},"application-dd37038c1f0879ef01c745fd8ef7928f3e45a56984deeabd50392be0a3162d6f.js":{"logical_path":"application.js","mtime":"2017-01-21T16:54:30+06:30","size":459409,"digest":"dd37038c1f0879ef01c745fd8ef7928f3e45a56984deeabd50392be0a3162d6f","integrity":"sha256-3TcDjB8Iee8Bx0X9jveSjz5FpWmE3uq9UDkr4KMWLW8="},"application-9db673cb6d4bf3821c5d6ed2f654d4ecb84adecf44609892b94d84b104a4ba68.css":{"logical_path":"application.css","mtime":"2017-01-21T16:54:27+06:30","size":261683,"digest":"9db673cb6d4bf3821c5d6ed2f654d4ecb84adecf44609892b94d84b104a4ba68","integrity":"sha256-nbZzy21L84IcXW7S9lTU7LhK3s9EYJiSuU2EsQSkumg="}},"assets":{"application.js":"application-dd37038c1f0879ef01c745fd8ef7928f3e45a56984deeabd50392be0a3162d6f.js","application.css":"application-9db673cb6d4bf3821c5d6ed2f654d4ecb84adecf44609892b94d84b104a4ba68.css"}} {"files":{"application-55570bc046304f178e10e45bec721268c8bf8e0a3bc8f2c1f69ff39df39dee3e.js":{"logical_path":"application.js","mtime":"2017-01-19T15:25:44+06:30","size":416216,"digest":"55570bc046304f178e10e45bec721268c8bf8e0a3bc8f2c1f69ff39df39dee3e","integrity":"sha256-VVcLwEYwTxeOEORb7HISaMi/jgo7yPLB9p/znfOd7j4="},"application-13eed745f8cdce49cda636dbb6e1d13489cce811adff36b761521f71e31214e9.css":{"logical_path":"application.css","mtime":"2017-01-19T15:25:44+06:30","size":735,"digest":"13eed745f8cdce49cda636dbb6e1d13489cce811adff36b761521f71e31214e9","integrity":"sha256-E+7XRfjNzknNpjbbtuHRNInM6BGt/za3YVIfceMSFOk="},"application-dd37038c1f0879ef01c745fd8ef7928f3e45a56984deeabd50392be0a3162d6f.js":{"logical_path":"application.js","mtime":"2017-01-21T16:54:30+06:30","size":459409,"digest":"dd37038c1f0879ef01c745fd8ef7928f3e45a56984deeabd50392be0a3162d6f","integrity":"sha256-3TcDjB8Iee8Bx0X9jveSjz5FpWmE3uq9UDkr4KMWLW8="},"application-9db673cb6d4bf3821c5d6ed2f654d4ecb84adecf44609892b94d84b104a4ba68.css":{"logical_path":"application.css","mtime":"2017-01-21T16:54:27+06:30","size":261683,"digest":"9db673cb6d4bf3821c5d6ed2f654d4ecb84adecf44609892b94d84b104a4ba68","integrity":"sha256-nbZzy21L84IcXW7S9lTU7LhK3s9EYJiSuU2EsQSkumg="},"spinner-c1cf81bef2ea82eaa43265a5ff786b7cd74e7d5f4f2de104b586f092ca0fb886.gif":{"logical_path":"spinner.gif","mtime":"2017-02-10T11:04:52+06:30","size":723,"digest":"c1cf81bef2ea82eaa43265a5ff786b7cd74e7d5f4f2de104b586f092ca0fb886","integrity":"sha256-wc+BvvLqguqkMmWl/3hrfNdOfV9PLeEEtYbwksoPuIY="},"application-4b07da359561fb578da05680a32fde19ae94afccd5ce3efeef8c5d0f2caa96df.js":{"logical_path":"application.js","mtime":"2017-03-08T14:08:26+06:30","size":482933,"digest":"4b07da359561fb578da05680a32fde19ae94afccd5ce3efeef8c5d0f2caa96df","integrity":"sha256-SwfaNZVh+1eNoFaAoy/eGa6Ur8zVzj7+74xdDyyqlt8="},"application-e6b1e1192547851708d9ee55b2e3889c54242c9f13777b26a8d33acbd5dedbac.css":{"logical_path":"application.css","mtime":"2017-10-26T17:47:18+06:30","size":260095,"digest":"e6b1e1192547851708d9ee55b2e3889c54242c9f13777b26a8d33acbd5dedbac","integrity":"sha256-5rHhGSVHhRcI2e5VsuOInFQkLJ8Td3smqNM6y9Xe26w="}},"assets":{"application.js":"application-4b07da359561fb578da05680a32fde19ae94afccd5ce3efeef8c5d0f2caa96df.js","application.css":"application-e6b1e1192547851708d9ee55b2e3889c54242c9f13777b26a8d33acbd5dedbac.css","spinner.gif":"spinner-c1cf81bef2ea82eaa43265a5ff786b7cd74e7d5f4f2de104b586f092ca0fb886.gif"}}