Class: Crm::TimeOffsController

Inherits:
CrmController show all
Includes:
Controllers::RequireTurboFrame
Defined in:
app/controllers/crm/time_offs_controller.rb

Overview

Employee and manager PTO dashboards: tabbed self-service views
(TimeOffRequest, TimeOffBalance, work schedule, policies) plus the
manager-only approval queues and team-status grid.

Constant Summary collapse

EMPLOYEE_TAB_ACTIONS =

Tab fragments never render standalone — non-frame hits redirect to their
dashboard with the tab preselected. Two hosts: the employee dashboard
(member route, keeps :id) and the manager dashboard (collection route).

%i[employee_tab_summary employee_tab_time_off_calculator employee_tab_request_history employee_tab_balance_history employee_tab_work_schedule employee_tab_company_holidays employee_tab_assigned_policies].freeze
MANAGER_TAB_ACTIONS =

Manager-dashboard tab fragments — see EMPLOYEE_TAB_ACTIONS.

%i[manager_tab_employee_status manager_tab_time_off_requests manager_tab_work_schedule_requests manager_tab_blocked_days manager_tab_company_holidays manager_tab_time_off_types manager_tab_time_off_policies].freeze

Constants included from Controllers::ReferenceFindable

Controllers::ReferenceFindable::ID_EMBEDDED_PATTERNS

Constants included from Controllers::AnalyticsEvents

Controllers::AnalyticsEvents::MAX_QUEUED_EVENTS, Controllers::AnalyticsEvents::SESSION_KEY

Constants included from Controllers::ErrorRendering

Controllers::ErrorRendering::NON_CONTENT_PATH_PREFIXES

Instance Method Summary collapse

Methods included from Controllers::RequireTurboFrame

require_in_pane_tab_frames, require_turbo_frame

Methods inherited from CrmController

#access_denied, #context_id, #context_object, #crm_home_path, #current_ability, #default_url_options, #download_temp, #get_tempfile_path_for_download, #init_status_job_collector, #initialize_crm_lazy_chunks, #persist_enqueued_status_jobs, #record_not_found, #redirect_to_job_or_fallback, #render_edit_action, #set_context, #set_download_path, #stash_file_for_temp_download, #sync_admin_presence_cookie, #touch_employee_last_seen

Methods inherited from ApplicationController

#account_impersonated?, #add_to_flash, #after_sign_in_path_for, #bypass_forgery_protection?, #chat_enabled?, #cloudflare_cleared?, #default_catalog, #default_url_options, #enable_turbo_frames, #find_publication, #fix_invalid_accept_header, #init_js_utils, #is_globals_call?, #layout_by_resource, #locale_store, #redirect_to, #require_employee_for_crm, #set_base_host, #set_real_ip, #set_report_errors_for, #should_render_layout?, #skip_layout_for_turbo_frame?, #stamp_impersonation_context, #tab_frame_breakout_request?, #warmlyyours_canada_ip?, #warmlyyours_ip?, #y

Methods included from Controllers::ReturnPathHandling

#check_for_return_path, #redirect_to_return_path_or_default

Methods included from Controllers::AnalyticsEvents

#consume_queued_analytics_events, #registration_lead_type, #track_event

Methods included from Controllers::DeviceDetection

#device_detector, #is_ie?

Methods included from Controllers::SubdomainDetection

#is_crm_request?, #is_www_request?, #json_request?

Methods included from Controllers::TurboSafeRedirect

#redirect_to

Methods included from Controllers::TrackingDetection

#bot_request?, #gdpr_country?, #gdpr_country_data, #prevent_bots, #set_tracking_cookie, #track_visitor?

Methods included from Controllers::AcceleratedFileSending

#send_file_accelerated, #send_upload_accelerated

Methods included from Controllers::ErrorRendering

#excp_string, #mail_to_for_error_reporting, #render_400, #render_404, #render_406, #render_410, #render_500, #render_invalid_authenticity_token, #render_ip_spoof_error, #render_unpermitted_parameters, #safe_referer_or_fallback

Methods included from Controllers::TurnstileVerification

