class User < ActiveRecord::Base # @!attribute role # @return [Enumberable] companyadmin role is assign to the company's admin enum role: [:user, :corp_admin, :admin] # @!attribute employment_type # @return [Enumberable] companyadmin role is assign to the company's admin enum employment_type: [:full_time, :part_time, :contractor] # @!attribute status # @return [Enumberable] if he is still a part of this company enum status: [:active, :terminated] # @!attribute email # @!attribute join_on # the date joined this company. # calculate the total vacation days this user has in this calendar year. # It can include days from previous years, depending on the accural type. # @return [Integer] the total vacation days def total_vacation_hours total_vacation_days * self.policy.work_hours_per_day end # calculate total vacation days of this year def total_vacation_days self.policy.tentures.inject(self.policy.base_vacation_days) do |res , i| res + (Time.zone.now - i[:anniversary].to_i.years > self.join_on ? i[:extra_days]: 0) end end # calculate the total vacation days that is used for in this calendar year # @return [Integer] the total used vacation days def total_used_vacation_days total_used_vacation_hours / self.policy.work_hours_per_day end def total_used_vacation_hours total_vacation_hours - total_remain_vacation_hours end # total_vacation_days - total_used_vacation_days # @return [Integer] total left over vacation days def total_remain_vacation_days total_remain_vacation_hours / self.policy.work_hours_per_day end def total_remain_vacation_hours TimeoffTask.where(user: self, sub_type: [:accrue, :adjustment, :vacation].map {|i| TimeoffTask.sub_types[i]}).sum(:total_hours) end def total_remain_personal_hours TimeoffTask.total_personal_hours_for_user(self) end def total_remain_sick_hours TimeoffTask.total_sick_hours_for_user(self) end # TODO: # check if user is on vacation, depending on his vacation requests # @return [Boolean] true or false def on_vacation? false end # TODO: # check if user is sick # @return [Boolean] true or false def is_sick? false end def self.policy_class EmployeePolicy end end