1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/services/accounting/accounting_period_service.rb

23 lines
826 B
Ruby

# frozen_string_literal: true
# module definition
module Accounting; end
# Provides methods for accessing AccountingPeriods properties
class Accounting::AccountingPeriodService
class << self
def find_last_period
AccountingPeriod.where(end_at: AccountingPeriod.select('max(end_at)')).first
end
def all_periods_with_users
AccountingPeriod.joins("INNER JOIN #{User.arel_table.name} ON users.id = accounting_periods.closed_by
INNER JOIN #{Profile.arel_table.name} ON profiles.user_id = users.id")
.select("#{AccountingPeriod.arel_table.name}.*,
#{Profile.arel_table.name}.first_name,
#{Profile.arel_table.name}.last_name")
.order('start_at DESC')
end
end
end