1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/app/services/users_export_service.rb

58 lines
1.7 KiB
Ruby
Raw Normal View History

2019-06-13 16:53:36 +02:00
# frozen_string_literal: true
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
class UsersExportService
# export subscriptions
def export_subscriptions(export)
@subscriptions = Subscription.all.includes(:plan, statistic_profile: [user: [:profile]])
2023-02-24 17:26:55 +01:00
content = ApplicationController.render(
template: 'exports/users_subscriptions',
locals: { subscriptions: @subscriptions },
handlers: [:axlsx],
formats: [:xlsx]
)
# write content to file
2023-02-24 17:26:55 +01:00
File.binwrite(export.file, content)
end
# export reservations
def export_reservations(export)
@reservations = Reservation.all.includes(:slots, :reservable, statistic_profile: [user: [:profile]])
2023-02-24 17:26:55 +01:00
content = ApplicationController.render(
template: 'exports/users_reservations',
locals: { reservations: @reservations },
handlers: [:axlsx],
formats: [:xlsx]
)
# write content to file
2023-02-24 17:26:55 +01:00
File.binwrite(export.file, content)
end
# export members
def export_members(export)
@members = User.members
.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]
)
# write content to file
2023-02-24 17:26:55 +01:00
File.binwrite(export.file, content)
end
2019-06-13 16:53:36 +02:00
end