mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-11 22:24:21 +01:00
48 lines
1.9 KiB
Plaintext
48 lines
1.9 KiB
Plaintext
# frozen_string_literal: true
|
|
|
|
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
|
|
|
|
indices.each do |index|
|
|
next unless index.table
|
|
|
|
index.statistic_types.each do |type|
|
|
wb.add_worksheet(name: ExcelService.statistic_type_sheet_name(type, wb)) do |sheet|
|
|
## data table
|
|
# heading labels
|
|
columns = [t('export.date'), t('export.user'), t('export.email'), t('export.phone'), t('export.gender'), t('export.age'),
|
|
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.revenue') if index.ca
|
|
sheet.add_row columns, style: header
|
|
|
|
# data rows
|
|
results['hits']['hits'].each do |hit|
|
|
# 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
|
|
|
|
# get matching objects
|
|
user = get_item(users, hit['_source']['userId'])
|
|
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)
|
|
end
|
|
add_hardcoded_cells(index, hit, data, styles, types)
|
|
# proceed the 'ca' field if requested
|
|
add_ca_cell(index, hit, data, styles, types)
|
|
|
|
# finally, add the data row to the workbook's sheet
|
|
sheet.add_row data, style: styles, types: types
|
|
end
|
|
end
|
|
end
|
|
end
|