isp_condition = []
report_date_condition = []
other_conditions = []
if params[:q].present?
# Filttering record from date wise.
if params[:q][:report_date_gteq].present? && params[:q][:report_date_lteq].present?
report_date_condition = ['report_date >= ? and report_date <= ?', params[:q][:report_date_gteq], params[:q][:report_date_lteq]]
end
# Filters for isp and other controls for fetching record.
params[:q].each do |k,v|
next if k.include?("report_date")
if k.include?("isp")
condition = k.split("_").last
case condition
when "contains"
isp_condition = ['isp like ?', "%"+v+"%"]
when "equals"
isp_condition = ['isp = ?', v]
when "starts_with"
isp_condition = ['isp like ?', v+"%"]
when "ends_with"
isp_condition = ['isp like ?', "%"+v]
end
next
end
if k.include?("equals")
param_name = k.split('_equals').first
other_conditions << ["#{param_name} = ?", v]
elsif k.include?("greater_than")
param_name = k.split('_greater_than').first
other_conditions << ["#{param_name} > ?", v]
elsif k.include?("less_than")
param_name = k.split('_less_than').first
other_conditions << ["#{param_name} < ?", v]
end
end
end
report_date_condition = []
other_conditions = []
if params[:q].present?
# Filttering record from date wise.
if params[:q][:report_date_gteq].present? && params[:q][:report_date_lteq].present?
report_date_condition = ['report_date >= ? and report_date <= ?', params[:q][:report_date_gteq], params[:q][:report_date_lteq]]
end
# Filters for isp and other controls for fetching record.
params[:q].each do |k,v|
next if k.include?("report_date")
if k.include?("isp")
condition = k.split("_").last
case condition
when "contains"
isp_condition = ['isp like ?', "%"+v+"%"]
when "equals"
isp_condition = ['isp = ?', v]
when "starts_with"
isp_condition = ['isp like ?', v+"%"]
when "ends_with"
isp_condition = ['isp like ?', "%"+v]
end
next
end
if k.include?("equals")
param_name = k.split('_equals').first
other_conditions << ["#{param_name} = ?", v]
elsif k.include?("greater_than")
param_name = k.split('_greater_than').first
other_conditions << ["#{param_name} > ?", v]
elsif k.include?("less_than")
param_name = k.split('_less_than').first
other_conditions << ["#{param_name} < ?", v]
end
end
end
No comments:
Post a Comment