1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-05 16:24:21 +01:00
fab-manager/app/views/exports/users_reservations.xlsx.axlsx
Sylvain d942d46632 WIP: migration to object[]
TODO: fix running tests, fix front-end
2021-05-28 17:34:20 +02:00

35 lines
1.5 KiB
Plaintext

# frozen_string_literal: true
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_reservations.reservations')) do |sheet|
## data table
# heading labels
columns = [t('export_reservations.customer_id'), t('export_reservations.customer'), t('export_reservations.email'),
t('export_reservations.reservation_date'), t('export_reservations.reservation_type'), t('export_reservations.reservation_object'),
t('export_reservations.slots_number_hours_tickets'), t('export_reservations.payment_method')]
sheet.add_row columns, style: header
# data rows
@reservations.each do |resrv|
data = [
resrv.user&.id,
resrv.user&.profile&.full_name || t('export_reservations.deleted_user'),
resrv.user&.email,
resrv.created_at.to_date,
resrv.reservable_type,
resrv.reservable.nil? ? '' : resrv.reservable.name,
resrv.reservable_type == 'Event' ? resrv.total_booked_seats : resrv.slots.count,
resrv.original_invoice&.paid_by_card? ? t('export_reservations.online_payment') : t('export_reservations.local_payment')
]
styles = [nil, nil, nil, date, nil, nil, nil, nil]
types = %i[integer string string date string string integer string]
sheet.add_row data, style: styles, types: types
end
end