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

52 lines
2.2 KiB
Plaintext
Raw Normal View History

2022-12-01 13:03:19 +01:00
# frozen_string_literal: true
2016-07-12 12:03:38 +02:00
wb = xlsx_package.workbook
2022-12-01 13:03:19 +01: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 12:03:38 +02:00
2023-02-24 17:26:55 +01:00
indices.each do |index|
2022-12-01 13:03:19 +01:00
next unless index.table
2016-07-12 12:03:38 +02:00
2022-12-01 13:03:19 +01:00
index.statistic_types.each do |type|
2023-03-20 14:57:15 +01:00
wb.add_worksheet(name: ExcelService.statistic_type_sheet_name(type, wb)) do |sheet|
2022-12-01 13:03:19 +01:00
## data table
# heading labels
2023-09-01 12:43:36 +02:00
user_heading_text = index.es_type_key == "project" ? t('export.project_author') : t('export.user')
columns = [t('export.date'), user_heading_text, t('export.email'), t('export.phone'), t('export.gender'), t('export.age'),
2022-12-01 13:03:19 +01:00
t('export.type')]
columns.push type.label unless type.simple
index.statistic_fields.each do |f|
columns.push f.label
end
columns.push t('export.reservation_context') if index.concerned_by_reservation_context?
2022-12-01 13:03:19 +01:00
columns.push t('export.revenue') if index.ca
columns.push t('export.coupon') if index.show_coupon?
2022-12-01 13:03:19 +01:00
sheet.add_row columns, style: header
2016-07-12 12:03:38 +02:00
2022-12-01 13:03:19 +01:00
# data rows
2023-02-24 17:26:55 +01:00
results['hits']['hits'].each do |hit|
2022-12-01 13:03:19 +01:00
# check that the current result is for the given index and type
next unless hit['_type'] == index.es_type_key && hit['_source']['type'] == type.key
2016-07-12 12:03:38 +02:00
2022-12-01 13:03:19 +01:00
# get matching objects
2023-02-24 17:26:55 +01:00
user = get_item(users, hit['_source']['userId'])
2022-12-01 13:03:19 +01:00
subtype = get_item(type.statistic_sub_types, hit['_source']['subType'], 'key')
# start to fill data and associated styles and data-types
data, styles, types = statistics_line(hit, user, type, subtype, date)
# proceed additional fields
index.statistic_fields.each do |f|
format_xlsx_cell(hit['_source'][f.key], data, styles, types, source_data_type: f.data_type, date_format: date)
2016-07-12 12:03:38 +02:00
end
2023-07-20 16:55:22 +02:00
add_hardcoded_cells(index, hit, data, styles, types)
2022-12-01 13:03:19 +01:00
# proceed the 'ca' field if requested
add_ca_cell(index, hit, data, styles, types)
add_coupon_cell(index, hit, data, styles, types)
2022-12-01 13:03:19 +01:00
# finally, add the data row to the workbook's sheet
sheet.add_row data, style: styles, types: types
2016-07-12 12:03:38 +02:00
end
end
end
2022-12-01 13:03:19 +01:00
end