Module: HasCompanySetup

Extended by:
ActiveSupport::Concern
Included in:
Company
Defined in:
app/models/concerns/has_company_setup.rb

Constant Summary collapse

UNSUPPORTED_PROVINCE =
'unsupported_province'
NO_CNESST_CODES =
'no_cnesst_codes'
EMPLOYEES_WITHOUT_ROLES =
'employees_without_roles'
EMPLOYEES_IN_UNSUPPORTED_PROVINCES =
'employees_in_unsupported_provinces'
EMPLOYEES_WITHOUT_PAYROLL_CALCULATIONS =
'employees_without_payroll_calculations'
NO_PAYROLL_PARAMETERS_FOR_CURRENT_YEAR =
'no_payroll_parameters_for_current_year'
NO_HOLIDAYS_FOR_THIS_YEAR =
'no_holidays_for_this_year'
NOT_ENOUGH_PAYROLL_PERIODS_FOR_THIS_YEAR =
'not_enough_payroll_periods_for_this_year'
NOT_ENOUGH_PAYROLL_PARAMETERS_FOR_NEXT_YEAR =
'not_enough_payroll_parameters_for_next_year'
NOT_ENOUGH_PAYROLL_PERIODS_FOR_NEXT_YEAR =
'not_enough_payroll_periods_for_next_year'
NOT_ENOUGH_PAID_HOLIDAYS_FOR_NEXT_YEAR =
'not_enough_paid_holidays_for_next_year'

Instance Method Summary collapse

Instance Method Details

#employees_in_unsupported_provincesObject



54
55
56
57
# File 'app/models/concerns/has_company_setup.rb', line 54

def employees_in_unsupported_provinces
  employees.includes(:province)
           .where.not(province: { province_code: Province::Codes::QUEBEC })
end

#employees_without_payroll_calculationsObject



59
60
61
62
63
# File 'app/models/concerns/has_company_setup.rb', line 59

def employees_without_payroll_calculations
  employees.joins(
    'LEFT JOIN employee_payroll_calculation ON employees.employee_id = employee_payroll_calculation.employee_id'
  ).where(employee_payroll_calculation: { employee_payroll_calculation_id: nil })
end

#employees_without_rolesObject



49
50
51
52
# File 'app/models/concerns/has_company_setup.rb', line 49

def employees_without_roles
  employees.joins('LEFT JOIN employee_roles ON employees.employee_id = employee_roles.employee_id')
           .where(employee_roles: { employee_role_id: nil })
end

#setup_completed?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/models/concerns/has_company_setup.rb', line 18

def setup_completed?
  setup_issues.empty?
end

#setup_issuesObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/concerns/has_company_setup.rb', line 22

def setup_issues
  issues = []

  # Company-level checks
  issues << UNSUPPORTED_PROVINCE unless in_supported_province?
  issues << NO_CNESST_CODES unless cnesst_code?

  # Employee-level checks
  issues << EMPLOYEES_WITHOUT_ROLES if employees_without_roles.exists?
  issues << EMPLOYEES_IN_UNSUPPORTED_PROVINCES if employees_in_unsupported_provinces.exists?
  issues << EMPLOYEES_WITHOUT_PAYROLL_CALCULATIONS if employees_without_payroll_calculations.exists?

  # Payroll-related checks
  issues << NO_PAYROLL_PARAMETERS_FOR_CURRENT_YEAR unless payroll_parameters_for_current_year.exists?
  issues << NO_HOLIDAYS_FOR_THIS_YEAR unless holidays_for_this_year.exists?
  issues << NOT_ENOUGH_PAYROLL_PERIODS_FOR_THIS_YEAR unless enough_payroll_periods_for_this_year?

  # Next year checks
  if in_end_of_year?
    issues << NOT_ENOUGH_PAYROLL_PARAMETERS_FOR_NEXT_YEAR unless payroll_parameters_for_next_year.exists?
    issues << NOT_ENOUGH_PAYROLL_PERIODS_FOR_NEXT_YEAR unless enough_payroll_periods_for_next_year?
    issues << NOT_ENOUGH_PAID_HOLIDAYS_FOR_NEXT_YEAR unless paid_holidays_for_next_year.exists?
  end

  issues
end