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

37 lines
1.6 KiB
Plaintext
Raw Normal View History

# frozen_string_literal: true
2016-07-12 13:00:56 +02:00
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
2016-07-12 13:00:56 +02:00
2023-03-20 14:57:15 +01:00
wb.add_worksheet(name: ExcelService.name_safe(t('export_reservations.reservations'))) do |sheet|
2016-07-12 13:00:56 +02:00
## 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'),
2022-09-05 11:39:23 +02:00
t('export_reservations.slots_number_hours_tickets'), t('export_reservations.payment_method'), t('export_reservations.coupon')]
sheet.add_row columns, style: header
2016-07-12 13:00:56 +02:00
# data rows
2023-02-24 17:26:55 +01:00
reservations.each do |resrv|
2022-09-05 11:39:23 +02:00
invoice = resrv.original_invoice
2016-07-12 13:00:56 +02:00
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,
2022-09-05 11:39:23 +02:00
invoice&.paid_by_card? ? t('export_reservations.online_payment') : t('export_reservations.local_payment'),
invoice&.coupon&.nil? ? '' : invoice&.coupon&.name
2016-07-12 13:00:56 +02:00
]
styles = [nil, nil, nil, date, nil, nil, nil, nil]
types = %i[integer string string date string string integer string]
2016-07-12 13:00:56 +02:00
sheet.add_row data, style: styles, types: types
2016-07-12 13:00:56 +02:00
end
end