2020-12-23 16:56:19 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Generates the PDF Document associated with the provided invoice, and send it to the customer
|
2016-03-23 18:39:41 +01:00
|
|
|
class InvoiceWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2023-01-05 12:09:16 +01:00
|
|
|
def perform(invoice_id)
|
2016-03-23 18:39:41 +01:00
|
|
|
# generate a invoice
|
|
|
|
invoice = Invoice.find invoice_id
|
2023-02-24 17:26:55 +01:00
|
|
|
pdf = ::Pdf::Invoice.new(invoice).render
|
2016-03-23 18:39:41 +01:00
|
|
|
|
|
|
|
# store invoice on drive
|
|
|
|
File.binwrite(invoice.file, pdf)
|
|
|
|
|
|
|
|
# notify user + send invoice by mail
|
|
|
|
if invoice.is_a?(Avoir)
|
|
|
|
NotificationCenter.call type: 'notify_user_when_avoir_ready',
|
|
|
|
receiver: invoice.user,
|
|
|
|
attached_object: invoice
|
|
|
|
else
|
|
|
|
NotificationCenter.call type: 'notify_user_when_invoice_ready',
|
|
|
|
receiver: invoice.user,
|
|
|
|
attached_object: invoice
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|