Exemplo n.º 1
0
    def _add_salary_1(self, values):
        # Input data validation
        # Check required fields
        if not funcs.check_required_fields(values[0], values[1], values[2]):
            return Response(ResponseStatus.fail,
                            strs.REQUIRED_FIELDS_NOT_FILLED_MSG)

        if not funcs.convert_to_int(values, [1, 2]):
            return Response(ResponseStatus.fail, strs.NOT_INTEGER_MSG)

        if values[1] < 0 or values[2] < 0:
            # TODO write to log
            return Response(ResponseStatus.fail, strs.INVALID_MEASURE_MSG)

        if values[1] > values[2]:
            return Response(ResponseStatus.fail,
                            strs.INVALID_NET_GROSS_RATIO_MSG)

        employee_id = self._get_employee_id(values[0])

        if employee_id is None:
            return Response(ResponseStatus.fail, strs.INTERNAL_ERROR_MSG)

        values[0] = employee_id

        return self._database_manager.actions(Actions.add_salary_1, values)
Exemplo n.º 2
0
    def _update_uniform_piece(self, values):
        # Input data validation
        # Check required fields
        if not funcs.check_required_fields(values[1], values[3], values[4],
                                           values[6]):
            return Response(ResponseStatus.fail,
                            strs.REQUIRED_FIELDS_NOT_FILLED_MSG)

        if not funcs.convert_to_int(values, [3, 4]):
            return Response(ResponseStatus.fail, strs.NOT_INTEGER_MSG)

        if values[3] < 0 or values[4] < 0:
            return Response(ResponseStatus.fail, strs.INVALID_MEASURE_MSG)

        uniform_name = self._get_uniform_name(values[1])

        if uniform_name is None:
            # TODO write to log
            return Response(ResponseStatus.fail, strs.INTERNAL_ERROR_MSG)

        response = self._database_manager.actions(Actions.update_uniform_piece,
                                                  values)

        if response.get_status() == ResponseStatus.success:
            for uniform_piece in self._uniform_pieces:
                if uniform_piece.get_uniform_piece_id() == values[0]:
                    uniform_piece.update_data(values)
                    uniform_piece.set_uniform_name(uniform_name)
                    break

        return response
Exemplo n.º 3
0
    def _update_child(self, values):
        # Input data validation
        # Check required fields
        if not funcs.check_required_fields(values[1], values[2], values[4]):
            return Response(ResponseStatus.fail,
                            strs.REQUIRED_FIELDS_NOT_FILLED_MSG)

        if values[6] == "" and values[8] == "":
            return Response(ResponseStatus.fail,
                            strs.CHILD_ONE_PARENT_REQUIRED_MSG)

        mother_id = self._get_employee_id(values[6])
        father_id = self._get_employee_id(values[8])

        if mother_id is None and father_id is None:
            return Response(ResponseStatus.fail, strs.INTERNAL_ERROR_MSG)

        query_values = [
            values[0], values[1], values[2], values[3], values[4], mother_id,
            father_id
        ]
        values[5] = mother_id
        values[7] = father_id

        response = self._database_manager.actions(Actions.update_child,
                                                  query_values)

        if response.get_status() == ResponseStatus.success:
            for child in self._children:
                if child.get_child_id() == values[0]:
                    child.update_data(values)
                    break

        return response
Exemplo n.º 4
0
    def _add_wage(self, values):
        # Input data validation
        # Check required fields
        if not funcs.check_required_fields(values[0], values[1], values[2],
                                           values[3]):
            return Response(ResponseStatus.fail,
                            strs.REQUIRED_FIELDS_NOT_FILLED_MSG)

        if not funcs.convert_to_int(values, [1, 2, 3]):
            return Response(ResponseStatus.fail, strs.NOT_INTEGER_MSG)

        if values[1] < 0 or values[2] < 0 or values[3] < 0:
            # TODO write to log
            return Response(ResponseStatus.fail, strs.INVALID_MEASURE_MSG)

        employee_id = self._get_employee_id(values[0])

        if employee_id is None:
            return Response(ResponseStatus.fail, strs.INTERNAL_ERROR_MSG)

        values[0] = employee_id

        response = self._database_manager.actions(Actions.add_wage, values)

        if response.get_status() == ResponseStatus.success:
            self._wages.append(response.get_data())
            self._update_wages_employees_names([-1])

        return response
