2019-03-18 14:33:30 +01:00
|
|
|
class ClosePeriodReminderWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
def perform
|
2019-05-27 16:09:27 +02:00
|
|
|
return if Invoice.count.zero?
|
|
|
|
|
2019-03-18 14:33:30 +01:00
|
|
|
last_period = AccountingPeriod.order(closed_at: :desc).limit(1).last
|
2019-05-27 16:09:27 +02:00
|
|
|
first_invoice = Invoice.order(created_at: :asc).limit(1).last
|
|
|
|
return if !last_period && first_invoice.created_at > (Time.current - 1.year)
|
|
|
|
return if last_period && last_period.end_at > (Time.current - 1.year)
|
2019-03-18 14:33:30 +01:00
|
|
|
|
|
|
|
NotificationCenter.call type: 'notify_admin_close_period_reminder',
|
|
|
|
receiver: User.admins,
|
|
|
|
attached_object: last_period || Invoice.order(:created_at).first
|
|
|
|
end
|
|
|
|
end
|