コード例 #1
0
    def all_reimbursements(self, employee_id):

        self.proj_one_log("Attempting to get all reimbursements...")

        sql = "select * from reimbursements where employee_id = %s"

        if employee_id == -1:
            sql = "select * from reimbursements"
            cursor = connection.cursor()
            cursor.execute(sql)
        else:
            cursor = connection.cursor()
            cursor.execute(sql, [
                employee_id
            ])

        records = cursor.fetchall()
        reimbursement_list = []

        for record in records:

            reimbursement = Reimbursement(
                record[0], record[1], record[2], float(str(record[3])),
                record[4], record[5], record[6], record[7],
                record[8], record[9]
            )
            reimbursement_list.append(reimbursement.json())

        if records:
            return reimbursement_list
        else:
            raise ResourceNotFound("Employee or reimbursement(s) not found.")
コード例 #2
0
    def create_reimbursement(self, new_rbmt):

        self.proj_one_log("Attempting to create reimbursement...")

        sql = "insert into reimbursements values (" + \
              "DEFAULT, %s, %s, %s, %s, %s, %s, " + \
              "%s, %s, %s) returning *"  # Last 3 values are dates.

        cursor = connection.cursor()
        cursor.execute(sql, [
            new_rbmt.employee_id,
            new_rbmt.class_type,
            new_rbmt.funds,
            new_rbmt.approval_stage,
            new_rbmt.stage_reason,
            new_rbmt.grade_or_presentation,
            new_rbmt.date_of_last_escalation,
            new_rbmt.date_requested,
            new_rbmt.date_starting
        ])

        connection.commit()
        record = cursor.fetchone()

        return Reimbursement(
            record[0], record[1], record[2], float(str(record[3])),
            record[4], record[5], record[6], record[7],
            record[8], record[9]
        )
コード例 #3
0
    def get_reimbursement(self, employee_id, reimbursement_id):

        self.proj_one_log("Attempting to get reimbursement...")

        sql = "select * from reimbursements where employee_id = %s and id = %s"

        cursor = connection.cursor()
        cursor.execute(sql, [
            employee_id, reimbursement_id
        ])

        record = cursor.fetchone()

        if record:
            return Reimbursement(
                record[0], record[1], record[2], float(str(record[3])),
                record[4], record[5], record[6], record[7],
                record[8], record[9]
            )
        else:
            raise ResourceNotFound("Reimbursement not found.")
コード例 #4
0
    def update_reimbursement(self, rmbt):

        self.proj_one_log("Attempting to update reimbursement...")

        sql = "update reimbursements set     " + \
              "class_type              = %s, " + \
              "funds                   = %s, " + \
              "approval_stage          = %s, " + \
              "stage_reason            = %s, " + \
              "grade_or_presentation   = %s, " + \
              "date_of_last_escalation = %s, " + \
              "date_requested          = %s, " + \
              "date_starting           = %s  " + \
              "where id = %s returning *"

        cursor = connection.cursor()
        cursor.execute(sql, [
            rmbt.class_type,
            rmbt.funds,
            rmbt.approval_stage,
            rmbt.stage_reason,
            rmbt.grade_or_presentation,
            rmbt.date_of_last_escalation,
            rmbt.date_requested,
            rmbt.date_starting,
            rmbt.id
        ])

        connection.commit()
        record = cursor.fetchone()

        if record:
            return Reimbursement(
                record[0], record[1], record[2], float(str(record[3])),
                record[4], record[5], record[6], record[7],
                record[8], record[9]
            )
        else:
            raise ResourceNotFound("Reimbursement not found.")
