2019-07-30 11:43:51 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Asynchronously export the accounting data (Invoices & Avoirs) to an external accounting software
|
|
|
|
class AccountingExportWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
def perform(export_id)
|
|
|
|
export = Export.find(export_id)
|
|
|
|
|
|
|
|
raise SecurityError, 'Not allowed to export' unless export.user.admin?
|
|
|
|
|
|
|
|
data = JSON.parse(export.query)
|
2019-09-16 16:31:16 +02:00
|
|
|
service = AccountingExportService.new(
|
|
|
|
data['columns'],
|
|
|
|
encoding: data['encoding'], format: export.extension, separator: export.key, date_format: data['date_format']
|
|
|
|
)
|
2019-07-30 11:43:51 +02:00
|
|
|
|
2019-07-30 16:06:35 +02:00
|
|
|
service.export(data['start_date'], data['end_date'], export.file)
|
2019-07-30 11:43:51 +02:00
|
|
|
|
|
|
|
NotificationCenter.call type: :notify_admin_export_complete,
|
|
|
|
receiver: export.user,
|
|
|
|
attached_object: export
|
|
|
|
end
|
|
|
|
end
|