Module: HrLite::LeaveDayCounter
- Defined in:
- app/services/hr_lite/leave_day_counter.rb
Overview
How many working days a leave request actually consumes. Weekends and company-wide holidays inside the range are free; a half-day (single-day requests only) consumes 0.5.
Class Method Summary collapse
-
.count(leave_request, calendar: nil) ⇒ Object
calendar:lets a caller counting many requests over the same span build ONE calendar and reuse it. - .count_range(start_date:, end_date:, half_day: false, calendar: nil) ⇒ Object
Class Method Details
.count(leave_request, calendar: nil) ⇒ Object
calendar: lets a caller counting many requests over the same span
build ONE calendar and reuse it. Each one costs a Holiday query and a
Setting query, and the balances grid counts every approved request of
every employee for every leave type.
10 11 12 13 14 15 16 17 |
# File 'app/services/hr_lite/leave_day_counter.rb', line 10 def self.count(leave_request, calendar: nil) count_range( start_date: leave_request.start_date, end_date: leave_request.end_date, half_day: leave_request.half_day, calendar: calendar ) end |
.count_range(start_date:, end_date:, half_day: false, calendar: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'app/services/hr_lite/leave_day_counter.rb', line 19 def self.count_range(start_date:, end_date:, half_day: false, calendar: nil) return 0 if start_date.nil? || end_date.nil? || end_date < start_date range = start_date..end_date working = (calendar || WorkingCalendar.new(range)).working_days_in(range) return BigDecimal("0.5") if half_day && working.positive? BigDecimal(working) end |