2020-12-23 15:29:56 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-12-23 16:56:19 +01:00
|
|
|
# Generates the PDF Document associated with the provided payment schedule, and send it to the customer
|
2020-12-23 15:29:56 +01:00
|
|
|
# If this is the case
|
|
|
|
class PaymentScheduleWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2020-12-23 16:56:19 +01:00
|
|
|
def perform(payment_schedule_id)
|
|
|
|
# generate a payment schedule document
|
|
|
|
ps = PaymentSchedule.find(payment_schedule_id)
|
2021-01-19 16:47:51 +01:00
|
|
|
pdf = ::PDF::PaymentSchedule.new(ps).render
|
2020-12-23 16:56:19 +01:00
|
|
|
|
|
|
|
# save the file on the disk
|
|
|
|
File.binwrite(ps.file, pdf)
|
|
|
|
|
|
|
|
# notify user, send schedule document by email
|
2021-01-19 16:47:51 +01:00
|
|
|
NotificationCenter.call type: 'notify_user_when_payment_schedule_ready',
|
2020-12-23 16:56:19 +01:00
|
|
|
receiver: ps.user,
|
|
|
|
attached_object: ps
|
2020-12-23 15:29:56 +01:00
|
|
|
end
|
|
|
|
end
|