p_product_ref search + filter ok
This commit is contained in:
parent
6b98b8f03c
commit
7b223648b8
@ -16,9 +16,15 @@ class Admin::PProductRefsController < ApplicationController
|
||||
|
||||
@p_product_refs = PProductRef.joins(:p_product)
|
||||
|
||||
@purchase_p_product_cats = PProductCat.where(:purchase => true).order(:name).all
|
||||
# @purchase_p_product_cats = PProductCat.where(:purchase => true).order(:name).all
|
||||
|
||||
global_search_ids = @p_product_refs.ids
|
||||
p_product_ref_cat_id_ids = @p_product_refs.ids
|
||||
s_brand_id_ids = @p_product_refs.ids
|
||||
|
||||
if params[:search][:global].to_s != ""
|
||||
global_search_ids = PProductRef.global_search(params[:search][:global]).ids
|
||||
end
|
||||
|
||||
if params[:search][:code].to_s != ""
|
||||
@p_product_refs = @p_product_refs.where("p_product_refs.ref LIKE ?","#{params[:search][:code]}%")
|
||||
@ -31,19 +37,27 @@ class Admin::PProductRefsController < ApplicationController
|
||||
|
||||
if params[:search][:p_product_ref_cat_id].to_s != ""
|
||||
if params[:search][:p_product_ref_cat_id].to_s == "null"
|
||||
@p_product_refs = @p_product_refs.where(:cc_p_product_cat_id => nil)
|
||||
# @p_product_refs = @p_product_refs.where(:cc_p_product_cat_id => nil)
|
||||
p_product_ref_cat_id_ids = @p_product_refs.where(:cc_p_product_cat_id => nil).ids
|
||||
else
|
||||
@p_product_refs = @p_product_refs.where(:cc_p_product_cat_id => params[:search][:p_product_ref_cat_id])
|
||||
# @p_product_refs = @p_product_refs.where(:cc_p_product_cat_id => params[:search][:p_product_ref_cat_id])
|
||||
p_product_ref_cat_id_ids = @p_product_refs.where(:cc_p_product_cat_id => params[:search][:p_product_ref_cat_id]).ids
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if params[:search][:s_brand_id].to_s != ""
|
||||
@p_product_refs = @p_product_refs.where(:p_products => {:s_brand_id => params[:search][:s_brand_id]})
|
||||
# @p_product_refs = @p_product_refs.where(:p_products => {:s_brand_id => params[:search][:s_brand_id]})
|
||||
# @p_product_refs = @p_product_refs.select { |ref| ref.p_product.s_brand_id == params[:search][:s_brand_id]}
|
||||
s_brand_id_ids = @p_product_refs.where(:p_products => {:s_brand_id => params[:search][:s_brand_id]}).ids
|
||||
end
|
||||
|
||||
if params[:search][:global].to_s != ""
|
||||
@p_product_refs = PProductRef.global_search(params[:search][:global])
|
||||
final_ids = global_search_ids & p_product_ref_cat_id_ids & s_brand_id_ids
|
||||
|
||||
if params[:search].present?
|
||||
@p_product_refs = PProductRef.where(id: final_ids)
|
||||
else
|
||||
@p_product_refs = PProductRef.joins(:p_product)
|
||||
end
|
||||
|
||||
@p_product_refs = sort_by_sorting(@p_product_refs, "id DESC")
|
||||
@ -110,7 +124,8 @@ class Admin::PProductRefsController < ApplicationController
|
||||
end
|
||||
|
||||
def autocomplete
|
||||
@p_product_refs = PProductRef.for_search(params[:search]).limit(50)
|
||||
@p_product_refs = PProductRef.joins(:p_product).all
|
||||
# @p_product_refs = PProductRef.for_search(params[:search]).limit(50)
|
||||
|
||||
if params[:p_customer_id]
|
||||
@p_customer = PCustomer.where(:id => params[:p_customer_id]).first
|
||||
|
@ -36,13 +36,20 @@
|
||||
%td
|
||||
Catégorie :
|
||||
%td
|
||||
.input-group
|
||||
=select_tag "search[p_product_ref_cat_id]", options_for_select([["",""],["Aucune","null"]]+PProductCat.order(:name).all.map{|a| [a.name, a.id]}, params[:search][:p_product_ref_cat_id]), class: "custom-select"
|
||||
.input-group-append{:onclick => "$(this).prev('select').val('').prop('selectedIndex',0);"}
|
||||
.btn.btn-outline-dark
|
||||
=ic(:times)
|
||||
|
||||
%td
|
||||
Marque :
|
||||
%td
|
||||
.input-group
|
||||
=select_tag "search[s_brand_id]", options_for_select([["",""]]+SBrand.order(:name).all.map{|a| [a.name, a.id]}, params[:search][:s_brand_id]), class: "custom-select"
|
||||
|
||||
.input-group-append{:onclick => "$(this).prev('select').val('').prop('selectedIndex',0);"}
|
||||
.btn.btn-outline-dark
|
||||
=ic(:times)
|
||||
|
||||
|
||||
=render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_product_refs}
|
||||
|
Reference in New Issue
Block a user