Ejemplo n.º 1
0
    def hours_before_six_and_less_than_nine(shift):
        six_pm = TimeSheet.get_shift_end(shift).replace(hour=18, minute=0)
        break_start = TimeSheet.get_break_start(shift)
        break_end = TimeSheet.get_break_end(shift)

        # shifts where 6pm comes BEFORE 9 hours duty
        if (TimeSheet.get_shift_start(shift) + timedelta(hours=9)) > TimeSheet.get_shift_end(shift) \
                .replace(hour=18, minute=0) < TimeSheet.get_shift_end(shift).replace(hour=12, minute=0):
            if break_start and break_end < six_pm:  # break STARTS and ENDS BEFORE 6pm
                hours_before_six_pm = (
                    TimeSheet.get_shift_start(shift) +
                    six_pm) - TimeSheet.get_break_duration(shift)
                return hours_before_six_pm

            elif break_start < six_pm < break_end:  # break STARTS BEFORE and ENDS AFTER 6pm
                break_before_six_pm = six_pm - TimeSheet.get_break_start(shift)
                hours_before_six_pm = (
                    six_pm -
                    TimeSheet.get_shift_start(shift)) - break_before_six_pm
                return hours_before_six_pm

            else:  # no break spanning BEFORE 6pm
                hours_before_six_pm = TimeSheet.get_shift_end(shift).replace(hour=18, minute=0) - \
                                      TimeSheet.get_shift_start(shift)
                return hours_before_six_pm

        else:  # no break BEFORE 6pm up to 9hrs
            hours_before_six_pm = TimeSheet.get_shift_end(shift).replace(hour=18, minute=0) - \
                                  TimeSheet.get_shift_start(shift)
            return hours_before_six_pm
Ejemplo n.º 2
0
    def hours_after_six_and_less_than_nine(shift):
        six_pm = TimeSheet.get_shift_end(shift).replace(hour=18, minute=0)
        duty_beyond_twelve = Weekday.duty_beyond_twelve_hours(shift)
        duty_beyond_nine = Weekday.duty_beyond_nine_hours(shift)
        overtime_duty = duty_beyond_twelve + duty_beyond_nine
        duty_remainder = TimeSheet.get_shift_length(shift) - overtime_duty
        start_plus_remainder = TimeSheet.get_shift_start(
            shift) + duty_remainder
        break_start = TimeSheet.get_break_start(shift)
        break_end = TimeSheet.get_break_end(shift)

        if TimeSheet.get_shift_start(shift) + duty_remainder > six_pm:
            if break_start and break_end < six_pm:  # break STARTS and ENDS BEFORE 6pm
                hours_after_six_pm = (start_plus_remainder - six_pm
                                      ) - TimeSheet.get_break_duration(shift)
                return hours_after_six_pm

            elif break_start < six_pm < break_end:  # break STARTS BEFORE and ENDS AFTER 6pm
                break_after_six_pm = TimeSheet.get_break_end(shift) - six_pm
                hours_after_six_pm = (start_plus_remainder -
                                      six_pm) - break_after_six_pm
                return hours_after_six_pm

            else:  # no break spanning AFTER 6pm
                hours_after_six_pm = timedelta(hours=0, minutes=0)
                return hours_after_six_pm

        else:  # no break within the reminder of duty up to 9hrs
            hours_after_six_pm = timedelta(hours=0, minutes=0)
            return hours_after_six_pm
Ejemplo n.º 3
0
    def duty_beyond_twelve_hours(shift):
        twelve_hours_duty = TimeSheet.get_shift_start(shift) + timedelta(
            hours=12)
        break_start = TimeSheet.get_break_start(shift)
        break_end = TimeSheet.get_break_end(shift)

        # break STARTS and ENDS AFTER 12hrs duty
        if break_start and break_end > twelve_hours_duty:
            duty_beyond_twelve_hours = (TimeSheet.get_shift_length(shift) - timedelta(hours=12)) - \
                                       TimeSheet.get_break_duration(shift)
            return duty_beyond_twelve_hours

        # break STARTS BEFORE and ENDS AFTER 12hrs duty
        elif break_start < twelve_hours_duty < break_end:
            duty_beyond_twelve_hours = TimeSheet.get_break_end(shift) - \
                                       (TimeSheet.get_shift_start(shift) + timedelta(hours=12))
            return duty_beyond_twelve_hours

        else:  # no break spanning AFTER 12hrs
            duty_beyond_twelve_hours = TimeSheet.get_shift_length(
                shift) - timedelta(hours=12)
            return duty_beyond_twelve_hours
