mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +01:00
48 lines
1.2 KiB
Ruby
48 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Periodically build the accounting data (AccountingLine) from the Invoices & Avoirs
|
|
class AccountingWorker
|
|
include Sidekiq::Worker
|
|
|
|
attr_reader :performed
|
|
|
|
def perform(action = :yesterday, *params)
|
|
send(action, *params)
|
|
end
|
|
|
|
def today
|
|
service = Accounting::AccountingService.new
|
|
start = Time.current.beginning_of_day
|
|
finish = Time.current.end_of_day
|
|
ids = service.build(start, finish)
|
|
@performed = "today: #{start} -> #{finish}; invoices: #{ids}"
|
|
end
|
|
|
|
def yesterday
|
|
service = Accounting::AccountingService.new
|
|
start = 1.day.ago.beginning_of_day
|
|
finish = 1.day.ago.end_of_day
|
|
ids = service.build(start, finish)
|
|
@performed = "yesterday: #{start} -> #{finish}; invoices: #{ids}"
|
|
end
|
|
|
|
def invoices(invoices_ids)
|
|
# clean
|
|
AccountingLine.where(invoice_id: invoices_ids).delete_all
|
|
# build
|
|
service = Accounting::AccountingService.new
|
|
invoices = Invoice.where(id: invoices_ids)
|
|
ids = service.build_from_invoices(invoices)
|
|
@performed = "invoices: #{ids}"
|
|
end
|
|
|
|
def all
|
|
# clean
|
|
AccountingLine.delete_all
|
|
# build
|
|
service = Accounting::AccountingService.new
|
|
ids = service.build_from_invoices(Invoice.all)
|
|
@performed = "all: #{ids}"
|
|
end
|
|
end
|