This commit is contained in:
Sunandar
2017-02-10 17:25:12 +06:30
parent 9931152796
commit 723ad7462a
8 changed files with 39 additions and 29 deletions

View File

@@ -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")