コード例 #1
0
def add_a_department():
    # Admin add a department of the company
    if request.method == 'POST':
        company_id = get_by_email_company_id()
        name = request.form['name']

        # add_department(company_id, name)
        Department.add_department(company_id, name)
    return render_template('admins/add_department.html')
コード例 #2
0
def view_directors_admin(sort_type, filter_type):
    # Displays directors of the company to the admin
    company_id = get_by_email_company_id()
    departments = view_departments(company_id)
    response = []
    directors_response = []
    department_response = []

    for department in departments:
        department_response.append(department)

    if filter_type.startswith("department"):
        department_id = filter_type[10:]
        # directors = get_directors_by_department(department_id)
        directors = Director.get_by_department_id(department_id)
        department = get_department(department_id)
        res = {}
        res['department_id'] = department_id
        res['department_name'] = department['name']
        res['directors'] = []
        append_director = []
        for director in directors:
            print(director)
            append_director.append(director)

        if sort_type != "default":
            res['directors'] = sorted(append_director, key=lambda k: k[sort_type])
        else:
            res['directors'] = append_director
        response.append(res)
    else:
        for department in department_response:
            res={}
            dept = department['_id']
            res['department_id'] = dept
            res['department_name'] = department['name']
            res['directors'] = []
            append_director = []
            # directors = get_directors_by_department(dept)
            directors = Director.get_by_department_id(dept)

            for director in directors:
                if filter_type != "default" and filter_type == director['name']:
                    append_director.append(director)
                elif filter_type == "default":
                    append_director.append(director)
                if director['name'] not in directors_response:
                    directors_response.append(director['name'])

            if sort_type != "default":
                res['directors'] = sorted(append_director, key=lambda k: k[sort_type])
            else:
                res['directors'] = append_director
            response.append(res)

    response = sorted(response, key=lambda k: k['department_name'])
    return render_template('admins/show_directors.html', response=response, department_response=department_response, directors_response=directors_response, sort_type=sort_type, filter_type=filter_type)
コード例 #3
0
def view_employees_admin(sort_type, filter_type):
    # Displays employees of the company to the admin
    company_id = get_by_email_company_id()
    departments = view_departments(company_id)
    response = []
    department_response = []
    for department in departments:
        department_response.append(department)

    if filter_type.startswith("department"):
        department_id = filter_type[10:]
        # employees = get_by_department_id(department_id)
        employees = Employee.get_by_department_id(department_id)
        department = get_department(department_id)
        res={}
        res['department_id'] = department_id
        res['department_name'] = department['name']
        res['employees'] = []
        append_employees = []

        for employee in employees:
            append_employees.append(employee)

        if sort_type != "default":
            res['employees'] = sorted(append_employees, key=lambda k: k[sort_type])
        else:
            res['employees'] = append_employees
        response.append(res)
    else:
        # for department in departments:
        #     print(department) - I am unable to use departments again for iterating why so in python?
        for department in department_response:
            res={}
            res['department_id'] = department['_id']
            res['department_name'] = department['name']
            res['employees'] = []
            append_employees = []

            # employees = get_by_department_id(department['_id'])
            employees = Employee.get_by_department_id(department['_id'])
            for employee in employees:
                append_employees.append(employee)

            if sort_type != "default":
                res['employees'] = sorted(append_employees, key=lambda k: k[sort_type])
            else:
                res['employees'] = append_employees

            response.append(res)

    response = sorted(response, key=lambda k: k['department_name'])
    return render_template('admins/show_employees.html', response=response, department_response=department_response, sort_type=sort_type, filter_type=filter_type)
コード例 #4
0
def add_a_bill_type():
    # Admin add a bill-type of the company
    company_id = get_by_email_company_id()
    departments = view_departments(company_id)
    if request.method == 'POST':
        department_id = request.form['department_id']
        type = request.form['type']
        reimbursement = request.form['reimbursement']

        # add_bill_type(department_id, type, reimbursement)
        BillType.add_bill_type(department_id, type, reimbursement)

    return render_template('admins/add_bill_type.html',
                           departments=departments)
コード例 #5
0
def add_a_director():
    # Admin add a director of the company
    company_id = get_by_email_company_id()
    departments = view_departments(company_id)

    if request.method == 'POST':
        email = request.form['email']
        name = request.form['name']
        designation = request.form['designation']
        department_id = request.form['department_id']
        date_of_joining = request.form['date_of_joining']

        Director.add_a_director(company_id, email, name, designation, department_id, date_of_joining)

    return render_template('admins/add_director.html', departments=departments)
