Exemplo n.º 1
0
def find_employee_all_info_by_name(first_name, last_name):
    employee = Employee.find_employee_by_name(first_name, last_name)
    if employee:
        result = Employee.find_employee_all_info_by_id(employee['employee_id'])
    else:
        return None
    return result
Exemplo n.º 2
0
def delete_salary(request):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    employee = EmployeeIdentifier()

    if request.method == 'POST':
        employee = EmployeeIdentifier(request.POST)
        if employee.is_valid():
            cleaned_data = employee.cleaned_data
            if cleaned_data.get('id'):
                target_employee = Employee.find_employee_all_info_by_id(
                    cleaned_data.get('id'))
                if target_employee:
                    return render(request, 'delete/salary_employee.html',
                                  {'employee': target_employee})

            if cleaned_data.get('first_name') and cleaned_data.get(
                    'last_name'):
                target_employee = Employee.find_employee_by_name(
                    cleaned_data.get('first_name'),
                    cleaned_data.get('last_name'))
                target_employee = Employee.find_employee_all_info_by_id(
                    target_employee['employee_id'])
                if target_employee:
                    return render(request, 'delete/salary_employee.html',
                                  {'employee': target_employee})

            messages.error(request, "No such employee.")

    return render(request, 'delete/before_search.html', {'employee': employee})
Exemplo n.º 3
0
def delete_salary_record(request, employee_id, salary_id):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    salary = Salary.objects.filter(id=salary_id)
    if salary:
        salary = salary[0]
        try:
            Salary.update_previous_later_salary_dates_when_delete(
                employee_id, salary_id)
            salary.delete()
            return render(request, 'delete/salary_success.html',
                          {'employee_id': employee_id})
        except IntegrityError as e:
            messages.error(
                request,
                "This salary record is referenced through restricted foreign keys."
            )
    else:
        messages.error(request, "No such salary record.")

    salary_history = Salary.find_salary_history_by_id(employee_id)
    employee = Employee.find_employee_by_id(employee_id)
    return render(request, 'delete/salary.html', {
        'salary_history': salary_history,
        'employee': employee
    })
Exemplo n.º 4
0
def read_employee_title(request, employee_id):
    employee = Employee.find_employee_by_id(employee_id)
    title_history = JobTitle.find_title_history_by_id(employee_id)
    return render(request, 'read/show_title_history.html', {
        'title_history': title_history,
        'employee': employee
    })
Exemplo n.º 5
0
def delete_title_record(request, employee_id, title_id):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    title = JobTitle.objects.filter(id=title_id)
    if title:
        title = title[0]
        try:
            JobTitle.update_previous_later_title_dates_when_delete(
                employee_id, title_id)
            title.delete()
            return render(request, 'delete/title_success.html',
                          {'employee_id': employee_id})
        except IntegrityError:
            messages.error(
                request,
                "This title record is referenced through restricted foreign keys."
            )
    else:
        messages.error(request, "No such title record.")
    title_history = JobTitle.find_title_history_by_id(employee_id)
    employee = Employee.find_employee_by_id(employee_id)
    return render(request, 'delete/title.html', {
        'title_history': title_history,
        'employee': employee
    })
Exemplo n.º 6
0
def delete_assignment_record(request, employee_id, assignment_id):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    assignment = EmployeeWorksAt.objects.filter(id=assignment_id)
    if assignment:
        assignment = assignment[0]
        try:
            EmployeeWorksAt.update_previous_later_assignment_dates_when_delete(
                employee_id, assignment_id)
            assignment.delete()
            return render(request, 'delete/assignment_success.html',
                          {'employee_id': employee_id})
        except IntegrityError:
            messages.error(
                request,
                "This assignment record is referenced through restricted foreign keys."
            )
    else:
        messages.error(request, "No such assignment record.")

    assignment_history = EmployeeWorksAt.find_assignment_history_by_id(
        employee_id)
    employee = Employee.find_employee_by_id(employee_id)
    return render(request, 'delete/assignment.html', {
        'assignment_history': assignment_history,
        'employee': employee
    })
def create_assignment(request):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    # check if there are employee records
    all_employees = Employee.find_all_employees()
    if not all_employees:
        messages.error(request, 'No employee record found in the system!')

    # check if there are employee records
    all_departments = Department.find_all_departments()
    if not all_departments:
        messages.error(request, 'No department record found in the system!')

    new_assignment = NewAssignment()

    if request.method == 'POST':
        new_assignment = NewAssignment(request.POST)
        if new_assignment.is_valid():
            cleaned_data = new_assignment.cleaned_data
            e_id = cleaned_data['employee_']
            d_id = cleaned_data['department_']
            EmployeeWorksAt.update_assignment_to_date(
                e_id, cleaned_data['from_date'])
            new_assignment_record = EmployeeWorksAt()
            new_assignment_record.employee = Employee.objects.get(pk=e_id)
            new_assignment_record.department = Department.objects.get(pk=d_id)
            new_assignment_record.from_date = cleaned_data['from_date']
            new_assignment_record.to_date = cleaned_data['to_date']
            # update the old to_date
            new_assignment_record.save()
            return render(request, 'create/assignment_success.html.html')

    return render(request, 'create/assignment.html',
                  {'new_assignment': new_assignment})
