Class: HrLite::ExpenseCategory

Inherits:
ApplicationRecord show all
Includes:
Audited, EncryptedMoney
Defined in:
app/models/hr_lite/expense_category.rb

Overview

"Travel", "Client entertainment", "Home office" — with the cap and the receipt rule that go with each.

Constant Summary

Constants included from Audited

Audited::REDACTED, Audited::SKIPPED_ATTRIBUTES

Instance Method Summary collapse

Instance Method Details

#remaining_for(user, month = Date.current.beginning_of_month) ⇒ Object

What is left of this month's cap for one person, or nil when uncapped. Counts everything not refused: a claim awaiting a decision has still been spent against the cap.



23
24
25
26
27
28
29
30
31
# File 'app/models/hr_lite/expense_category.rb', line 23

def remaining_for(user, month = Date.current.beginning_of_month)
  return nil if uncapped?

  spent = expenses.where(user_id: user.id)
                  .where(spent_on: month..month.end_of_month)
                  .where.not(status: %w[rejected cancelled])
                  .sum(BigDecimal(0)) { |e| e.amount || BigDecimal(0) }
  [ monthly_cap - spent, BigDecimal(0) ].max
end

#uncapped?Boolean

Returns:

  • (Boolean)


18
# File 'app/models/hr_lite/expense_category.rb', line 18

def uncapped? = monthly_cap.nil?