diff --git a/app/.DS_Store b/app/.DS_Store index df9a612..6e41ebe 100644 Binary files a/app/.DS_Store and b/app/.DS_Store differ diff --git a/app/assets/.DS_Store b/app/assets/.DS_Store index aad3b52..6b56a5d 100644 Binary files a/app/assets/.DS_Store and b/app/assets/.DS_Store differ diff --git a/app/assets/stylesheets/style.css b/app/assets/stylesheets/style.css index ba9192a..93476cc 100644 --- a/app/assets/stylesheets/style.css +++ b/app/assets/stylesheets/style.css @@ -257,4 +257,7 @@ hr .container ul.nav>.nav-item:first-child{ padding-left: 80px; } +.show_image{ + padding-top: 30px; +} \ No newline at end of file diff --git a/app/controllers/api/batch_line_items_controller.rb b/app/controllers/api/batch_line_items_controller.rb index 6ca977f..686b4e3 100644 --- a/app/controllers/api/batch_line_items_controller.rb +++ b/app/controllers/api/batch_line_items_controller.rb @@ -8,9 +8,9 @@ class Api::BatchLineItemsController < ApplicationController client_id="" check_member= Member.authenticate_session_token(session_token) - if !check_member.nil? + if !check_member.nil? encrypt_key="" - wristband_code="" + asset_identity="" find_batch = Batch.find_by_id(batch_id) if !find_batch.nil? @@ -21,7 +21,7 @@ class Api::BatchLineItemsController < ApplicationController product_type=find_user.product_type client_id=find_user.id - if !encrypt_key.nil? + if !encrypt_key.nil? check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid) if check_manufacture.nil? serial_no=BatchLineItem.generate_serial_no(client_id.to_s) @@ -31,20 +31,20 @@ class Api::BatchLineItemsController < ApplicationController digest_data= Digest::MD5.hexdigest(str) hex_data=digest_data.hex hex_str=hex_data.to_s - wristband_code=hex_str[0..15] - check_wirstband=BatchLineItem.find_by_asset_identity(wristband_code) + asset_identity=hex_str[0..15] + check_asset=BatchLineItem.find_by_asset_identity(asset_identity) - if check_wirstband.nil? - @out=create_product(wristband_code,serial_no,batch_id,manufacture_uid,card_type) + if check_asset.nil? + @out=create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type) else - @out=false,'Wristband is already registered!' + @out=false,'Asset Identity is already registered!' end 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 else - @out=false,'Wristband is already registered!' - end + @out=false,'Manufacture UID is already registered!' + end else @out=false,'Invalid User!' end @@ -58,9 +58,9 @@ class Api::BatchLineItemsController < ApplicationController @out=false,'Sorry!Unauthorized user!' 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.asset_identity=wristband_code + batchLineItem.asset_identity=asset_identity batchLineItem.serial_no=serial_no batchLineItem.batch_id=batch_id batchLineItem.manufacture_uid = manufacture_uid diff --git a/app/controllers/api/batches_controller.rb b/app/controllers/api/batches_controller.rb index 6487039..24a52b1 100644 --- a/app/controllers/api/batches_controller.rb +++ b/app/controllers/api/batches_controller.rb @@ -11,18 +11,23 @@ class Api::BatchesController < ApplicationController adult_or_child=params[:adult_or_child] client_id=params[:client_id] - user_id=check_member.user_id - batch = Batch.create_batch(created_by,date,order_ref,card_qty,user_id,adult_or_child,client_id) - if !batch.nil? - @out=true,batch.id - else - @out=false,'Error occurs in creating batch!' - end - else - @out = false, "Sorry!Unauthorized user!" + find_client=Client.find_by_id(client_id) + if !find_client.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) + if !batch.nil? + @out=true,batch.id + else + @out=false,'Error occurs in creating batch!' + end + else + @out = false, "Client does not exist!" + end + else + @out = false, "Sorry!Unauthorized user!" end - end - def batch_end + end + def batch_end session_token=params[:session_token] batch_id=params[:batch_id] @@ -66,8 +71,7 @@ class Api::BatchesController < ApplicationController session_token=params[:session_token] 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 !created_by.nil? batches = Batch.where('batch_end is null and created_by=?', created_by) diff --git a/app/controllers/batch_line_items_controller.rb b/app/controllers/batch_line_items_controller.rb index 2c017cb..f0dba26 100644 --- a/app/controllers/batch_line_items_controller.rb +++ b/app/controllers/batch_line_items_controller.rb @@ -2,19 +2,47 @@ class BatchLineItemsController < ApplicationController require "csv" skip_before_filter :verify_authenticity_token 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 - - @clients=Client.all - - @batches=Batch.where('user_id=?',user_id) - @batchLineItems=BatchLineItem.joins('inner join 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]) + 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]).per(10) + else + sub_query="(select * from batches where user_id="+user_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]).per(10) + 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 client_id=params[:client_id] batches=Batch.where('client_id=?',client_id) @@ -27,25 +55,34 @@ class BatchLineItemsController < ApplicationController end def export batch_list="" - @batchLineItems="" + @batchLineItems=nil user_id=current_member.user_id @clients=Client.all @batches=Batch.where('user_id=?',user_id) + client_id=params[:client] if params[:batch].present? batch_list=params[:batch] end - client_id=params[:client] - + 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") - + 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| format.html 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 \ No newline at end of file diff --git a/app/models/batch_line_item.rb b/app/models/batch_line_item.rb index b2993b7..1c8758c 100644 --- a/app/models/batch_line_item.rb +++ b/app/models/batch_line_item.rb @@ -77,6 +77,7 @@ class BatchLineItem < ApplicationRecord return encrypted end + # def self.encrypted(data,encrypt_key) # crypt = ActiveSupport::MessageEncryptor.new(encrypt_key) # encrypted_data = crypt.encrypt_and_sign(data) diff --git a/app/models/member.rb b/app/models/member.rb index 5168826..b1034a7 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -12,7 +12,7 @@ class Member < ApplicationRecord else mem = Member.find_by_session_token(token) if mem.nil? - return false + return nil else return mem end diff --git a/app/views/batch_line_items/export.csv.erb b/app/views/batch_line_items/export.csv.erb deleted file mode 100644 index e69de29..0000000 diff --git a/app/views/batch_line_items/export.html.erb b/app/views/batch_line_items/export.html.erb deleted file mode 100644 index 5b765a4..0000000 --- a/app/views/batch_line_items/export.html.erb +++ /dev/null @@ -1,60 +0,0 @@ -
+