2021-04-21 17:38:06 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-12 13:10:06 +02:00
|
|
|
wb = xlsx_package.workbook
|
|
|
|
|
2021-04-21 17:38:06 +02:00
|
|
|
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:10:06 +02:00
|
|
|
|
2023-03-20 14:57:15 +01:00
|
|
|
wb.add_worksheet(name: ExcelService.name_safe(t('export_subscriptions.subscriptions'))) do |sheet|
|
2016-07-12 13:10:06 +02:00
|
|
|
|
|
|
|
## data table
|
|
|
|
# heading labels
|
|
|
|
columns = [t('export_subscriptions.id'), t('export_subscriptions.customer'), t('export_subscriptions.email'),
|
|
|
|
t('export_subscriptions.subscription'), t('export_subscriptions.period'), t('export_subscriptions.start_date'),
|
2021-04-21 17:38:06 +02:00
|
|
|
t('export_subscriptions.expiration_date'), t('export_subscriptions.amount')]
|
|
|
|
sheet.add_row columns, style: header
|
2016-07-12 13:10:06 +02:00
|
|
|
|
|
|
|
# data rows
|
2023-02-24 17:26:55 +01:00
|
|
|
subscriptions.each do |sub|
|
2016-07-12 13:10:06 +02:00
|
|
|
data = [
|
2021-04-21 17:38:06 +02:00
|
|
|
sub.user&.id,
|
|
|
|
sub.user&.profile&.full_name || t('export_subscriptions.deleted_user'),
|
|
|
|
sub.user&.email,
|
|
|
|
sub.plan.human_readable_name(group: true),
|
|
|
|
t("duration.#{sub.plan.interval}", count: sub.plan.interval_count),
|
|
|
|
sub.created_at.to_date,
|
|
|
|
sub.expired_at.to_date,
|
|
|
|
number_to_currency(sub.plan.amount / 100.00)
|
2016-07-12 13:10:06 +02:00
|
|
|
]
|
|
|
|
styles = [nil, nil, nil, nil, nil, date, date, nil, nil]
|
2021-04-21 17:38:06 +02:00
|
|
|
types = %i[integer string string string string date date string string]
|
2016-07-12 13:10:06 +02:00
|
|
|
|
2021-04-21 17:38:06 +02:00
|
|
|
sheet.add_row data, style: styles, types: types
|
2016-07-12 13:10:06 +02:00
|
|
|
end
|
2021-04-21 17:38:06 +02:00
|
|
|
end
|