Module: TimeOffPlannedWorkDayHelper
- Included in:
- Crm::TimeOffsHelper, DailyFocus::Prompt, EmployeeTimeOffsHelper
- Defined in:
- app/helpers/time_off_planned_work_day_helper.rb
Overview
Planned work window for partial-day PTO (TimeOffRequestDate#planned_work_day JSON).
Used by CRM UI and WorkforceMailer PTO notifications.
Instance Method Summary collapse
-
#time_off_planned_work_day_planned_hours(planned_work_day, requested_amount) ⇒ Object
Hours the employee plans to work after subtracting the requested time off.
- #time_off_planned_work_day_summary(planned_work_day) ⇒ Object
-
#time_off_planned_work_day_usual_summary(planned_work_day) ⇒ Object
Usual weekday schedule snapshotted at request time, formatted to match the planned summary.
Instance Method Details
#time_off_planned_work_day_planned_hours(planned_work_day, requested_amount) ⇒ Object
Hours the employee plans to work after subtracting the requested time off.
41 42 43 44 45 46 47 48 |
# File 'app/helpers/time_off_planned_work_day_helper.rb', line 41 def time_off_planned_work_day_planned_hours(planned_work_day, requested_amount) return if planned_work_day.blank? || requested_amount.blank? usual_hours = planned_work_day.with_indifferent_access.dig(:usual, :hours) return if usual_hours.blank? format_planned_hours(usual_hours.to_d - requested_amount.to_d) end |
#time_off_planned_work_day_summary(planned_work_day) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/time_off_planned_work_day_helper.rb', line 6 def time_off_planned_work_day_summary(planned_work_day) return if planned_work_day.blank? h = planned_work_day.with_indifferent_access planned = h[:planned] return if planned.blank? p = planned.with_indifferent_access parts = [] parts << "#{format_planned_time_ampm(p[:start_time])}–#{format_planned_time_ampm(p[:end_time])} work" if p[:start_time].present? && p[:end_time].present? if ActiveModel::Type::Boolean.new.cast(p[:skip_lunch]) parts << 'no lunch' elsif p[:lunch_start].present? && p[:lunch_end].present? parts << "lunch #{format_planned_time_ampm(p[:lunch_start])}–#{format_planned_time_ampm(p[:lunch_end])}" end parts.presence&.join(' · ') end |
#time_off_planned_work_day_usual_summary(planned_work_day) ⇒ Object
Usual weekday schedule snapshotted at request time, formatted to match the planned summary.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/time_off_planned_work_day_helper.rb', line 25 def time_off_planned_work_day_usual_summary(planned_work_day) return if planned_work_day.blank? h = planned_work_day.with_indifferent_access usual = h[:usual] return if usual.blank? u = usual.with_indifferent_access parts = [] parts << "#{format_planned_time_ampm(u[:start_time])}–#{format_planned_time_ampm(u[:end_time])} work" if u[:start_time].present? && u[:end_time].present? parts << "lunch #{format_planned_time_ampm(u[:lunch_start])}–#{format_planned_time_ampm(u[:lunch_end])}" if u[:lunch_start].present? && u[:lunch_end].present? parts << "#{format_planned_hours(u[:hours])} h" if u[:hours].present? parts.presence&.join(' · ') end |