add new field

This commit is contained in:
Sunandar
2017-02-09 18:01:50 +06:30
parent 9dc6fd3cbe
commit 07477f1a06
7 changed files with 132 additions and 91 deletions

View File

@@ -13,15 +13,14 @@ class BatchLineItemsController < ApplicationController
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)
.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')
.select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page]).per(10)
.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
batch_list=params[:batch]
client_id=params[:client]
@@ -32,12 +31,12 @@ class BatchLineItemsController < ApplicationController
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])
.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+")"
@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])
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
end
@@ -71,12 +70,21 @@ class BatchLineItemsController < ApplicationController
end
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,'' as location")
res=Batch.where("client_id=? and id in (?)",client_id,batch_list).update_all("export_count = export_count + 1")
# 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+")"
@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+")"
@batchLineItems = BatchLineItem.joins('inner join '+sub_query+' as batches on batches.id=batch_line_items.batch_id').select("*,'' as secret_token,'' as location")
@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")
end
if !@batchLineItems.empty?