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

25 lines
762 B
Ruby
Raw Normal View History

2016-03-23 18:39:41 +01:00
class InvoiceWorker
include Sidekiq::Worker
def perform(invoice_id, subscription_expiration_date)
2016-03-23 18:39:41 +01:00
# generate a invoice
invoice = Invoice.find invoice_id
pdf = ::PDF::Invoice.new(invoice, subscription_expiration_date).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