def post(self, request, pk, user_id, format=None):
        ltd_plan = self._get_plan(pk)
        emp_person = self._get_employee_person(user_id)
        if not emp_person:
            return Response({'message': 'No Person Found'})
        compensation_service = CompensationService(emp_person.id)
        current_salary = None
        try:
            current_salary = compensation_service.get_current_annual_salary()
        except ValueError:
            return Response({'message': 'No salary info'})

        if not request.DATA['amount'] and request.DATA['amount'] != 0:
            amount = None
        else:
            amount = request.DATA['amount']

        disability_service = DisabilityInsuranceService(ltd_plan)
        effective_rate = disability_service.get_benefit_rate_of_cost(
            emp_person)
        effective_benefit_amount = disability_service.get_effective_benefit_amount(
            ltd_plan.max_benefit_monthly, amount, 12, current_salary)
        total_premium = disability_service.get_total_premium(
            effective_benefit_amount, effective_rate)
        employee_premium = disability_service.get_employee_premium(
            total_premium)
        return Response({
            'total': total_premium,
            'employee': employee_premium,
            'amount': effective_benefit_amount
        })
Ejemplo n.º 2
0
    def _write_regular_pay(self, timecard, person, profile, excelSheet, row_num, col_num):
        weekly_pay = None
        if person:
            compensation_service = CompensationService(person.id, profile)
            week_total_hours = 0
            if timecard:
                week_total_hours = self._get_week_total(timecard, 'workHours')
            weekly_pay = compensation_service.get_current_weekly_salary(week_total_hours)

        if weekly_pay:
            col_num = self._write_field(excelSheet, row_num, col_num, '{0:.2f}'.format(weekly_pay))
        else:
            col_num = self._write_field(excelSheet, row_num, col_num, 'Salary Not Available')

        return col_num
    def get_basic_life_insurance_cost_for_employee(self, personId):
        fix_cost = self._use_fix_benefit_cost()

        compensation_service = CompensationService(personId)
        current_salary = compensation_service.get_current_annual_salary()
        benefit_amount = self._get_effective_benefit_amount(
            self._life_insurance_plan.insurance_amount,
            self._life_insurance_plan.salary_multiplier, current_salary)
        cost = None
        if fix_cost:
            cost = BasicLifeInsuranceCost(
                self._life_insurance_plan.total_cost_per_period,
                self._life_insurance_plan.employee_cost_per_period,
                benefit_amount)
        else:
            total_cost = self._get_total_premium(
                benefit_amount, self._life_insurance_plan.total_cost_rate,
                1.0 / 12)
            employee_cost = self._get_employee_premium(
                total_cost,
                self._life_insurance_plan.employee_contribution_percentage)
            cost = BasicLifeInsuranceCost(total_cost, employee_cost,
                                          benefit_amount)
        return cost
Ejemplo n.º 4
0
    def _get_user_data(self, user):
        result = {}

        # User info
        user_info = {}

        ## Basic info
        user_info['user_id'] = user.id
        user_info[
            'user_id_env_encode'] = self.hash_key_service.encode_key_with_environment(
                user.id)
        user_info['account_email'] = user.email

        ## Person and Compensation Info
        persons = Person.objects.filter(user=user.id, relationship='self')
        if (len(persons) > 0):
            person_model = persons[0]
            person_data = PersonInfo(person_model)
            user_info['first_name'] = person_data.first_name
            user_info['last_name'] = person_data.last_name

            compensation_info = CompensationService(person_model=person_model)
            hourly_rate = compensation_info.get_current_hourly_rate()
            if (hourly_rate):
                hourly_rate = round(hourly_rate, 2)
            user_info['hourly_rate'] = hourly_rate

        result['user_info'] = user_info

        # Company Info
        company_info = {}

        company_users = CompanyUser.objects.filter(user=user.id)
        company_id = None
        if (len(company_users) > 0):
            company_user = company_users[0]
            company_id = company_user.company_id
            company_info['company_id'] = company_id
            company_info[
                'company_id_env_encode'] = self.hash_key_service.encode_key_with_environment(
                    company_user.company_id)
            if (company_user.company):
                company_info['company_name'] = company_user.company.name

        result['company_info'] = company_info

        # Application Features
        application_features = None
        if (company_id):
            application_feature_service = ApplicationFeatureService()
            application_features = application_feature_service.get_complete_application_feature_status_by_company(
                company_id)
            result['app_features_info'] = application_features

        # Projects
        if (application_features
                and application_features[APP_FEATURE_PROJECTMANAGEMENT]):
            project_service = ProjectService()
            result['project_list'] = project_service.get_projects_by_company(
                company_id, active_only=True)

        return result