def create_title(request):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    # check if there are employee records
    all_employees = Employee.find_all_employees()
    if not all_employees:
        messages.error(request, 'No employee record found in the system!')

    new_title = NewTitle()

    if request.method == 'POST':
        new_title = NewTitle(request.POST)
        if new_title.is_valid():
            cleaned_data = new_title.cleaned_data
            e_id = cleaned_data['current_employee']
            new_title_record = JobTitle()
            new_title_record.employee = Employee.objects.get(pk=e_id)
            new_title_record.from_date = cleaned_data['from_date']
            new_title_record.to_date = cleaned_data['to_date']
            new_title_record.title = cleaned_data['title']
            # update the old to_date
            JobTitle.update_title_to_date(e_id, cleaned_data['from_date'])
            new_title_record.save()
            return render(request, 'create/title_success.html')

    return render(request, 'create/title.html', {'new_title': new_title})
Exemplo n.º 9
0
def read_employee_assignment(request, employee_id):
    employee = Employee.find_employee_by_id(employee_id)
    assignment_history = EmployeeWorksAt.find_assignment_history_by_id(
        employee_id)
    return render(request, 'read/show_assignment.html', {
        'assignment_history': assignment_history,
        'employee': employee
    })
def get_all_employees():
    all_employees = Employee.find_all_employees()
    if not all_employees:
        employees = [('', '')]
    else:
        employees = [(i['employee_id'], i['first_name'] + " " + i['last_name'])
                     for i in all_employees]
    return employees
Exemplo n.º 11
0
def delete_employee(request):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    all_employees = Employee.find_all_employees()

    return render(request, 'delete/employee.html',
                  {'employees': all_employees})
Exemplo n.º 12
0
def delete_title_history(request, employee_id):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    title_history = JobTitle.find_title_history_by_id(employee_id)
    employee = Employee.find_employee_by_id(employee_id)

    return render(request, 'delete/title.html', {
        'title_history': title_history,
        'employee': employee
    })
Exemplo n.º 13
0
def delete_salary_history(request, employee_id):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    salary_history = Salary.find_salary_history_by_id(employee_id)
    employee = Employee.find_employee_by_id(employee_id)

    return render(request, 'delete/salary.html', {
        'salary_history': salary_history,
        'employee': employee
    })
Exemplo n.º 14
0
def delete_assignment_history(request, employee_id):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    assignment_history = EmployeeWorksAt.find_assignment_history_by_id(
        employee_id)
    employee = Employee.find_employee_by_id(employee_id)

    return render(request, 'delete/assignment.html', {
        'assignment_history': assignment_history,
        'employee': employee
    })
Exemplo n.º 15
0
def read_employee_salary(request, employee_id):
    """
    Read salary history for a specific employee by id.
    :param request: http request
    :param employee_id: the target employee id
    :return: page render result
    """
    employee = Employee.find_employee_by_id(employee_id)
    salary_history = Salary.find_salary_history_by_id(employee_id)
    return render(request, 'read/show_salary_history.html', {
        'salary_history': salary_history,
        'employee': employee
    })
Exemplo n.º 16
0
def update_assignment(request, employee_id, assignment_id):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    employee = Employee.find_employee_by_id(employee_id)
    current_assignment = EmployeeWorksAt.objects.filter(id=assignment_id)
    assignment = UpdateAssignment()
    if current_assignment:
        current_assignment = current_assignment[0]
        initial_data = {
            'department': current_assignment.department,
            'employee': current_assignment.employee,
            'from_date': current_assignment.from_date,
            'to_date': current_assignment.to_date
        }
        assignment = UpdateAssignment(initial=initial_data)
    else:
        messages.error(request, "No such assignment record.")

    if request.method == 'POST':
        assignment = UpdateAssignment(request.POST,
                                      instance=current_assignment)
        if assignment.is_valid():
            cleaned_data = assignment.cleaned_data
            current_assignment.department = cleaned_data['department']
            current_assignment.employee = cleaned_data['employee']
            current_assignment.from_date = cleaned_data['from_date']
            current_assignment.to_date = cleaned_data['to_date']
            EmployeeWorksAt.update_previous_later_assignment_dates(
                employee_id, assignment_id, cleaned_data['from_date'],
                cleaned_data['to_date'])
            current_assignment.save()
            return render(request, 'update/assignment_success.html',
                          {'employee_id': employee_id})

    return render(request, 'update/assignment.html', {
        'assignment': assignment,
        'employee': employee
    })
