1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/app/views/exports/users_members.xlsx.axlsx

83 lines
3.5 KiB
Plaintext
Raw Normal View History

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
2023-03-20 14:57:15 +01:00
wb.add_worksheet(name: ExcelService.name_safe(t('export_members.members'))) do |sheet|
2016-07-12 12:48:26 +02:00
## data table
# heading labels
columns = [t('export_members.id'),
2023-02-03 12:50:18 +01:00
t('export_members.external_id'),
t('export_members.surname'),
t('export_members.first_name'),
t('export_members.email'),
t('export_members.newsletter'),
t('export_members.last_login'),
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'),
2023-02-03 12:50:18 +01:00
t('export_members.organization_address'),
t('export_members.note')]
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|
expiration = member&.subscription&.expired_at
2016-07-12 12:48:26 +02:00
data = [
2019-06-13 16:53:36 +02:00
member.id,
2023-02-03 12:50:18 +01:00
member.invoicing_profile.external_id || '',
2019-06-13 16:53:36 +02:00
member.profile.last_name,
member.profile.first_name,
member.email,
member.is_allow_newsletter,
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'),
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,
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 || '',
member.invoicing_profile&.organization&.name || '',
2023-02-03 12:50:18 +01:00
member.invoicing_profile&.organization&.address&.address || '',
ActionController::Base.helpers.sanitize(member.profile.note, tags: []) || ''
2016-07-12 12:48:26 +02:00
]
2023-02-03 12:50:18 +01:00
styles = [nil, nil, nil, nil, nil, nil, date, nil, nil, nil, nil, nil, nil, nil,
nil, nil, nil, date, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
2023-02-03 12:50:18 +01:00
types = %i[integer string string string string boolean date string integer string string string string string
string string string date string string integer string 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