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

80 lines
3.2 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
wb.add_worksheet(name: t('export_members.members')) do |sheet|
## data table
# heading labels
columns = [t('export_members.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'),
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|
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,
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 && Time.now < expiration ? member.subscription.plan.name : t('export_members.without_subscriptions'),
expiration && Time.now < 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 || '',
2019-06-13 16:53:36 +02:00
member.invoicing_profile&.organization&.address&.address || ''
2016-07-12 12:48:26 +02: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]
types = %i[integer 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]
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