1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-12 01:52:24 +01:00
fab-manager/app/views/api/members/export_members.xlsx.axlsx
2016-07-12 12:48:26 +02:00

36 lines
1.6 KiB
Plaintext

wb = xlsx_package.workbook
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
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.gender'), t('export_members.age'), t('export_members.phone'), t('export_members.group'),
t('export_members.subscription'), t('export_members.subscription_end_date'), t('export_members.validated_trainings')]
sheet.add_row columns, :style => header
# data rows
@members.each do |member|
data = [
member.id,
member.profile.last_name,
member.profile.first_name,
member.email,
member.profile.gender ? t('export_members.man') : t('export_members.woman'),
member.profile.age,
member.profile.phone,
member.group.name,
(member.subscription and member.subscription.expired_at > Time.now) ? member.subscription.plan.name : t('export_members.without_subscriptions'),
(member.subscription and member.subscription.expired_at > Time.now) ? member.subscription.expired_at.to_date : nil,
member.trainings.map(&:name).join("\n")
]
styles = [nil, nil, nil, nil, nil, nil, nil, nil, nil, date, nil]
types = [:integer, :string, :string, :string, :string, :integer, :string, :string, :string, :date, :string]
sheet.add_row data, :style => styles, :types => types
end
end