1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-30 11:24:21 +01:00
fab-manager/app/views/exports/users_reservations.xlsx.axlsx

33 lines
1.4 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_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,
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.invoice.paid_with_stripe?) ? t('export_reservations.local_payment') : t('export_reservations.online_payment')
]
styles = [nil, nil, nil, date, nil, nil, nil, nil]
types = [:integer, :string, :string, :date, :string, :string, :integer, :string]
sheet.add_row data, style: styles, types: types
end
end