Class: HrLite::ExpenseCategory
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- HrLite::ExpenseCategory
- 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
-
#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.
- #uncapped? ⇒ Boolean
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
18 |
# File 'app/models/hr_lite/expense_category.rb', line 18 def uncapped? = monthly_cap.nil? |