Ejemplo n.º 4
0
    def get_sunday_pay(self):
        payslip = defaultdict(float)
        wage_rate = 0

        for shift in self.data['shifts']:
            day_of_week = TimeSheet.weekdays(shift)

            if day_of_week == 7:  # get hours for Saturday
                wage_level = float(
                    shift['wageLevel'])  # get wage level for shift
                if wage_level == 1:
                    wage_rate = float(self.data['wageLevels']['1'])
                elif wage_level == 2:
                    pass
                elif wage_level == 3:
                    wage_rate = float(self.data['wageLevels']['3'])

                if shift.get('breakStart'):  # looks for shifts with a break
                    shift_length = TimeSheet.get_shift_length(shift)
                    break_duration = TimeSheet.get_break_duration(shift)
                    nett_hours = shift_length - break_duration

                    if nett_hours > timedelta(
                            hours=12):  # shift length greater than 12hrs
                        plus_twelve_hours = nett_hours - timedelta(hours=12)
                        plus_twelve = (plus_twelve_hours.total_seconds() /
                                       3600 * wage_rate) * 2.25
                        plus_nine_hours = 3.0
                        plus_nine = (plus_nine_hours * wage_rate) * 2.25
                        normal_hours = (9.0 * wage_rate) * 1.95

                        if 'sunday_plus_twelve' in payslip:
                            payslip['sunday_plus_twelve'] += round(
                                plus_twelve, 3)
                        else:
                            payslip['sunday_plus_twelve'] = round(
                                plus_twelve, 3)

                        if 'sunday_plus_nine' in payslip:
                            payslip['sunday_plus_nine'] += round(plus_nine, 3)
                        else:
                            payslip['sunday_plus_nine'] = round(plus_nine, 3)

                        if 'sunday_normal' in payslip:
                            payslip['sunday_normal'] += round(normal_hours, 3)
                        else:
                            payslip['sunday_normal'] = round(normal_hours, 3)

                    elif nett_hours > timedelta(hours=9) <= timedelta(
                            hours=12):  # shift length 9-12hrs
                        plus_nine_hours = nett_hours - timedelta(hours=9)
                        plus_nine = (plus_nine_hours.total_seconds() / 3600 *
                                     wage_rate) * 2.25
                        normal_hours = (9.0 * wage_rate) * 1.95

                        if 'sunday_plus_nine' in payslip:
                            payslip['sunday_plus_nine'] += round(plus_nine, 3)
                        else:
                            payslip['sunday_plus_nine'] = round(plus_nine, 3)

                        if 'sunday_normal' in payslip:
                            payslip['sunday_normal'] += round(normal_hours, 3)
                        else:
                            payslip['sunday_normal'] = round(normal_hours, 3)

                    else:  # shift length less than 9hrs
                        normal_hours = (nett_hours.total_seconds() / 3600 *
                                        wage_rate) * 1.50

                        if 'sunday_normal' in payslip:
                            payslip['sunday_normal'] += round(normal_hours, 3)
                        else:
                            payslip['sunday_normal'] = round(normal_hours, 3)

                else:  # same logic as above with no break during the shift
                    shift_length = TimeSheet.get_shift_length(shift)

                    if shift_length > timedelta(hours=12):
                        plus_twelve_hours = shift_length - timedelta(hours=12)
                        plus_twelve = (plus_twelve_hours.total_seconds() /
                                       3600 * wage_rate) * 2.25
                        plus_nine_hours = 3.0
                        plus_nine = (plus_nine_hours * wage_rate) * 2.25
                        normal_hours = (9.0 * wage_rate) * 1.95

                        if 'sunday_plus_twelve' in payslip:
                            payslip['sunday_plus_twelve'] += round(
                                plus_twelve, 3)
                        else:
                            payslip['sunday_plus_twelve'] = round(
                                plus_twelve, 3)

                        if 'sunday_plus_nine' in payslip:
                            payslip['sunday_plus_nine'] += round(plus_nine, 3)
                        else:
                            payslip['sunday_plus_nine'] = round(plus_nine, 3)

                        if 'sunday_normal' in payslip:
                            payslip['sunday_normal'] += round(normal_hours, 3)
                        else:
                            payslip['sunday_normal'] = round(normal_hours, 3)

                    elif shift_length > timedelta(hours=9) <= timedelta(
                            hours=12):  # shift length 9-12hrs
                        plus_nine_hours = shift_length - timedelta(hours=9)
                        plus_nine = (plus_nine_hours.total_seconds() / 3600 *
                                     wage_rate) * 2.25
                        normal_hours = (9.0 * wage_rate) * 1.95

                        if 'sunday_plus_nine' in payslip:
                            payslip['sunday_plus_nine'] += round(plus_nine, 3)
                        else:
                            payslip['sunday_plus_nine'] = round(plus_nine, 3)

                        if 'sunday_normal' in payslip:
                            payslip['sunday_normal'] += round(normal_hours, 3)
                        else:
                            payslip['sunday_normal'] = round(normal_hours, 3)

                    else:
                        normal_hours = (shift_length.total_seconds() / 3600 *
                                        wage_rate) * 1.95

                        if 'sunday_normal' in payslip:
                            payslip['sunday_normal'] += round(normal_hours, 3)
                        else:
                            payslip['sunday_normal'] = round(normal_hours, 3)

        return payslip