fonctions pour export des utilisateurs en CSV
This commit is contained in:
parent
fe24493d07
commit
647e71e8d6
@ -298,13 +298,83 @@ class Admin::PCustomersController < ApplicationController
|
|||||||
|
|
||||||
|
|
||||||
@p_customers = @p_customers.distinct
|
@p_customers = @p_customers.distinct
|
||||||
@p_customers = @p_customers.limit(50)
|
|
||||||
|
|
||||||
params[:per_page] = params[:per_page] || 50
|
|
||||||
|
|
||||||
per_page = params[:per_page]
|
|
||||||
page = (params[:page] and params[:page] != "") ? params[:page] : 1
|
|
||||||
@p_customers = @p_customers.page(page).per(per_page)
|
respond_to do |format|
|
||||||
|
format.html{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
params[:per_page] = params[:per_page] || 50
|
||||||
|
|
||||||
|
per_page = params[:per_page]
|
||||||
|
page = (params[:page] and params[:page] != "") ? params[:page] : 1
|
||||||
|
@p_customers = @p_customers.page(page).per(per_page)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
format.csv {
|
||||||
|
@headers = []
|
||||||
|
@columns = []
|
||||||
|
PCustomer.qi_table_order.each do |key, value|
|
||||||
|
|
||||||
|
if value.instance_of? Hash
|
||||||
|
name = value[:name]
|
||||||
|
else
|
||||||
|
name = value
|
||||||
|
end
|
||||||
|
|
||||||
|
if name != "Actions"
|
||||||
|
@headers << name.to_s
|
||||||
|
@columns << key
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@csv = CSV.generate(:headers => true, :col_sep => ";") do |csv|
|
||||||
|
csv << @headers
|
||||||
|
|
||||||
|
@p_customers.each do |p_customer|
|
||||||
|
line = []
|
||||||
|
|
||||||
|
@columns.each do |column|
|
||||||
|
|
||||||
|
if (p_customer.respond_to?("csv_"+column.to_s))
|
||||||
|
line << p_customer.send("csv_"+column.to_s)
|
||||||
|
elsif (p_customer.respond_to?(column))
|
||||||
|
if p_customer.send(column.to_s).class.to_s == "BigDecimal"
|
||||||
|
line << p_customer.send(column.to_s).to_s.gsub('.', ',')
|
||||||
|
else
|
||||||
|
line << p_customer.send(column.to_s)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
line << column.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
csv << line
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@data_to_send = @csv
|
||||||
|
|
||||||
|
send_data @data_to_send, :filename => "export-csv.csv" #, :type => 'text/csv; charset=iso-8859-1; header=present'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
|
|||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
|
|
||||||
|
|
||||||
|
require "csv"
|
||||||
|
|
||||||
before_action :set_locale
|
before_action :set_locale
|
||||||
|
|
||||||
|
@ -255,8 +255,17 @@ class PCustomer < ApplicationRecord
|
|||||||
:cc_show_name => {:name => "Nom", :reorder => true},
|
:cc_show_name => {:name => "Nom", :reorder => true},
|
||||||
:mlm_token => {:name => "Code ambassadeur", :reorder => true},
|
:mlm_token => {:name => "Code ambassadeur", :reorder => true},
|
||||||
:enabled => "Actif ?",
|
:enabled => "Actif ?",
|
||||||
|
:test_user => "Utilisateur test ?",
|
||||||
:parent => "Ambassadeur",
|
:parent => "Ambassadeur",
|
||||||
:particular => "Ville",
|
|
||||||
|
|
||||||
|
|
||||||
|
:particular_cp => "Code postal",
|
||||||
|
:particular_city => "Ville",
|
||||||
|
:particular_country => "Pays",
|
||||||
|
|
||||||
|
:email => "Email",
|
||||||
|
:tel => "Téléphone",
|
||||||
:actions => "Actions"
|
:actions => "Actions"
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -550,4 +559,38 @@ class PCustomer < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def csv_parent
|
||||||
|
if self.parent
|
||||||
|
self.parent.mlm_token.to_s+" - "+self.show_name.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def csv_mlm_token
|
||||||
|
self.mlm_token if self.ambassadeur
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def csv_tel
|
||||||
|
self.particular.tel if self.particular
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def csv_particular_cp
|
||||||
|
self.particular.cp if self.particular
|
||||||
|
end
|
||||||
|
|
||||||
|
def csv_particular_city
|
||||||
|
self.particular.city if self.particular
|
||||||
|
end
|
||||||
|
|
||||||
|
def csv_particular_country
|
||||||
|
self.particular.country if self.particular
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,11 @@
|
|||||||
-if p_customer.enabled
|
-if p_customer.enabled
|
||||||
Oui
|
Oui
|
||||||
|
|
||||||
|
-tr[:test_user] = capture do
|
||||||
|
%td
|
||||||
|
-if p_customer.test_user
|
||||||
|
Oui
|
||||||
|
|
||||||
-tr[:parent] = capture do
|
-tr[:parent] = capture do
|
||||||
%td
|
%td
|
||||||
-if p_customer.parent
|
-if p_customer.parent
|
||||||
@ -19,6 +24,12 @@
|
|||||||
=p_customer.mlm_token
|
=p_customer.mlm_token
|
||||||
|
|
||||||
|
|
||||||
|
-tr[:tel] = capture do
|
||||||
|
%td
|
||||||
|
-if p_customer.particular
|
||||||
|
=p_customer.particular.tel
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-tr[:p_commercial] = capture do
|
-tr[:p_commercial] = capture do
|
||||||
%td
|
%td
|
||||||
@ -27,12 +38,26 @@
|
|||||||
-tr[:p_customer_cat] = capture do
|
-tr[:p_customer_cat] = capture do
|
||||||
%td= p_customer.p_customer_cat.name if p_customer.p_customer_cat
|
%td= p_customer.p_customer_cat.name if p_customer.p_customer_cat
|
||||||
|
|
||||||
-tr[:particular] = capture do
|
-tr[:particular_country] = capture do
|
||||||
|
%td
|
||||||
|
-if p_customer.particular
|
||||||
|
= p_customer.particular.country
|
||||||
|
|
||||||
|
-tr[:particular_cp] = capture do
|
||||||
%td
|
%td
|
||||||
-if p_customer.particular
|
-if p_customer.particular
|
||||||
= p_customer.particular.cp
|
= p_customer.particular.cp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-tr[:particular_city] = capture do
|
||||||
|
%td
|
||||||
|
-if p_customer.particular
|
||||||
= p_customer.particular.city
|
= p_customer.particular.city
|
||||||
= p_customer.particular.country
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-tr[:actions] = capture do
|
-tr[:actions] = capture do
|
||||||
%td.actions
|
%td.actions
|
||||||
|
@ -113,16 +113,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
=link_to ic(:search)+" Rechercher", "#", :class => "btn btn-default btn-qi-search", :onclick => "$(this).closest('form').submit();$(this).html('...');return false;"
|
|
||||||
|
|
||||||
|
=render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_customers, :csv => true}
|
||||||
.results_count
|
|
||||||
="(#{@p_customers.total_count}) résultat(s)"
|
|
||||||
|
|
||||||
="-"
|
|
||||||
|
|
||||||
=select_tag "search[per_page]", options_for_select([50,100,200,500], params[:search][:per_page])
|
|
||||||
résultats par page
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
=hidden_field_tag :column, params[:column]
|
=hidden_field_tag :column, params[:column]
|
||||||
=hidden_field_tag :direction, params[:direction]
|
=hidden_field_tag :direction, params[:direction]
|
||||||
|
|
||||||
|
|
||||||
=link_to ic(:search)+" Rechercher", "#", :class => "btn btn-default btn-qi-search", :onclick => "$(this).closest('form').submit();$(this).html('...');return false;"
|
=link_to ic(:search)+" Rechercher", "#", :class => "btn btn-default btn-qi-search", :onclick => "$(this).closest('form').submit();$(this).html('...');return false;"
|
||||||
|
|
||||||
|
|
||||||
@ -11,3 +12,7 @@
|
|||||||
|
|
||||||
=select_tag "search[per_page]", options_for_select([50,100,200,500], params[:search][:per_page])
|
=select_tag "search[per_page]", options_for_select([50,100,200,500], params[:search][:per_page])
|
||||||
résultats par page
|
résultats par page
|
||||||
|
|
||||||
|
-if csv = csv || nil and csv
|
||||||
|
="-"
|
||||||
|
=link_to "export csv", params.permit!.merge(:format => :csv)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user