#load_turnstile_script_tag, #turnstile_lazy_widget, #turnstile_script_tag, #turnstile_widget, #validate_turnstile!

Methods included from Controllers::CloudflareCaching

edge_cached, #edge_cached_action?, #reset_cloudflare_cache, #set_cloudflare_cache, #skip_edge_cache!, #skip_session

Methods included from Controllers::Webpackable

#preload_webpack_fonts, #webpack_css_include, #webpack_css_url, #webpack_js_include, #wpd_is_running?

Methods included from Controllers::Localizable

#cloudflare_country_locale, #determine_request_locale, #geocoder_locale, #guest_user_locale_check, #locale_optional_www_auth_path?, #param_locale, #set_locale, #set_request_locale, #skip_localization?, #warmlyyours_ip_locale

Methods included from Controllers::Authenticable

#access_denied, #authenticate_account, #authenticate_account!, #authenticate_account_from_login_token!, #check_is_a_manager, #check_is_a_sales_manager, #check_is_an_admin, #check_is_an_employee, #check_party, #clear_mismatched_guest_user, #create_guest_user, #credentials?, #current_or_guest_user, #current_or_guest_user_id_read_only, #current_user, #devise_mapping, #fully_logged_in?, #generate_bot_id, #guest_user, #identifiable?, #init_current_user, #initialize_guest, #load_context_user, #logging_in, #resource, #resource_name, #restrict_access_for_non_employees, #scrubbed_request_path, #user_object, #warn_on_session_guest_id_leak

Methods included from UrlsHelper

#catalog_breadcrumb_links, #catalog_link, #catalog_link_for_product_line, #catalog_link_for_sku, #cms_link, #delocalized_path, #path_to_sales_product_sku, #path_to_sales_product_sku_for_product_line, #path_to_sales_product_sku_for_product_line_slug, #product_line_from_catalog_link, #protocol_neutral_url, #sanitize_external_url, #valid_external_url?

Instance Method Details

#employee_dashboardvoid

This method returns an undefined value.

Renders the employee's own PTO dashboard: requests, balances, work
schedule, holidays, and assigned policies, filterable by type and
year.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/crm/time_offs_controller.rb', line 50

def employee_dashboard
  @employee = Employee.find(params[:id])
  @work_schedules = @employee.work_schedules.order(:effective_date)
  assign_company_holiday_tab_collections
  @policies = @employee.time_off_policies.includes(:time_off_type).order(:accrual_start_date)

  @time_off_requests = @employee.time_off_requests.includes(:time_off_type).order(start_date: :desc)
  @time_off_balances = @employee.time_off_balances.includes(:time_off_type).order(date: :asc, id: :asc)
  @upcoming_time_off = fetch_upcoming_time_off

  # Filter by time off type if a type is selected
  if params[:time_off_type_id].present?
    @time_off_requests = @time_off_requests.where(time_off_type_id: params[:time_off_type_id])
    # For Banked Time, filter by category='banked' instead of time_off_type_id
    @time_off_balances = if params[:time_off_type_id].to_i == TimeOffType::BANKED_TIME_ID
                           @time_off_balances.where(category: 'banked')
                         else
                           @time_off_balances.where(time_off_type_id: params[:time_off_type_id])
                         end
  end

  # Filter by year, default to the current year if no year is selected
  selected_year = params[:year].present? ? params[:year].to_i : Time.current.year
  @time_off_requests = @time_off_requests.where('EXTRACT(YEAR FROM created_at) = ?', selected_year)
  @time_off_balances = @time_off_balances.where(date: Date.new(selected_year).all_year)

  # Call the balance calculator for all time off types as of today
  as_of_date = safe_parse_date(params[:calculator_date])
  @time_off_balances_view = TimeOffBalanceCalculator.new(employee: @employee, date: as_of_date).formatted_balances

  @time_off_vacation_summary = TimeOffBalanceCalculator.new(employee: @employee).vacation_summary
end

#employee_tab_assigned_policiesvoid

This method returns an undefined value.

Tab: assigned time off policies.



166
167
168
169
170
# File 'app/controllers/crm/time_offs_controller.rb', line 166

