From 99311527963de0c58eea901da7beef06cc6d9267 Mon Sep 17 00:00:00 2001 From: Sunandar Date: Fri, 10 Feb 2017 10:56:47 +0630 Subject: [PATCH] edit --- .DS_Store | Bin 6148 -> 6148 bytes app/assets/.DS_Store | Bin 6148 -> 6148 bytes .../api/batch_line_items_controller.rb | 79 ++++++------------ app/controllers/api/batches_controller.rb | 13 +-- app/models/batch.rb | 9 +- app/models/batch_line_item.rb | 23 +++-- app/views/batch_line_items/index.html.erb | 17 ++-- 7 files changed, 63 insertions(+), 78 deletions(-) diff --git a/.DS_Store b/.DS_Store index 14e19ca60f2161f114b770455578be31e3404d24..e926c64fdb8a34488c7b21942938544a2901df7e 100644 GIT binary patch delta 389 zcmZoMXfc=|#>B)qu~2NHo}vgF0|Nsi1A_oVa!yiyeh!eyz_#(@3dVYn1T#Y-LjglU zN->foLo!1?LmopKLncFdQh9MfQcivnQ0dd8f}G6a5(9%9j7-cdtZeKYoLnHt&lww> zkzXEMl2}q&?37p(4d!L0q$WYx0f{9UFm?#g1yFW)H0yzfW*Aiu*~Ajq|BVml1dIv5R4ZPudX&W*HJJu zHLcZAs5Un@&`~fkHmj}W;E+@|w)YOttDZb%>a^)IW^M-h1PB-z8H^w-K?nsWw*Xme z$U#sRT$GoSpO+34-#G6K%Vu^Cehy&hZv6P2c{0CCJ*u~2NHo}vf~0|Nsi1A_oVa!yiyeh!eyz&x=~Ll`8^%#g@Xz)+A< t43XPx&3uMs^91I(Oq)<`|I`%m7a(7xVxC diff --git a/app/assets/.DS_Store b/app/assets/.DS_Store index 6b56a5d51ea6b2853f6a23bd1fe41b5d59629618..5abf0cdff43543207d66c32d64def2e989516659 100644 GIT binary patch delta 18 acmZoMXfc>@d}50F#s`w@o7p-3@&f=$0S8+E delta 20 ccmZoMXfc>@oRM+kMKkt^4V;_VIsWnk08q>aX#fBK diff --git a/app/controllers/api/batch_line_items_controller.rb b/app/controllers/api/batch_line_items_controller.rb index ddf241a..c3d4c50 100644 --- a/app/controllers/api/batch_line_items_controller.rb +++ b/app/controllers/api/batch_line_items_controller.rb @@ -1,10 +1,9 @@ class Api::BatchLineItemsController < ApplicationController - skip_before_filter :verify_authenticity_token - def register + skip_before_filter :verify_authenticity_token + def register batch_id=params[:batch_id] session_token=params[:session_token] manufacture_uid = params[:card_manufacture] - # product_category_id=params[:product_category_id] client_id="" @@ -26,61 +25,36 @@ class Api::BatchLineItemsController < ApplicationController if !find_user.nil? encrypt_key=find_user.secrect_key location_code=find_user.location_code - # product_type=find_user.product_type + client_id=find_user.id if !encrypt_key.nil? - arr=Array.new - arr=BatchLineItem.get_array - - str_dup="" - str_wb="" - dup_count=0 - wb_count=0 - arr=arr.as_json - - arr.each do |item| - manufacture_uid=item - - check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid) - if check_manufacture.nil? - serial_no=BatchLineItem.generate_serial_no(client_id.to_s) + 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 ==1 - asset_identity=BatchLineItem.generate_account_no(location_code) - @out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,"") - elsif product_type==2 - str="manufacture_uid="+manufacture_uid.to_s+"&serial_no="+serial_no.to_s + if product_type ==1 #CARD + asset_identity=BatchLineItem.generate_account_no(location_code) + @out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,"") + elsif product_type==2 #TICKET + str="manufacture_uid="+manufacture_uid.to_s+"&serial_no="+serial_no.to_s - digest_data= Digest::MD5.hexdigest(str) - hex_data=digest_data.hex - hex_str=hex_data.to_s - asset_identity=hex_str[0..15] + digest_data= Digest::MD5.hexdigest(str) + hex_data=digest_data.hex + hex_str=hex_data.to_s + asset_identity=hex_str[0..15] - check_asset=BatchLineItem.find_by_asset_identity(asset_identity) - - if check_asset.nil? - @out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type) - else - @out=false,'Asset Identity is already registered!' - - str_wb=str_wb+asset_identity.to_s+"," - wb_count=wb_count+1 - end + check_asset=BatchLineItem.find_by_asset_identity(asset_identity) + + if check_asset.nil? + @out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type) + else + @out=false,'Asset Identity is already registered!' end - else - @out=false,'Manufacture UID is already registered!' - put @out - str_dup=str_dup+manufacture_uid.to_s+"," - dup_count=dup_count+1 - end - end - puts str_dup - puts dup_count - puts str_wb - puts wb_count - puts 'Asset Identity duplicat' + wb_count.to_s - puts 'Manufacture UID '+ dup_count.to_s + end + else + @out=false,'Manufacture UID is already registered!' + end else @out=false,'Invalid User!' end @@ -96,6 +70,5 @@ class Api::BatchLineItemsController < ApplicationController else @out=false,'Sorry!Unauthorized user!' end - end - + end end \ No newline at end of file diff --git a/app/controllers/api/batches_controller.rb b/app/controllers/api/batches_controller.rb index 0a73ce5..d759529 100644 --- a/app/controllers/api/batches_controller.rb +++ b/app/controllers/api/batches_controller.rb @@ -4,20 +4,21 @@ class Api::BatchesController < ApplicationController session_token=params[:session_token] check_member= Member.authenticate_session_token(session_token) if !check_member.nil? - date = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d") - created_by = params[:created_by] - order_ref = params[:order_ref] - card_qty = params[:card_qty] + date = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d") + order_ref = params[:order_ref] adult_or_child=params[:adult_or_child] client_id=params[:client_id] product_category_id=params[:product_category_id] + find_user=User.find_by_id(check_member.user_id) + created_by=find_user.name find_client=Client.find_by_id(client_id) if !find_client.nil? find_product_category=ProductCategory.find_by_id(product_category_id) if !find_product_category.nil? - user_id=check_member.user_id - batch = Batch.create_batch(created_by,date,order_ref,card_qty,user_id,adult_or_child,client_id,product_category_id) + user_id=check_member.user_id + + batch = Batch.create_batch(date,order_ref,user_id,created_by,adult_or_child,client_id,product_category_id) if !batch.nil? @out=true,batch.id else diff --git a/app/models/batch.rb b/app/models/batch.rb index eb85b04..9cb8307 100644 --- a/app/models/batch.rb +++ b/app/models/batch.rb @@ -1,14 +1,14 @@ class Batch < ApplicationRecord has_many :batch_line_item - - def self.create_batch(created_by,date,order_ref, card_qty,user_id,adult_or_child,client_id,product_category_id) + + def self.create_batch(date,order_ref,user_id,created_by,adult_or_child,client_id,product_category_id) batch = Batch.new - batch.created_by = created_by + batch.created_by=created_by batch.order_ref = order_ref batch.date = date batch.batch_start = true batch.batch_start_time=DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d") - batch.qty_processing = card_qty.to_i + batch.qty_processing = 0 batch.qty_success = 0 batch.qty_fail = 0 batch.user_id=user_id @@ -16,6 +16,7 @@ class Batch < ApplicationRecord batch.client_id=client_id batch.product_category_id=product_category_id batch.adult_or_child=adult_or_child.upcase + if batch.save return batch else diff --git a/app/models/batch_line_item.rb b/app/models/batch_line_item.rb index 2a354d5..7625958 100644 --- a/app/models/batch_line_item.rb +++ b/app/models/batch_line_item.rb @@ -53,11 +53,9 @@ class BatchLineItem < ApplicationRecord CSV.generate(headers: true) do |csv| csv << attributes all.each do |encoder| - if encoder.product_type_id ==1 - puts 'Card' + 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 - else - puts 'Tickets' + else str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s end @@ -96,20 +94,33 @@ class BatchLineItem < ApplicationRecord 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") + batch=Batch.find_by_id(batch_id) + 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 + + card_qty=batch.qty_processing.to_i + success_qty=batch.qty_success + + batch.qty_processing=card_qty+1 + batch.qty_success=success_qty+1 + batch.save @result = true,batchLineItem.serial_no,batchLineItem.asset_identity else - @result=false,'Error occurs in registration encoder!' + qty_fail=batch.qty_fail + batch.qty_fail=qty_fail+1 + batch.save + + @result=false,'Error occurs in registration encoder!' end end def self.get_array arr=Array.new - (1..50).each do |i| + (1..1000).each do |i| str= SecureRandom.hex uid=str[0..13] arr.push(uid) diff --git a/app/views/batch_line_items/index.html.erb b/app/views/batch_line_items/index.html.erb index 5581f33..1485160 100644 --- a/app/views/batch_line_items/index.html.erb +++ b/app/views/batch_line_items/index.html.erb @@ -41,14 +41,13 @@ - - - - - - - - + + + + + + + @@ -60,7 +59,7 @@ - + <% end %>
Serail NoAsset IdentityManufacture UIDBatch NoAsset TypeCreated At Update At Serail NoAsset IdentityManufacture UIDBatch NoAsset TypeCreated At Update At
<%= item.batch_name rescue '' %> <%= item.asset_type rescue '' %> <%= item.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %><%= item.updated_at.strftime("%e,%b %Y %I:%M %p") rescue '' %><%= item.updated_at.strftime("%e,%b %Y %I:%M %p") rescue '' %>