Ejemplo n.º 5
0
    def __init__(self,
                 person_model,
                 company_model,
                 employee_user_id,
                 profile_model=None):
        self._employee_profile_model = None
        self._compensation_service = None
        self._employee_user_id = employee_user_id
        self._company_model = company_model
        self._is_new_employee = None

        if (person_model):
            try:
                if (profile_model):
                    self._employee_profile_model = profile_model
                else:
                    self._employee_profile_model = EmployeeProfile.objects.get(
                        company=company_model.id, person=person_model.id)
                self._compensation_service = CompensationService(
                    person_model=person_model,
                    profile=self._employee_profile_model)
            except EmployeeProfile.DoesNotExist:
                pass

        self.job_title = ''
        self.employee_number = ''
        self.hire_date = ''
        self.end_date = ''
        self.pay_cycle = ''
        self.employment_status = ''
        self.projected_hours_per_pay_cycle = ''
        self.projected_hours_per_week = ''
        self.pay_type = ''
        self.compensation_effective_date = ''
        self.current_hourly_rate = ''
        self.current_pay_period_salary = ''
        self.annual_salary = ''
        self.employment_type = ''
        self.department = None
        self.division = None
        self.job = None

        if (self._employee_profile_model):
            self.job_title = self._employee_profile_model.job_title
            self.employee_number = self._employee_profile_model.employee_number
            self.hire_date = self._employee_profile_model.start_date
            self.end_date = self._employee_profile_model.end_date
            self.pay_cycle = company_model.pay_period_definition.name
            self.employment_status = self._employee_profile_model.employment_status
            self.employment_type = self._employee_profile_model.employment_type

            if (self._employee_profile_model.department):
                self.department = Department(
                    self._employee_profile_model.department.department,
                    self._employee_profile_model.department.code)

            if (self._employee_profile_model.division):
                self.division = Division(
                    self._employee_profile_model.division.division,
                    self._employee_profile_model.division.code)

            if (self._employee_profile_model.job):
                self.job = Job(self._employee_profile_model.job.job,
                               self._employee_profile_model.job.code)

            if (self._compensation_service):
                current_compensation = self._compensation_service.current_compensation

                if (current_compensation):
                    projected_hours_cycle = self._get_projected_hours_per_pay_cycle(
                        current_compensation,
                        company_model.pay_period_definition)
                    if (projected_hours_cycle):
                        self.projected_hours_per_pay_cycle = projected_hours_cycle

                    projected_hours_week = self._get_projected_hours_per_week(
                        current_compensation)
                    if (projected_hours_week):
                        self.projected_hours_per_week = projected_hours_week

                    pay_type = self._compensation_service.get_current_pay_type(
                    )
                    if (pay_type):
                        self.pay_type = pay_type

                    self.compensation_effective_date = current_compensation.effective_date

                    if (self.pay_type == PAY_TYPE_HOURLY):
                        self.current_hourly_rate = self._compensation_service.get_current_hourly_rate(
                        )
                    elif (self.pay_type == PAY_TYPE_SALARY):
                        self.annual_salary = self._compensation_service.get_current_annual_salary(
                        )
                        self.current_pay_period_salary = self._get_pay_period_salary(
                            self.annual_salary,
                            company_model.pay_period_definition)