def employee_tab_assigned_policies
  @employee = Employee.find(params[:id])
  setup_employee_dashboard_data
  render 'tab_assigned_policies', layout: should_render_layout?
end

#employee_tab_balance_historyvoid

This method returns an undefined value.

Tab: balance history.



139
140
141
142
143
# File 'app/controllers/crm/time_offs_controller.rb', line 139

def employee_tab_balance_history
  @employee = Employee.find(params[:id])
  setup_employee_dashboard_data
  render 'tab_balance_history', layout: should_render_layout?
end

#employee_tab_company_holidaysvoid

This method returns an undefined value.

Tab: company holidays.



157
158
159
160
161
# File 'app/controllers/crm/time_offs_controller.rb', line 157

def employee_tab_company_holidays
  @employee = Employee.find(params[:id])
  setup_employee_dashboard_data
  render 'tab_company_holidays', layout: should_render_layout?
end

#employee_tab_request_historyvoid

This method returns an undefined value.

Tab: past and pending requests.



130
131
132
133
134
# File 'app/controllers/crm/time_offs_controller.rb', line 130

def employee_tab_request_history
  @employee = Employee.find(params[:id])
  setup_employee_dashboard_data
  render 'tab_request_history', layout: should_render_layout?
end

#employee_tab_summaryObject

Employee tab actions



112
113
114
115
116
# File 'app/controllers/crm/time_offs_controller.rb', line 112

def employee_tab_summary
  @employee = Employee.find(params[:id])
  setup_employee_dashboard_data
  render 'tab_summary', layout: should_render_layout?
end

#employee_tab_time_off_calculatorvoid

This method returns an undefined value.

Tab: the time off balance calculator.



121
122
123
124
125
# File 'app/controllers/crm/time_offs_controller.rb', line 121

def employee_tab_time_off_calculator
  @employee = Employee.find(params[:id])
  setup_employee_dashboard_data
  render 'tab_time_off_calculator', layout: should_render_layout?
end

#employee_tab_work_schedulevoid

This method returns an undefined value.

Tab: work schedule.



148
149
150
151
152
# File 'app/controllers/crm/time_offs_controller.rb', line 148

def employee_tab_work_schedule
  @employee = Employee.find(params[:id])
  setup_employee_dashboard_data
  render 'tab_work_schedule', layout: should_render_layout?
end

#filter_balancesvoid

This method returns an undefined value.

AJAX endpoint: re-renders the balance calculator partial as of a given
date.



87
88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/crm/time_offs_controller.rb', line 87

def filter_balances
  @employee = Employee.find(params[:id])
  as_of_date = safe_parse_date(params[:calculator_date])
  @time_off_balances_view = TimeOffBalanceCalculator.new(employee: @employee, date: as_of_date).formatted_balances
  @highlight_time_off_type_id = params[:highlight_time_off_type_id]

  respond_to do |format|
    format.html { render partial: 'crm/time_offs/calculator', locals: { time_off_balances_view: @time_off_balances_view }, layout: false }
    format.turbo_stream
  end
end

#filter_work_schedulevoid

This method returns an undefined value.

AJAX endpoint: re-renders the work-schedule partial effective as of a
given date.



103
104
105
106
107
108
109
# File 'app/controllers/crm/time_offs_controller.rb', line 103

def filter_work_schedule
  @employee = Employee.find(params[:id])
  as_of_date = safe_parse_date(params[:calculator_date])
  @work_schedule = @employee.work_schedules.effective_on(as_of_date).first

  render partial: 'crm/time_off_requests/work_schedule', layout: false
end

#manager_dashboardvoid

This method returns an undefined value.

Renders the manager dashboard shell (PTO managers only).



23
24
25
26
27
28
29
30
31
# File 'app/controllers/crm/time_offs_controller.rb', line 23

def manager_dashboard
  unless current_user.can?(:manage, TimeOffRequest)
    flash[:alert] = 'You do not have permission to access the PTO manager.'
    redirect_to root_path
    return
  end

  setup_manager_dashboard_shell
end

#manager_employee_statusObject