コード例 #6
0
def add_employee():
    # Admin add a employee of the company
    company_id = get_by_email_company_id()
    departments = view_departments(company_id)

    if request.method == 'POST':
        email = request.form['email']
        name = request.form['name']
        designation = request.form['designation']
        department_id = request.form['department_id']
        date_of_joining = request.form['date_of_joining']
        monthly_salary = request.form['monthly_salary']

        Employee.add_an_employee(company_id, email, name, designation, department_id, date_of_joining, monthly_salary)

    return render_template('admins/add_employee.html', departments=departments)
コード例 #7
0
def view_bill_types_admin(sort_type, filter_type):
    # Displays bill-type of the company to the admin
    company_id = get_by_email_company_id()
    departments = view_departments(company_id)
    response = []
    types = []
    department_response = []

    for department in departments:
        department_response.append(department)

    if filter_type.startswith("department"):
        department_id = filter_type[10:]
        bills_type = get_bills_type_by_department(department_id)
        department = get_department(department_id)
        res = {}
        res['department_id'] = department_id
        res['department_name'] = department['name']
        res['bills_type'] = []
        billtypes = []

        for billtype in bills_type:
            billtypes.append(billtype)
            if billtype['type'] not in types:
                types.append(billtype['type'])

        if sort_type != "default":
            res['bills_type'] = sorted(billtypes, key=lambda k: k[sort_type])
        else:
            res['bills_type'] = billtypes
        response.append(res)
    else:
        for department in department_response:
            res = {}
            res['department_id'] = department['_id']
            res['department_name'] = department['name']
            res['bills_type'] = []
            billtypes = []

            bills_type = get_bills_type_by_department(department['_id'])

            for billtype in bills_type:
                if filter_type != "default" and filter_type == billtype['type']:
                    billtypes.append(billtype)
                elif filter_type == "default":
                    billtypes.append(billtype)
                if billtype['type'] not in types:
                    types.append(billtype['type'])

            if sort_type != "default":
                res['bills_type'] = sorted(billtypes,
                                           key=lambda k: k[sort_type])
            else:
                res['bills_type'] = billtypes
            response.append(res)

    response = sorted(response,
                      key=lambda k: k['department_name'])  #alphabetical order

    return render_template('admins/show_bill_types.html',
                           response=response,
                           department_response=department_response,
                           types=types,
                           sort_type=sort_type,
                           filter_type=filter_type)
コード例 #8
0
def view_managers_admin(sort_type, filter_type):
    # Displays managers of the company to the admin

    company_id = get_by_email_company_id()
    #managers = view_managers(company_id)
    departments = view_departments(company_id)
    response = []
    managers_response = []
    department_response = []

    for department in departments:
        department_response.append(department)

    if filter_type.startswith("department"):
        department_id = filter_type[10:]
        # managers = get_managers_by_department(department_id)
        managers = Manager.get_by_department_id(department_id)
        department = get_department(department_id)
        res = {}
        res['department_id'] = department_id
        res['department_name'] = department['name']
        res['managers'] = []
        append_managers = []
        for manager in managers:
            append_managers.append(manager)

        if sort_type != "default":
            res['managers'] = sorted(append_managers,
                                     key=lambda k: k[sort_type])
        else:
            res['managers'] = append_managers
        response.append(res)
    else:
        for department in department_response:
            res = {}
            dept = department['_id']
            res['department_id'] = dept
            res['department_name'] = department['name']
            res['managers'] = []
            append_managers = []
            # managers = get_managers_by_department(dept)
            managers = Manager.get_by_department_id(dept)

            for manager in managers:
                if filter_type != "default" and filter_type == manager['name']:
                    append_managers.append(manager)
                elif filter_type == "default":
                    append_managers.append(manager)
                if manager['name'] not in managers_response:
                    managers_response.append(manager['name'])

            if sort_type != "default":
                res['managers'] = sorted(append_managers,
                                         key=lambda k: k[sort_type])
            else:
                res['managers'] = append_managers
            response.append(res)

    response = sorted(response, key=lambda k: k['department_name'])
    return render_template('admins/show_managers.html',
                           response=response,
                           department_response=department_response,
                           managers_response=managers_response,
                           sort_type=sort_type,
                           filter_type=filter_type)
コード例 #9
0
def view_departments_admin():
    # Displays departments of the company to the admin
    company_id = get_by_email_company_id()
    departments = Department.get_all(company_id)
    return render_template('admins/show_departments.html', departments=departments)