2019-06-13 16:53:36 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-27 17:00:06 +02:00
|
|
|
require 'abstract_controller'
|
|
|
|
require 'action_controller'
|
|
|
|
require 'action_view'
|
|
|
|
require 'active_record'
|
|
|
|
|
|
|
|
# require any helpers
|
|
|
|
require './app/helpers/application_helper'
|
|
|
|
|
2019-06-13 16:53:36 +02:00
|
|
|
# There routines will generate Excel files containing data dumped from database
|
2016-07-27 17:00:06 +02:00
|
|
|
class UsersExportService
|
|
|
|
# export subscriptions
|
|
|
|
def export_subscriptions(export)
|
2019-07-10 12:25:08 +02:00
|
|
|
@subscriptions = Subscription.all.includes(:plan, statistic_profile: [user: [:profile]])
|
2016-07-27 17:00:06 +02:00
|
|
|
|
2023-02-24 17:26:55 +01:00
|
|
|
content = ApplicationController.render(
|
|
|
|
template: 'exports/users_subscriptions',
|
|
|
|
locals: { subscriptions: @subscriptions },
|
|
|
|
handlers: [:axlsx],
|
|
|
|
formats: [:xlsx]
|
|
|
|
)
|
2016-07-27 17:00:06 +02:00
|
|
|
# write content to file
|
2023-02-24 17:26:55 +01:00
|
|
|
File.binwrite(export.file, content)
|
2016-07-27 17:00:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# export reservations
|
|
|
|
def export_reservations(export)
|
2021-05-28 17:34:20 +02:00
|
|
|
@reservations = Reservation.all.includes(:slots, :reservable, statistic_profile: [user: [:profile]])
|
2016-07-27 17:00:06 +02:00
|
|
|
|
2023-02-24 17:26:55 +01:00
|
|
|
content = ApplicationController.render(
|
|
|
|
template: 'exports/users_reservations',
|
|
|
|
locals: { reservations: @reservations },
|
|
|
|
handlers: [:axlsx],
|
|
|
|
formats: [:xlsx]
|
|
|
|
)
|
2016-07-27 17:00:06 +02:00
|
|
|
# write content to file
|
2023-02-24 17:26:55 +01:00
|
|
|
File.binwrite(export.file, content)
|
2016-07-27 17:00:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# export members
|
|
|
|
def export_members(export)
|
2020-01-14 14:33:00 +01:00
|
|
|
@members = User.members
|
2019-07-10 11:27:45 +02:00
|
|
|
.includes(:group, :tags, :projects, :profile,
|
2023-02-24 17:26:55 +01:00
|
|
|
invoicing_profile: [:invoices, :address, { organization: [:address] }],
|
|
|
|
statistic_profile: [:trainings, { subscriptions: [:plan] }])
|
|
|
|
|
|
|
|
content = ApplicationController.render(
|
|
|
|
template: 'exports/users_members',
|
|
|
|
locals: { members: @members },
|
|
|
|
handlers: [:axlsx],
|
|
|
|
formats: [:xlsx]
|
|
|
|
)
|
2016-07-27 17:00:06 +02:00
|
|
|
# write content to file
|
2023-02-24 17:26:55 +01:00
|
|
|
File.binwrite(export.file, content)
|
2016-07-27 17:00:06 +02:00
|
|
|
end
|
2019-06-13 16:53:36 +02:00
|
|
|
end
|