Full-page team availability for a selected day (date nav like daily_focus/review).
Any CRM employee; contrast with +manager_dashboard+ (PTO managers only).



35
36
37
38
39
40
41
42
43
# File 'app/controllers/crm/time_offs_controller.rb', line 35

def manager_employee_status
  unless current_user.can?(:read, :team_employee_status_dashboard)
    flash[:alert] = 'You do not have permission to view team schedules.'
    redirect_to root_path
    return
  end

  setup_employee_status_data
end

#manager_tab_blocked_daysvoid

This method returns an undefined value.

Tab: upcoming company-wide blocked days.



213
214
215
216
217
218
219
220
# File 'app/controllers/crm/time_offs_controller.rb', line 213

def manager_tab_blocked_days
  unless current_user.can?(:manage, TimeOffRequest)
    head :forbidden
    return
  end
  @blocked_days = TimeOffBlockedDay.where(blocked_date: Time.zone.today..).order(:blocked_date)
  render 'manager_tab_blocked_days', layout: should_render_layout?
end

#manager_tab_company_holidaysvoid

This method returns an undefined value.

Tab: company holidays by region.



225
226
227
228
229
230
231
232
# File 'app/controllers/crm/time_offs_controller.rb', line 225

def manager_tab_company_holidays
  unless current_user.can?(:manage, TimeOffRequest)
    head :forbidden
    return
  end
  setup_company_holidays_data
  render 'manager_tab_company_holidays', layout: should_render_layout?
end

#manager_tab_employee_statusObject

Manager tab actions



173
174
175
176
177
178
179
180
# File 'app/controllers/crm/time_offs_controller.rb', line 173

def manager_tab_employee_status
  unless current_user.can?(:read, :team_employee_status_dashboard)
    head :forbidden
    return
  end
  setup_employee_status_data
  render 'manager_tab_employee_status', layout: should_render_layout?
end

#manager_tab_time_off_policiesvoid

This method returns an undefined value.

Tab: time off policy management.



249
250
251
252
253
254
255
256
# File 'app/controllers/crm/time_offs_controller.rb', line 249

def manager_tab_time_off_policies
  unless current_user.can?(:manage, TimeOffRequest)
    head :forbidden
    return
  end
  @time_off_policies = TimeOffPolicy.for_manager_policies_tab
  render 'manager_tab_time_off_policies', layout: should_render_layout?
end

#manager_tab_time_off_requestsvoid

This method returns an undefined value.

Tab: pending time off requests awaiting manager decision.



185
186
187
188
189
190
191
192
193
194
# File 'app/controllers/crm/time_offs_controller.rb', line 185

def manager_tab_time_off_requests
  unless current_user.can?(:manage, TimeOffRequest)
    head :forbidden
    return
  end
  @pending_time_off_requests = TimeOffRequest.where(state: 'requested')
                                             .includes(:time_off_type, employee: %i[profile_image employee_record])
                                             .order(:created_at)
  render 'manager_tab_time_off_requests', layout: should_render_layout?
end

#manager_tab_time_off_typesvoid

This method returns an undefined value.

Tab: time off type management.



237
238
239
240
241
242
243
244
# File 'app/controllers/crm/time_offs_controller.rb', line 237

def manager_tab_time_off_types
  unless current_user.can?(:manage, TimeOffRequest)
    head :forbidden
    return
  end
  @time_off_types = TimeOffType.all
  render 'manager_tab_time_off_types', layout: should_render_layout?
end

#manager_tab_work_schedule_requestsvoid

This method returns an undefined value.

Tab: pending work schedule change requests.



199
200
201
202
203
204
205
206
207
208
# File 'app/controllers/crm/time_offs_controller.rb', line 199

def manager_tab_work_schedule_requests
  unless current_user.can?(:manage, TimeOffRequest)
    head :forbidden
    return
  end
  @pending_work_schedule_requests = WorkSchedule.where(state: 'pending')
                                                .includes(employee: %i[profile_image employee_record])
                                                .order(:created_at)
  render 'manager_tab_work_schedule_requests', layout: should_render_layout?
end