Exemplo n.º 5
0
    def _add_free_days(self, values):
        # Input data validation
        # Check required fields
        if not funcs.check_required_fields(values[0], values[4]):
            return Response(ResponseStatus.fail,
                            strs.REQUIRED_FIELDS_NOT_FILLED_MSG)

        if values[3] <= 0:
            return Response(ResponseStatus.fail, strs.INVALID_DATES_MSG)

        employee_id = self._get_employee_id(values[0])

        if employee_id is None:
            return Response(ResponseStatus.fail, strs.INTERNAL_ERROR_MSG)

        values[0] = employee_id

        response = self._database_manager.actions(Actions.add_free_days,
                                                  values)

        if response.get_status() == ResponseStatus.success:
            self._all_free_days.append(response.get_data())
            self._update_free_days_employees_names([-1])

        return response
Exemplo n.º 6
0
    def _add_uniform(self, values):
        # Input data validation
        # Check required fields
        if not funcs.check_required_fields(values[0]):
            return Response(ResponseStatus.fail,
                            strs.REQUIRED_FIELDS_NOT_FILLED_MSG)

        response = self._database_manager.actions(Actions.add_uniform, values)

        if response.get_status() == ResponseStatus.success:
            self._uniforms.append(response.get_data())

        return response
Exemplo n.º 7
0
    def _login(self, values):
        # Input data validation
        if not funcs.check_required_fields(values[0], values[1]):
            return Response(ResponseStatus.fail, strs.MISSING_CREDENTIALS_MSG)

        # Check credentials
        response = self._database_manager.actions(Actions.login, values)

        if response.get_status() == ResponseStatus.success:
            self._user = User.from_values(response.get_data()[0])
            response.set_message(
                strs.SUCCESSFUL_LOGIN_MSG.format(
                    username=self._user.get_username()))

        return response
Exemplo n.º 8
0
    def _update_salary_1(self, values):
        # Input data validation
        # Check required fields
        if not funcs.check_required_fields(values[2], values[3]):
            return Response(ResponseStatus.fail,
                            strs.REQUIRED_FIELDS_NOT_FILLED_MSG)

        if not funcs.convert_to_int(values, [2, 3]):
            return Response(ResponseStatus.fail, strs.NOT_INTEGER_MSG)

        if values[2] < 0 or values[3] < 0:
            # TODO write to log
            return Response(ResponseStatus.fail, strs.INVALID_MEASURE_MSG)

        if values[2] > values[3]:
            return Response(ResponseStatus.fail,
                            strs.INVALID_NET_GROSS_RATIO_MSG)

        return self._database_manager.actions(Actions.update_salary_1, values)
Exemplo n.º 9
0
    def _update_employee(self, values):
        # Input data validation
        # Check required fields
        if not funcs.check_required_fields(values[1], values[2], values[4],
                                           values[7], values[9]):
            return Response(ResponseStatus.fail,
                            strs.REQUIRED_FIELDS_NOT_FILLED_MSG)

        # Check before m fields
        before_m = values[11]

        if not funcs.convert_to_int(before_m, range(3)):
            return Response(ResponseStatus.fail, strs.NOT_INTEGER_MSG)

        years = before_m[0]
        months = before_m[1]
        days = before_m[2]

        if years < 0 or months < 0 or months > 11 or days < 0 or days > 30:
            # TODO write to log
            return Response(ResponseStatus.fail, strs.INVALID_DATE_FORMAT_MSG)

        values[11] = funcs.to_days(years, months, days)

        position_id = self._get_position_id(values[7])

        # Check position id
        if position_id is None:
            # TODO write to log
            return Response(ResponseStatus.fail, strs.INTERNAL_ERROR_MSG)

        values[7] = position_id

        response = self._database_manager.actions(Actions.update_employee,
                                                  values)

        if response.get_status() == ResponseStatus.success:
            for employee in self._employees:
                if employee.get_employee_id() == values[0]:
                    employee.update_data(values)
                    break

        return response
