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
|
|
|
|
|
|
|
ActionController::Base.prepend_view_path './app/views/'
|
|
|
|
# place data in view_assigns
|
2019-06-13 16:53:36 +02:00
|
|
|
view_assigns = { subscriptions: @subscriptions }
|
2016-07-27 17:00:06 +02:00
|
|
|
av = ActionView::Base.new(ActionController::Base.view_paths, view_assigns)
|
|
|
|
av.class_eval do
|
|
|
|
# include any needed helpers (for the view)
|
|
|
|
include ApplicationHelper
|
|
|
|
end
|
|
|
|
|
|
|
|
content = av.render template: 'exports/users_subscriptions.xlsx.axlsx'
|
|
|
|
# write content to file
|
2019-06-13 16:53:36 +02:00
|
|
|
File.open(export.file, 'w+b') { |f| f.puts content }
|
2016-07-27 17:00:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# export reservations
|
|
|
|
def export_reservations(export)
|
2019-09-10 16:45:45 +02:00
|
|
|
@reservations = Reservation.all.includes(:slots, :reservable, :invoice, statistic_profile: [user: [:profile]])
|
2016-07-27 17:00:06 +02:00
|
|
|
|
|
|
|
ActionController::Base.prepend_view_path './app/views/'
|
|
|
|
# place data in view_assigns
|
2019-06-13 16:53:36 +02:00
|
|
|
view_assigns = { reservations: @reservations }
|
2016-07-27 17:00:06 +02:00
|
|
|
av = ActionView::Base.new(ActionController::Base.view_paths, view_assigns)
|
|
|
|
av.class_eval do
|
|
|
|
# include any needed helpers (for the view)
|
|
|
|
include ApplicationHelper
|
|
|
|
end
|
|
|
|
|
|
|
|
content = av.render template: 'exports/users_reservations.xlsx.axlsx'
|
|
|
|
# write content to file
|
2019-06-13 16:53:36 +02:00
|
|
|
File.open(export.file, 'w+b') { |f| f.puts 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,
|
|
|
|
invoicing_profile: [:invoices, :address, organization: [:address]],
|
|
|
|
statistic_profile: [:trainings, subscriptions: [:plan]])
|
2016-07-27 17:00:06 +02:00
|
|
|
|
|
|
|
ActionController::Base.prepend_view_path './app/views/'
|
|
|
|
# place data in view_assigns
|
2019-06-13 16:53:36 +02:00
|
|
|
view_assigns = { members: @members }
|
2016-07-27 17:00:06 +02:00
|
|
|
av = ActionView::Base.new(ActionController::Base.view_paths, view_assigns)
|
|
|
|
av.class_eval do
|
|
|
|
# include any needed helpers (for the view)
|
|
|
|
include ApplicationHelper
|
|
|
|
end
|
|
|
|
|
|
|
|
content = av.render template: 'exports/users_members.xlsx.axlsx'
|
|
|
|
# write content to file
|
2019-06-13 16:53:36 +02:00
|
|
|
File.open(export.file, 'w+b') { |f| f.puts content }
|
2016-07-27 17:00:06 +02:00
|
|
|
end
|
|
|
|
|
2019-06-13 16:53:36 +02:00
|
|
|
end
|