Ejemplo n.º 6
0
class EmployeeEmploymentProfileInfo(object):
    def __init__(self,
                 person_model,
                 company_model,
                 employee_user_id,
                 profile_model=None):
        self._employee_profile_model = None
        self._compensation_service = None
        self._employee_user_id = employee_user_id
        self._company_model = company_model
        self._is_new_employee = None

        if (person_model):
            try:
                if (profile_model):
                    self._employee_profile_model = profile_model
                else:
                    self._employee_profile_model = EmployeeProfile.objects.get(
                        company=company_model.id, person=person_model.id)
                self._compensation_service = CompensationService(
                    person_model=person_model,
                    profile=self._employee_profile_model)
            except EmployeeProfile.DoesNotExist:
                pass

        self.job_title = ''
        self.employee_number = ''
        self.hire_date = ''
        self.end_date = ''
        self.pay_cycle = ''
        self.employment_status = ''
        self.projected_hours_per_pay_cycle = ''
        self.projected_hours_per_week = ''
        self.pay_type = ''
        self.compensation_effective_date = ''
        self.current_hourly_rate = ''
        self.current_pay_period_salary = ''
        self.annual_salary = ''
        self.employment_type = ''
        self.department = None
        self.division = None
        self.job = None

        if (self._employee_profile_model):
            self.job_title = self._employee_profile_model.job_title
            self.employee_number = self._employee_profile_model.employee_number
            self.hire_date = self._employee_profile_model.start_date
            self.end_date = self._employee_profile_model.end_date
            self.pay_cycle = company_model.pay_period_definition.name
            self.employment_status = self._employee_profile_model.employment_status
            self.employment_type = self._employee_profile_model.employment_type

            if (self._employee_profile_model.department):
                self.department = Department(
                    self._employee_profile_model.department.department,
                    self._employee_profile_model.department.code)

            if (self._employee_profile_model.division):
                self.division = Division(
                    self._employee_profile_model.division.division,
                    self._employee_profile_model.division.code)

            if (self._employee_profile_model.job):
                self.job = Job(self._employee_profile_model.job.job,
                               self._employee_profile_model.job.code)

            if (self._compensation_service):
                current_compensation = self._compensation_service.current_compensation

                if (current_compensation):
                    projected_hours_cycle = self._get_projected_hours_per_pay_cycle(
                        current_compensation,
                        company_model.pay_period_definition)
                    if (projected_hours_cycle):
                        self.projected_hours_per_pay_cycle = projected_hours_cycle

                    projected_hours_week = self._get_projected_hours_per_week(
                        current_compensation)
                    if (projected_hours_week):
                        self.projected_hours_per_week = projected_hours_week

                    pay_type = self._compensation_service.get_current_pay_type(
                    )
                    if (pay_type):
                        self.pay_type = pay_type

                    self.compensation_effective_date = current_compensation.effective_date

                    if (self.pay_type == PAY_TYPE_HOURLY):
                        self.current_hourly_rate = self._compensation_service.get_current_hourly_rate(
                        )
                    elif (self.pay_type == PAY_TYPE_SALARY):
                        self.annual_salary = self._compensation_service.get_current_annual_salary(
                        )
                        self.current_pay_period_salary = self._get_pay_period_salary(
                            self.annual_salary,
                            company_model.pay_period_definition)

    @property
    def new_employee(self):
        if (self._is_new_employee is None):
            company_user = CompanyUser.objects.get(
                user=self._employee_user_id,
                company_user_type=USER_TYPE_EMPLOYEE,
                company=self._company_model.id)

            self._is_new_employee = company_user.new_employee
        return self._is_new_employee

    def _get_projected_hours_per_pay_cycle(self, compensation_info,
                                           pay_period_definition):
        if (compensation_info.projected_hour_per_month):
            return float(compensation_info.projected_hour_per_month
                         ) * pay_period_definition.month_factor
        return None

    def _get_projected_hours_per_week(self, compensation_info):
        if (compensation_info.projected_hour_per_month):
            return float(compensation_info.projected_hour_per_month) * 12 / 52
        return None

    def _get_pay_period_salary(self, annual_salary, pay_period_definition):
        if (not annual_salary):
            return annual_salary
        return float(annual_salary) / 12.0 * pay_period_definition.month_factor

    ''' Check if employee is active, at least partially, during the specified
        time period.
        The period_start and period_end are expected to be datetime objects
    '''

    def is_employee_active_anytime_in_time_period(self, period_start,
                                                  period_end):
        # just return some dumb assumption for inputs not sufficient
        # for determination
        if (not self.hire_date):
            return False

        # Compute the 2 date diffs to see if employee active period
        # overlaps the given time period to check
        # The 2 time range overlaps if the below 2 statements hold altogether
        #  * employee_start_date <= period_end
        #  * employee_end_date >= period_start
        return ((self.hire_date <= period_end)
                and (not self.end_date or self.end_date >= period_start))

    def is_full_time_employee(self):
        return self.employment_type == FULL_TIME
 def get(self, request, person_id, format=None):
     comp_service = CompensationService(person_id)
     all_comps = comp_service.get_all_compensation_ordered()
     serializer = CompensationInfoSerializer(all_comps, many=True)
     return Response(serializer.data)