2022-11-18 16:42:11 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Periodically build the accounting data (AccountingLine) from the Invoices & Avoirs
|
|
|
|
class AccountingWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2022-11-22 17:43:19 +01:00
|
|
|
def perform(action = :today, *params)
|
|
|
|
send(action, *params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def today
|
2022-11-18 16:42:11 +01:00
|
|
|
service = Accounting::AccountingService.new
|
|
|
|
service.build(DateTime.current.beginning_of_day, DateTime.current.end_of_day)
|
|
|
|
end
|
2022-11-22 17:43:19 +01:00
|
|
|
|
|
|
|
def invoices(invoices_ids)
|
2022-12-08 15:15:47 +01:00
|
|
|
# clean
|
2022-12-08 16:48:55 +01:00
|
|
|
AccountingLine.where(invoice_id: ids).delete_all
|
2022-12-08 15:15:47 +01:00
|
|
|
# build
|
2022-11-22 17:43:19 +01:00
|
|
|
service = Accounting::AccountingService.new
|
|
|
|
invoices = Invoice.where(id: invoices_ids)
|
|
|
|
service.build_from_invoices(invoices)
|
|
|
|
end
|
|
|
|
|
|
|
|
def all
|
2022-12-08 15:15:47 +01:00
|
|
|
# clean
|
2022-12-08 16:48:55 +01:00
|
|
|
AccountingLine.delete_all
|
2022-12-08 15:15:47 +01:00
|
|
|
# build
|
2022-11-22 17:43:19 +01:00
|
|
|
service = Accounting::AccountingService.new
|
|
|
|
service.build_from_invoices(Invoice.all)
|
|
|
|
end
|
2022-11-18 16:42:11 +01:00
|
|
|
end
|