From 0c53f506e7558e5c96ed90d0c18e63f3487d0f1d Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Wed, 22 Jul 2020 10:04:40 +0200 Subject: [PATCH] suite --- app/controllers/admin/p_customers_controller.rb | 17 +++++++++++++++++ app/models/p_customer.rb | 12 ++++++++++-- .../admin/p_customers/_p_customer.html.haml | 11 +++++++++++ app/views/admin/p_customers/index.html.haml | 7 +++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/p_customers_controller.rb b/app/controllers/admin/p_customers_controller.rb index 038f577..a45ac4d 100644 --- a/app/controllers/admin/p_customers_controller.rb +++ b/app/controllers/admin/p_customers_controller.rb @@ -197,6 +197,23 @@ class Admin::PCustomersController < ApplicationController @fav_p_customers = PCustomer.where(:fav => true).order(:name).all + + #params[:search][:enabled] = "Oui" if !params[:search][:enabled] + + if params[:search][:enabled].to_s == "Oui" + @p_customers = @p_customers.where(:enabled => true) + elsif params[:search][:enabled].to_s == "Non" + @p_customers = @p_customers.where(:enabled => false) + end + + params[:search][:test_user] = "Non" if !params[:search][:test_user] + + if params[:search][:test_user].to_s == "Oui" + @p_customers = @p_customers.where(:test_user => true) + elsif params[:search][:test_user].to_s == "Non" + @p_customers = @p_customers.where(:test_user => false) + end + if params[:code].to_s != "" @p_customers = @p_customers.where("p_customers.code LIKE ?","#{params[:code]}%") diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index c0b3627..a9cf34e 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -252,7 +252,8 @@ class PCustomer < ApplicationRecord def self.qi_table_order { :created_at => {:name => "Date de création", :reorder => true, :as => :date}, - :cc_show_name => {:name => "Nom", :reorder => true}, + :name => {:name => "Nom", :reorder => true, :sort_name => "particulars.name"}, + :firstname => {:name => "Prénom", :reorder => true, :sort_name => "particulars.firstname"}, :mlm_token => {:name => "Code ambassadeur", :reorder => true}, :enabled => "Actif ?", :test_user => "Utilisateur test ?", @@ -274,7 +275,7 @@ class PCustomer < ApplicationRecord def self.valid_sort - ["code", "cc_show_name", "created_at", "cache_encours_th", "cache_encours", "cache_payments_th", "cache_payments", "cache_payments_tot", "cache_ca"] + ["code", "cc_show_name","particulars.firstname","particulars.name", "created_at", "cache_encours_th", "cache_encours", "cache_payments_th", "cache_payments", "cache_payments_tot", "cache_ca"] end @@ -577,6 +578,13 @@ class PCustomer < ApplicationRecord self.particular.tel if self.particular end + def csv_name + self.particular.name if self.particular + end + + def csv_firstname + self.particular.firstname if self.particular + end def csv_particular_cp self.particular.cp if self.particular diff --git a/app/views/admin/p_customers/_p_customer.html.haml b/app/views/admin/p_customers/_p_customer.html.haml index b73f2e8..28b2fcb 100644 --- a/app/views/admin/p_customers/_p_customer.html.haml +++ b/app/views/admin/p_customers/_p_customer.html.haml @@ -56,6 +56,17 @@ = p_customer.particular.city + -tr[:name] = capture do + %td + -if p_customer.particular + = p_customer.particular.name + + + -tr[:firstname] = capture do + %td + -if p_customer.particular + = p_customer.particular.firstname + diff --git a/app/views/admin/p_customers/index.html.haml b/app/views/admin/p_customers/index.html.haml index 3ddee93..ef64068 100644 --- a/app/views/admin/p_customers/index.html.haml +++ b/app/views/admin/p_customers/index.html.haml @@ -50,6 +50,13 @@ %table %tr + %td + Actif : + =select_tag "search[enabled]", options_for_select([[""], "Oui", "Non"], params[:search][:enabled]) + + %td + Utilisateur test ? + =select_tag "search[test_user]", options_for_select([[""], "Oui", "Non"], params[:search][:test_user]) %td Catégorie :