Exemplo n.º 10
0
    def _update_free_days(self, values):
        # Input data validation
        # Check required fields
        if not funcs.check_required_fields(values[5]):
            return Response(ResponseStatus.fail,
                            strs.REQUIRED_FIELDS_NOT_FILLED_MSG)

        if values[4] <= 0:
            return Response(ResponseStatus.fail, strs.INVALID_DATES_MSG)

        response = self._database_manager.actions(Actions.update_free_days,
                                                  values)

        if response.get_status() == ResponseStatus.success:
            for free_days in self._all_free_days:
                if free_days.get_free_days_id() == values[0]:
                    free_days.update_data(values)
                    break

        return response
Exemplo n.º 11
0
    def _update_wage(self, values):
        # Input data validation
        # Check required fields
        if not funcs.check_required_fields(values[2], values[3], values[4]):
            return Response(ResponseStatus.fail,
                            strs.REQUIRED_FIELDS_NOT_FILLED_MSG)

        if not funcs.convert_to_int(values, [2, 3, 4]):
            return Response(ResponseStatus.fail, strs.NOT_INTEGER_MSG)

        if values[2] < 0 or values[3] < 0 or values[4] < 0:
            # TODO write to log
            return Response(ResponseStatus.fail, strs.INVALID_MEASURE_MSG)

        response = self._database_manager.actions(Actions.update_wage, values)

        if response.get_status() == ResponseStatus.success:
            for wage in self._wages:
                if wage.get_wage_id() == values[0]:
                    wage.update_data(values)
                    break

        return response
Exemplo n.º 12
0
    def _update_position(self, values):
        # Input data validation
        # Check required fields
        if not funcs.check_required_fields(values[1], values[2]):
            return Response(ResponseStatus.fail,
                            strs.REQUIRED_FIELDS_NOT_FILLED_MSG)

        position_id = self._get_position_id(values[0])

        if position_id is None:
            return Response(ResponseStatus.fail, strs.INTERNAL_ERROR_MSG)

        values[0] = position_id
        response = self._database_manager.actions(Actions.update_position,
                                                  values)

        if response.get_status() == ResponseStatus.success:
            for position in self._positions:
                if position.get_position_id() == values[0]:
                    position.update_data(values)
                    break

        return response
Exemplo n.º 13
0
    def _update_uniform(self, values):
        # Input data validation
        # Check required fields
        if not funcs.check_required_fields(values[1]):
            return Response(ResponseStatus.fail,
                            strs.REQUIRED_FIELDS_NOT_FILLED_MSG)

        uniform_id = self._get_uniform_id(values[0])

        if uniform_id is None:
            # TODO write to log
            return Response(ResponseStatus.fail, strs.INTERNAL_ERROR_MSG)

        values[0] = uniform_id
        response = self._database_manager.actions(Actions.update_uniform,
                                                  values)

        if response.get_status() == ResponseStatus.success:
            for uniform in self._uniforms:
                if uniform.get_uniform_id() == uniform_id:
                    uniform.set_name(values[1])
                    break

        return response
Exemplo n.º 14
0
    def _add_child(self, values):
        # Input data validation
        # Check required fields
        if not funcs.check_required_fields(values[0], values[1], values[3]):
            return Response(ResponseStatus.fail,
                            strs.REQUIRED_FIELDS_NOT_FILLED_MSG)

        mother_id = self._get_employee_id(values[4])
        father_id = self._get_employee_id(values[5])

        if mother_id is None and father_id is None:
            return Response(ResponseStatus.fail,
                            strs.CHILD_ONE_PARENT_REQUIRED_MSG)

        values[4] = mother_id
        values[5] = father_id

        response = self._database_manager.actions(Actions.add_child, values)

        if response.get_status() == ResponseStatus.success:
            self._children.append(response.get_data())
            self._update_children_parents([-1])

        return response