2019-06-13 16:53:36 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-12 12:48:26 +02:00
|
|
|
wb = xlsx_package.workbook
|
|
|
|
|
2019-06-13 16:53:36 +02:00
|
|
|
header = wb.styles.add_style b: true, bg_color: Stylesheet.primary.upcase.gsub('#', 'FF'), fg_color: 'FFFFFFFF'
|
|
|
|
date = wb.styles.add_style format_code: Rails.application.secrets.excel_date_format
|
2016-07-12 12:48:26 +02:00
|
|
|
|
|
|
|
wb.add_worksheet(name: t('export_members.members')) do |sheet|
|
|
|
|
|
|
|
|
## data table
|
|
|
|
# heading labels
|
2016-11-16 15:08:24 +01:00
|
|
|
columns = [t('export_members.id'),
|
|
|
|
t('export_members.surname'),
|
|
|
|
t('export_members.first_name'),
|
|
|
|
t('export_members.email'),
|
|
|
|
t('export_members.newsletter'),
|
2019-10-29 11:09:17 +01:00
|
|
|
t('export_members.last_login'),
|
2016-11-16 15:08:24 +01:00
|
|
|
t('export_members.gender'),
|
|
|
|
t('export_members.age'),
|
|
|
|
t('export_members.address'),
|
|
|
|
t('export_members.phone'),
|
|
|
|
t('export_members.website'),
|
|
|
|
t('export_members.job'),
|
|
|
|
t('export_members.interests'),
|
|
|
|
t('export_members.cad_software_mastered'),
|
|
|
|
t('export_members.group'),
|
|
|
|
t('export_members.subscription'),
|
|
|
|
t('export_members.subscription_end_date'),
|
|
|
|
t('export_members.validated_trainings'),
|
|
|
|
t('export_members.tags'),
|
|
|
|
t('export_members.number_of_invoices'),
|
|
|
|
t('export_members.projects'),
|
|
|
|
t('export_members.facebook'),
|
|
|
|
t('export_members.twitter'),
|
|
|
|
t('export_members.echo_sciences'),
|
|
|
|
t('export_members.organization'),
|
|
|
|
t('export_members.organization_address')]
|
2019-06-13 16:53:36 +02:00
|
|
|
sheet.add_row columns, style: header
|
2016-07-12 12:48:26 +02:00
|
|
|
|
|
|
|
# data rows
|
|
|
|
@members.each do |member|
|
2019-07-10 11:27:45 +02:00
|
|
|
expiration = member&.subscription&.expired_at
|
2016-07-12 12:48:26 +02:00
|
|
|
data = [
|
2019-06-13 16:53:36 +02:00
|
|
|
member.id,
|
|
|
|
member.profile.last_name,
|
|
|
|
member.profile.first_name,
|
|
|
|
member.email,
|
|
|
|
member.is_allow_newsletter,
|
2019-10-29 11:09:17 +01:00
|
|
|
member.last_sign_in_at&.to_date,
|
2019-06-13 16:53:36 +02:00
|
|
|
member.statistic_profile.gender ? t('export_members.man') : t('export_members.woman'),
|
2019-07-10 11:27:45 +02:00
|
|
|
member.statistic_profile.age,
|
2019-06-13 16:53:36 +02:00
|
|
|
member.invoicing_profile&.address&.address || '',
|
|
|
|
member.profile.phone,
|
|
|
|
member.profile.website,
|
|
|
|
member.profile.job,
|
|
|
|
member.profile.interest,
|
|
|
|
member.profile.software_mastered,
|
|
|
|
member.group&.name,
|
2019-12-02 11:57:25 +01:00
|
|
|
expiration && DateTime.current < expiration ? member.subscription.plan.name : t('export_members.without_subscriptions'),
|
|
|
|
expiration && DateTime.current < expiration ? member.subscription.expired_at.to_date : nil,
|
2019-06-13 16:53:36 +02:00
|
|
|
member.trainings.map(&:name).join("\n"),
|
|
|
|
member.tags.map(&:name).join("\n"),
|
|
|
|
member.invoices.size,
|
|
|
|
member.projects.map(&:name).join("\n"),
|
|
|
|
member.profile.facebook || '',
|
|
|
|
member.profile.twitter || '',
|
|
|
|
member.profile.echosciences || '',
|
2019-07-10 11:27:45 +02:00
|
|
|
member.invoicing_profile&.organization&.name || '',
|
2019-06-13 16:53:36 +02:00
|
|
|
member.invoicing_profile&.organization&.address&.address || ''
|
2016-07-12 12:48:26 +02:00
|
|
|
]
|
2019-10-29 11:09:17 +01:00
|
|
|
styles = [nil, nil, nil, nil, nil, date, nil, nil, nil, nil, nil, nil, nil,
|
2019-06-13 16:53:36 +02:00
|
|
|
nil, nil, nil, date, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
|
2016-11-16 15:08:24 +01:00
|
|
|
|
2019-10-29 11:09:17 +01:00
|
|
|
types = %i[integer string string string boolean date string integer string string string string string
|
2019-07-10 11:27:45 +02:00
|
|
|
string string string date string string integer string string string string string string string]
|
2016-07-12 12:48:26 +02:00
|
|
|
|
2019-06-13 16:53:36 +02:00
|
|
|
sheet.add_row data, style: styles, types: types
|
2016-07-12 12:48:26 +02:00
|
|
|
end
|
|
|
|
end
|