p_product_ref search + filter ok

This commit is contained in:
Barnabé 2021-09-29 15:45:28 +02:00
parent 6b98b8f03c
commit 7b223648b8
2 changed files with 34 additions and 12 deletions

View File

@ -16,9 +16,15 @@ class Admin::PProductRefsController < ApplicationController
@p_product_refs = PProductRef.joins(:p_product) @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 != "" if params[:search][:code].to_s != ""
@p_product_refs = @p_product_refs.where("p_product_refs.ref LIKE ?","#{params[:search][:code]}%") @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 != ""
if params[:search][:p_product_ref_cat_id].to_s == "null" 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 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
end end
if params[:search][:s_brand_id].to_s != "" 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 end
if params[:search][:global].to_s != "" final_ids = global_search_ids & p_product_ref_cat_id_ids & s_brand_id_ids
@p_product_refs = PProductRef.global_search(params[:search][:global])
if params[:search].present?
@p_product_refs = PProductRef.where(id: final_ids)
else
@p_product_refs = PProductRef.joins(:p_product)
end end
@p_product_refs = sort_by_sorting(@p_product_refs, "id DESC") @p_product_refs = sort_by_sorting(@p_product_refs, "id DESC")
@ -110,7 +124,8 @@ class Admin::PProductRefsController < ApplicationController
end end
def autocomplete 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] if params[:p_customer_id]
@p_customer = PCustomer.where(:id => params[:p_customer_id]).first @p_customer = PCustomer.where(:id => params[:p_customer_id]).first

View File

@ -36,13 +36,20 @@
%td %td
Catégorie : Catégorie :
%td %td
=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
=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 %td
Marque : Marque :
%td %td
=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
=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} =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_product_refs}