2016-07-12 13:00:56 +02:00
|
|
|
wb = xlsx_package.workbook
|
|
|
|
|
2019-09-10 16:45:45 +02:00
|
|
|
header = wb.styles.add_style b: true, :bg_color => Stylesheet.primary.upcase.gsub('#', 'FF'), :fg_color => 'FFFFFFFF'
|
2016-07-12 13:00:56 +02:00
|
|
|
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')]
|
2019-09-10 16:45:45 +02:00
|
|
|
sheet.add_row columns, style: header
|
2016-07-12 13:00:56 +02:00
|
|
|
|
|
|
|
# data rows
|
|
|
|
@reservations.each do |resrv|
|
|
|
|
data = [
|
2020-07-21 17:25:19 +02:00
|
|
|
resrv.user&.id,
|
|
|
|
resrv.user&.profile&.full_name || t('export_reservations.deleted_user'),
|
|
|
|
resrv.user&.email,
|
2016-07-12 13:00:56 +02:00
|
|
|
resrv.created_at.to_date,
|
|
|
|
resrv.reservable_type,
|
|
|
|
(resrv.reservable.nil? ? '' : resrv.reservable.name),
|
2016-11-09 15:01:41 +01:00
|
|
|
(resrv.reservable_type == 'Event') ? resrv.total_booked_seats: resrv.slots.count,
|
2020-07-21 17:25:19 +02:00
|
|
|
(resrv.invoice&.paid_with_stripe?) ? t('export_reservations.online_payment') : t('export_reservations.local_payment')
|
2016-07-12 13:00:56 +02:00
|
|
|
]
|
|
|
|
styles = [nil, nil, nil, date, nil, nil, nil, nil]
|
|
|
|
types = [:integer, :string, :string, :date, :string, :string, :integer, :string]
|
|
|
|
|
2019-09-10 16:45:45 +02:00
|
|
|
sheet.add_row data, style: styles, types: types
|
2016-07-12 13:00:56 +02:00
|
|
|
end
|
2019-09-10 16:45:45 +02:00
|
|
|
end
|