1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/workers/invoice_worker.rb
Sylvain 3e4892d3a5 WIP: creating payment schedule workers
see TODO in app/workers/payment_schedule*
2020-12-23 16:56:19 +01:00

28 lines
888 B
Ruby

# frozen_string_literal: true
# Generates the PDF Document associated with the provided invoice, and send it to the customer
class InvoiceWorker
include Sidekiq::Worker
def perform(invoice_id, subscription_expiration_date)
# generate a invoice
invoice = Invoice.find invoice_id
pdf = ::PDF::Invoice.new(invoice, subscription_expiration_date).render
# 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