コード例 #5
0
    def update_reimbursement():
        try:
            reimbursement = Reimbursement()

            reimbursement.id = \
                int(request.form.get('id'))
            reimbursement.employee_id = \
                int(current_user.id)
            reimbursement.class_type = \
                request.form.get('classType')
            reimbursement.funds = \
                float(str(request.form.get('funds')))

            # Build approval stage:

            reimbursement.approval_stage = int(
                request.form.get('approvalStage'))

            if request.form.get('approvalCheck'):
                reimbursement.approval_stage += 1
                if reimbursement.approval_stage < 0:
                    reimbursement.approval_stage = 0
                if reimbursement.approval_stage > 5:
                    reimbursement.approval_stage = 5

            if not request.form.get('approvalCheck'):
                if 0 <= reimbursement.approval_stage < 5:
                    reimbursement.approval_stage += 1
                    reimbursement.approval_stage *= -1

            # Build new stage reason:

            reimbursement.stage_reason = request.form.get('stageReason')

            if not reimbursement.approval_stage \
                   == int(request.form.get('approvalStage')):

                prefix = str(reimbursement.approval_stage) + " ("

                if reimbursement.approval_stage == 0: prefix += "Requested"
                if reimbursement.approval_stage == 1:
                    prefix += "Approved, Req. Grading"
                if reimbursement.approval_stage == 2:
                    prefix += "Approval Email Provided"
                if reimbursement.approval_stage == 3:
                    prefix += "Approved By Supervisor"
                if reimbursement.approval_stage == -3:
                    prefix += "Rejected By Supervisor"
                if reimbursement.approval_stage == 4:
                    prefix += "Approved By Dept. Head"
                if reimbursement.approval_stage == -4:
                    prefix += "Rejected By Dept. Head"
                if reimbursement.approval_stage == 5:
                    prefix += "Approved, Awarded"
                if reimbursement.approval_stage == -5:
                    prefix += "Rejected By BenCo"
                prefix += "):(br)" + str(
                    request.form.get('approvalText')) + "(br)(br)"

                reimbursement.stage_reason = prefix + reimbursement.stage_reason

                if len(reimbursement.stage_reason) > 500:
                    reimbursement.stage_reason = reimbursement.stage_reason[
                        0:497] + "..."

            # End

            reimbursement.grade_or_presentation = \
                request.form.get('gradeOrPresentation')

            reimbursement.date_of_last_escalation = \
                int(str(request.form.get('dateRequested')).replace("-", ""))
            reimbursement.date_requested = \
                int(str(request.form.get('dateRequested')).replace("-", ""))
            reimbursement.date_starting = \
                int(str(request.form.get('dateStarting')).replace("-", ""))

            RS.update_reimbursement(reimbursement)

            return jsonify(reimbursement.json()), 200

        except ResourceNotFound as r:
            return r.message, 404
コード例 #6
0
    def post_reimbursement(empy_id):

        reimbursement = Reimbursement()

        reimbursement.employee_id = \
            int(empy_id)
        reimbursement.class_type = \
            request.form.get('classType')
        reimbursement.funds = \
            float(str(request.form.get('funds')))
        reimbursement.stage_reason = \
            "0 (Req. by " + request.form.get('name') + \
            "):(br)" + request.form.get('eventInfo')
        reimbursement.grade_or_presentation = \
            request.form.get('gradeOrPresentation')

        reimbursement.date_of_last_escalation = \
            int(str(request.form.get('dateRequested')).replace("-", ""))
        reimbursement.date_requested = \
            int(str(request.form.get('dateRequested')).replace("-", ""))
        reimbursement.date_starting = \
            int(str(request.form.get('dateStarting')).replace("-", ""))

        reimbursement = RS.create_reimbursement(reimbursement)

        return jsonify(reimbursement.json()), 201
コード例 #7
0
    def rmbts_req_user_attn(self, user_id):

        self.proj_one_log("Getting user's pos. in company hierarchy...")

        boss_chain_length = 0
        employee_id = user_id

        while employee_id != -1:
            sql = "select supervisor_id from employees where id = %s"
            cursor = connection.cursor()
            cursor.execute(sql, [
                int(employee_id)
            ])
            record = cursor.fetchone()

            employee_id = record[0]
            if employee_id != -1:
                boss_chain_length += 1

    # # Boss chain length acquired: 0 = Dept. Head, 1 = Supervisor, 2 = Peon """

        self.proj_one_log("Getting all of user's underlings...")

        underlings = []
        underling_search_count = 0

        while underling_search_count < 2 - boss_chain_length:
            sql = "select id from employees where supervisor_id = %s"
            if underling_search_count > 0:
                sql = "select id from employees where not supervisor_id = %s "
                for underling in underlings:
                    sql += "and supervisor_id = " + str(int(underling))

            cursor = connection.cursor()
            cursor.execute(sql, [
                int(user_id)
            ])

            records = cursor.fetchall()
            for record in records:
                underlings.append(record[0])

            underling_search_count += 1

    # # All of user's underlings acquired.

        self.proj_one_log("Getting reimbursements req. user's attention...")

        rmbts_req_attn = []

        for underling in underlings:

            sql = "select * from reimbursements where " + \
                  "employee_id = %s and " + \
                  "approval_stage = %s"
            cursor = connection.cursor()
            cursor.execute(sql, [
                int(underling), int(3 - boss_chain_length)
            ])

            records = cursor.fetchall()
            for record in records:
                rmbt = Reimbursement(
                    record[0], record[1], record[2], float(str(record[3])),
                    record[4], record[5], record[6], record[7],
                    record[8], record[9]
                )
                rmbts_req_attn.append(rmbt.json())

        return rmbts_req_attn
コード例 #8
0
 def test_reimbursement_model(self):
     class_cash = Reimbursement(funds=3333.33)
     self.assertEqual(isinstance(class_cash, Reimbursement), True)