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
|
|
|
|
|
2023-01-04 10:27:14 +01:00
|
|
|
attr_reader :performed
|
|
|
|
|
|
|
|
def perform(action = :yesterday, *params)
|
2022-11-22 17:43:19 +01:00
|
|
|
send(action, *params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def today
|
2022-11-18 16:42:11 +01:00
|
|
|
service = Accounting::AccountingService.new
|
2023-02-14 13:10:58 +01:00
|
|
|
start = Time.current.beginning_of_day
|
|
|
|
finish = Time.current.end_of_day
|
2023-01-04 10:27:14 +01:00
|
|
|
ids = service.build(start, finish)
|
|
|
|
@performed = "today: #{start} -> #{finish}; invoices: #{ids}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def yesterday
|
|
|
|
service = Accounting::AccountingService.new
|
2023-02-14 13:10:58 +01:00
|
|
|
start = 1.day.ago.beginning_of_day
|
|
|
|
finish = 1.day.ago.end_of_day
|
2023-01-04 10:27:14 +01:00
|
|
|
ids = service.build(start, finish)
|
|
|
|
@performed = "yesterday: #{start} -> #{finish}; invoices: #{ids}"
|
2022-11-18 16:42:11 +01:00
|
|
|
end
|
2022-11-22 17:43:19 +01:00
|
|
|
|
|
|
|
def invoices(invoices_ids)
|
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)
|
2023-01-04 10:27:14 +01:00
|
|
|
ids = service.build_from_invoices(invoices)
|
|
|
|
@performed = "invoices: #{ids}"
|
2022-11-22 17:43:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def all
|
2022-12-08 15:15:47 +01:00
|
|
|
# build
|
2022-11-22 17:43:19 +01:00
|
|
|
service = Accounting::AccountingService.new
|
2023-01-04 10:27:14 +01:00
|
|
|
ids = service.build_from_invoices(Invoice.all)
|
|
|
|
@performed = "all: #{ids}"
|
2022-11-22 17:43:19 +01:00
|
|
|
end
|
2022-11-18 16:42:11 +01:00
|
|
|
end
|