Exemplo n.º 17
0
def update_title(request, employee_id, title_id):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    employee = Employee.find_employee_by_id(employee_id)
    current_title = JobTitle.objects.filter(id=title_id)
    title = UpdateTitle()
    if current_title:
        current_title = current_title[0]
        initial_data = {
            'title': current_title.title,
            'employee': current_title.employee,
            'from_date': current_title.from_date,
            'to_date': current_title.to_date
        }
        title = UpdateTitle(initial=initial_data)
    else:
        messages.error(request, "No such title record.")

    if request.method == 'POST':
        title = UpdateTitle(request.POST, instance=current_title)
        if title.is_valid():
            cleaned_data = title.cleaned_data
            current_title.title = cleaned_data['title']
            current_title.from_date = cleaned_data['from_date']
            current_title.to_date = cleaned_data['to_date']
            JobTitle.update_previous_later_title_dates(
                employee_id, title_id, cleaned_data['from_date'],
                cleaned_data['to_date'])
            current_title.save()
            return render(request, 'update/title_success.html',
                          {'employee_id': employee_id})

    return render(request, 'update/title.html', {
        'title': title,
        'title_id': title,
        'employee': employee
    })
Exemplo n.º 18
0
def update_salary(request, employee_id, salary_id):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    employee = Employee.find_employee_by_id(employee_id)
    current_salary = Salary.objects.filter(id=salary_id)
    salary = UpdateSalary()
    if current_salary:
        current_salary = current_salary[0]
        initial_data = {
            'amount': current_salary.amount,
            'from_date': current_salary.from_date,
            'to_date': current_salary.to_date,
            'employee': current_salary.employee
        }
        salary = UpdateSalary(initial=initial_data)
    else:
        messages.error(request, "No such salary record.")

    if request.method == 'POST':
        salary = UpdateSalary(request.POST, instance=current_salary)
        if salary.is_valid():
            cleaned_data = salary.cleaned_data
            current_salary.amount = cleaned_data['amount']
            current_salary.from_date = cleaned_data['from_date']
            current_salary.to_date = cleaned_data['to_date']
            Salary.update_previous_later_salary_dates(
                employee_id, salary_id, cleaned_data['from_date'],
                cleaned_data['to_date'])
            current_salary.save()
            return render(request, 'update/salary_success.html',
                          {'employee_id': employee_id})

    return render(request, 'update/salary.html', {
        'salary': salary,
        'salary_id': salary_id,
        'employee': employee
    })
Exemplo n.º 19
0
def delete_employee_record(request, employee_id):
    if not has_admin_access(request):
        return HttpResponseRedirect(reverse('guest'))

    all_employees = Employee.find_all_employees()
    employee = Employee.objects.filter(id=employee_id)
    if employee:
        employee = employee[0]
    else:
        messages.error(request, "No such employee.")
        return render(request, 'delete/employee.html',
                      {'employees': all_employees})

    try:
        employee.delete()
        return render(request, 'delete/employee_success.html')
    except IntegrityError:
        messages.error(
            request,
            "Employee '{} {}' is referenced through restricted foreign keys.".
            format(employee.first_name, employee.last_name))
        return render(request, 'delete/employee.html',
                      {'employees': all_employees})
Exemplo n.º 20
0
def read_employee(request):
    forms = EmployeeIdentifier()

    if request.method == 'POST':
        forms = EmployeeIdentifier(request.POST)
        if forms.is_valid():
            cleaned_data = forms.cleaned_data
            result = None
            if cleaned_data.get('id'):
                e_id = cleaned_data.get('id')
                result = Employee.find_employee_all_info_by_id(e_id)
                if result:
                    return render(request, 'read/show_employee_result.html',
                                  {'employee': result})
            if cleaned_data.get('first_name') and cleaned_data.get(
                    'last_name'):
                first_name = cleaned_data.get('first_name')
                last_name = cleaned_data.get('last_name')
                result = find_employee_all_info_by_name(first_name, last_name)
            return render(request, 'read/show_employee_result.html',
                          {'employee': result})

    return render(request, 'read/read_employee.html', {'forms': forms})
Exemplo n.º 21
0
def read_employee_all(request):
    employees = Employee.find_all_employees()
    return render(request, 'read/show_all_employees.html',
                  {'employees': employees})
Exemplo n.º 22
0
def read_employee_info(request, employee_id):
    employee = Employee.find_employee_all_info_by_id(employee_id)
    return render(request, 'read/show_employee_result.html',
                  {'employee': employee})