From 723ad7462a27b1084a60794fae4f97299ca4a368 Mon Sep 17 00:00:00 2001 From: Sunandar Date: Fri, 10 Feb 2017 17:25:12 +0630 Subject: [PATCH] edit --- app/assets/stylesheets/style.css | 6 +++++ app/controllers/api/batches_controller.rb | 14 +++++----- .../batch_line_items_controller.rb | 27 ++++++++++--------- app/models/batch.rb | 4 +-- app/models/batch_line_item.rb | 2 +- app/views/batch_line_items/index.html.erb | 5 ++-- app/views/batches/index.html.erb | 6 +++-- db/schema.rb | 4 +-- 8 files changed, 39 insertions(+), 29 deletions(-) diff --git a/app/assets/stylesheets/style.css b/app/assets/stylesheets/style.css index 93476cc..e53e963 100644 --- a/app/assets/stylesheets/style.css +++ b/app/assets/stylesheets/style.css @@ -260,4 +260,10 @@ hr .show_image{ padding-top: 30px; } +.multiselect-container{ + width: 250px; +} +.ul.multiselect-container > li> a> label{ + padding-left: 10px; +} \ No newline at end of file diff --git a/app/controllers/api/batches_controller.rb b/app/controllers/api/batches_controller.rb index d759529..457ae3b 100644 --- a/app/controllers/api/batches_controller.rb +++ b/app/controllers/api/batches_controller.rb @@ -10,15 +10,13 @@ class Api::BatchesController < ApplicationController 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(date,order_ref,user_id,created_by,adult_or_child,client_id,product_category_id) + batch = Batch.create_batch(date,order_ref,user_id,adult_or_child,client_id,product_category_id) if !batch.nil? @out=true,batch.id else @@ -76,16 +74,16 @@ class Api::BatchesController < ApplicationController end def batch_progress_list session_token=params[:session_token] - created_by=params[:created_by] + user_id=params[:created_by] 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) - if !batches.blank? + if !user_id.nil? + batches = Batch.where('batch_end is null and user_id=?', user_id) + if !batches.empty? @out=true,batches else - @out = false, "No Batch" + @out = false, batches end else @out = false, "Sorry!Unauthorized user!" diff --git a/app/controllers/batch_line_items_controller.rb b/app/controllers/batch_line_items_controller.rb index a8937fb..1f1917c 100644 --- a/app/controllers/batch_line_items_controller.rb +++ b/app/controllers/batch_line_items_controller.rb @@ -5,36 +5,35 @@ class BatchLineItemsController < ApplicationController def index - user_id=current_member.user_id + # user_id=current_member.user_id @clients=Client.all.order('id asc') find_client=Client.select(:id).order('id asc').first if !find_client.nil? client_id=find_client.id - sub_query="(select * from batches where user_id="+user_id.to_s+" and client_id="+client_id.to_s+")" + sub_query="(select * from batches where 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').order('batch_line_items.id desc').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') + else + @batchLineItems=BatchLineItem.joins('inner join batches on batches.id=batch_line_items.batch_id') .select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10) end end def search - user_id=current_member.user_id + # 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+")" + sub_query="(select * from batches where id in ("+batch_list+") 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').order('batch_line_items.id desc').page(params[:page]).per(10) else - sub_query="(select * from batches where user_id="+user_id.to_s+" and client_id="+client_id.to_s+")" + sub_query="(select * from batches where 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').order('batch_line_items.id desc').page(params[:page]).per(10) @@ -65,23 +64,27 @@ class BatchLineItemsController < ApplicationController find_client=Client.find_by_id(client_id) location_code=find_client.location_code + find_user=User.find_by_id(user_id) + if !find_user.nil? + exported_by=find_user.name + end if params[:batch].present? batch_list=params[:batch] end if !batch_list.empty? - res=Batch.where("client_id=? and id in (?)",client_id,batch_list).update_all("export_count = export_count + 1") + res=Batch.where("client_id=? and id in (?)",client_id,batch_list).update_all("export_count = export_count + 1,exported_by='"+exported_by+"'") # sub_query=Batch.where('id in (?)',batch_list).select('*').to_sql - sub_query= "(select * from batches where user_id="+user_id.to_s+" and client_id="+client_id.to_s+")" + sub_query= "(select * from batches where client_id="+client_id.to_s+")" @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') .where('batch_id in (?)',batch_list) .select("*,product.product_type_id ,product.name,'' as secret_token,'' as location") 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+")" + 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+")" @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') .select("*,product.product_type_id ,product.name,'' as secret_token,'' as location") diff --git a/app/models/batch.rb b/app/models/batch.rb index 9cb8307..61da858 100644 --- a/app/models/batch.rb +++ b/app/models/batch.rb @@ -1,9 +1,9 @@ class Batch < ApplicationRecord has_many :batch_line_item - def self.create_batch(date,order_ref,user_id,created_by,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.created_by=created_by + batch.exported_by="" batch.order_ref = order_ref batch.date = date batch.batch_start = true diff --git a/app/models/batch_line_item.rb b/app/models/batch_line_item.rb index 7625958..d6eda8b 100644 --- a/app/models/batch_line_item.rb +++ b/app/models/batch_line_item.rb @@ -120,7 +120,7 @@ class BatchLineItem < ApplicationRecord end def self.get_array arr=Array.new - (1..1000).each do |i| + (1..100).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 1485160..75b9032 100644 --- a/app/views/batch_line_items/index.html.erb +++ b/app/views/batch_line_items/index.html.erb @@ -79,7 +79,7 @@ $(document).ready(function(){ client_id=$(this).val() get_batch(client_id) }); - function get_batch(client_id){ + function get_batch(client_id){ $('#batch').multiselect('disable'); $.ajax({ type: "GET", @@ -110,7 +110,7 @@ $(document).ready(function(){ filter(client,batch); }); - function filter(client,batch){ + function filter(client,batch){ if (batch==null){ batch="" } @@ -130,6 +130,7 @@ $(document).ready(function(){ } }); } + $("ul.multiselect-container > li> a > label").attr("style","padding-left:10px"); }) \ No newline at end of file diff --git a/app/views/batches/index.html.erb b/app/views/batches/index.html.erb index 717cf91..45d9453 100644 --- a/app/views/batches/index.html.erb +++ b/app/views/batches/index.html.erb @@ -18,7 +18,8 @@ Qty Processing Qty Success Qty Fail - Export Count + Export Count + Exported By Creatd At @@ -30,7 +31,8 @@ <%= batch.qty_processing rescue '' %> <%= batch.qty_success rescue '' %> <%= batch.qty_fail rescue '' %> - <%= batch.export_count %> + <%= batch.export_count %> + <%= batch.exported_by %> <%= batch.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %> <% end %> diff --git a/db/schema.rb b/db/schema.rb index d30c891..140480b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170209102414) do +ActiveRecord::Schema.define(version: 20170210103359) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -35,7 +35,7 @@ ActiveRecord::Schema.define(version: 20170209102414) do t.string "order_ref", null: false t.boolean "batch_start" t.boolean "batch_end" - t.string "created_by", null: false + t.string "exported_by", null: false t.integer "qty_processing", null: false t.integer "qty_success", null: false t.integer "qty_fail", null: false