def edit_contract_page(request, contract_id): if request.POST and request.FILES: reference_number = request.POST.get('reference_number') position_id = request.POST.get('position') employee_id = request.POST.get('employee') effective_date = request.POST.get('effective_date') expiry_date = request.POST.get('expiry_date') risk = request.POST.get('risk') document = request.FILES.get('document') position = get_position(position_id) employee = get_employee(employee_id) contract_list = Contract.objects.filter(id=contract_id) contract_list.update(reference_number=reference_number, position=position, employee=employee, effective_date=effective_date, expiry_date=expiry_date, risk=risk, document=document) return HttpResponseRedirect(reverse(manage_job_contracts)) contract = get_contract(contract_id) positions = get_all_positions() employees = get_active_employees() context = { "contracts_page": "active", "contract": contract, "employees": employees, "positions": positions, } return render(request, 'contracts/edit_contract.html', context)
def edit_termination_page(request, termination_id): if request.POST and request.FILES: employee_id = request.POST.get('employee') type = request.POST.get('type') termination_letter = request.FILES.get('termination_letter') clearance_form = request.FILES.get('clearance_form') description = request.POST.get('description') employee = get_employee(employee_id) termination_list = Termination.objects.filter(id=termination_id) try: termination_list.update(employee=employee, type=type, termination_letter=termination_letter, clearance_form=clearance_form, description=description) return HttpResponseRedirect(reverse(manage_terminations_page)) except IntegrityError: messages.warning( request, "Integrity problems with trying to add a new offence") termination = get_termination(termination_id) terminations = get_all_terminations() employees = get_active_employees() context = { "contracts_page": "active", "termination": termination, "terminations": terminations, "employees": employees } return render(request, 'contracts/edit_termination.html', context)
def manage_terminations_page(request): if request.POST: employee_id = request.POST.get('employee') type = request.POST.get('type') termination_letter = request.FILES.get('termination_letter') clearance_form = request.FILES.get('clearance_form') description = request.POST.get('description') employee = get_employee(employee_id) try: new_termination = Termination.objects.create( employee=employee, type=type, termination_letter=termination_letter, clearance_form=clearance_form, description=description) send_notification_generic( employee, "Termination Recorded", "Your termination record has been created") except IntegrityError: messages.warning( request, "Integrity problems with trying to add a new offence") return HttpResponseRedirect(reverse(manage_terminations_page)) terminations = get_all_terminations() employees = get_active_employees() context = { "contracts_page": "active", "employees": employees, "terminations": terminations, } return render(request, 'contracts/manage_terminations.html', context)
def edit_offence_page(request, offence_id): if request.POST: name = request.POST.get('name') employee_id = request.POST.get('employee') penalty_id = request.POST.get('penalty') resolved = request.POST.get('resolved') description = request.POST.get('description') penalty = get_penalty(penalty_id) employee = get_employee(employee_id) offence_list = Offence.objects.filter(id=offence_id) offence_list.update(name=name, penalty=penalty, employee=employee, resolved=resolved, description=description) return HttpResponseRedirect(reverse(manage_offences_page)) offence = get_offence(offence_id) offences = get_all_offences() employees = get_active_employees() penalties = get_all_penalties() context = { "contracts_page": "active", "employees": employees, "offences": offences, "penalties": penalties, "offence": offence } return render(request, 'contracts/edit_offence.html', context)
def manage_offences_page(request): if request.POST: name = request.POST.get('name') employee_id = request.POST.get('employee') penalty_id = request.POST.get('penalty') resolved = request.POST.get('resolved') description = request.POST.get('description') penalty = get_penalty(penalty_id) employee = get_employee(employee_id) try: new_offence = Offence.objects.create(name=name, penalty=penalty, employee=employee, resolved=resolved, description=description) send_notification_generic(employee, "Offence Recorded", "You have a new offence recorded") except IntegrityError: messages.warning( request, "Integrity problems with trying to add a new offence") return HttpResponseRedirect(reverse(manage_offences_page)) offences = get_all_offences() employees = get_active_employees() penalties = get_all_penalties() context = { "contracts_page": "active", "employees": employees, "offences": offences, "penalties": penalties } return render(request, 'contracts/manage_offences.html', context)
def manage_employee_kpi(request, employee_id): employee = get_employee(employee_id) employee_kpis = get_all_employee_kpi(employee=employee) if request.POST: measure_of_success = request.POST.get("measure_of_success") weight = request.POST.get("weight") score = request.POST.get("score") if score > weight: messages.warning(request, "Employee KPI added successfully") return HttpResponseRedirect(reverse(manage_department_kpi)) try: EmployeeKPI.objects.create( measure_of_success=measure_of_success, weight=weight, score=score, employee=employee, ) messages.warning(request, "Employee KPI added successfully") return HttpResponseRedirect( reverse(manage_employee_kpi, args=[employee.id])) except IntegrityError: messages.warning( request, "Integrity problems with trying to add performance KPI") context = { "performance_page": "active", "employee_kpis": employee_kpis, "employee": employee, } return render(request, "performance/manage_employee_kpi.html", context)
def performance_rating_filter(value: int): """Outputs integer with performance score of employee""" employee = get_employee(value) try: return calculate_performance_rating(employee) except: """Broad Exception hides bad behaviour""" return 0
def damage_filter(value: int): """Outputs integer with damage dedution""" employee = get_employee(value) try: deduction = Deduction.objects.get(name="Damage", employee=employee) amount = int(deduction.amount) except Deduction.DoesNotExist: deduction = 0 amount = deduction return amount
def edit_department(request): if request.method == "POST": department_id = request.POST.get('department_id') employee_id = request.POST.get('employee_id') employee = get_employee(employee_id) department = get_department(department_id) department.name = request.POST.get('department_name') department.hod = employee department.save() messages.success(request, f'Department Info Changed Successfully') return redirect('manage_departments_page') messages.error(request, f'Changes Not Saved, Check your inputs and try again!') return redirect('manage_departments_page')
def update_employee_financial_details(csv_obj): with open(csv_obj.file_name.path, 'r') as f: reader = csv.reader(f) employees = [] statutory_deductions = [] non_statutory_deductions = [] for i, row in enumerate(reader): if i < 2: # Ignore first 2 rows pass else: employee_id = row[0] currency_code = row[2] basic_salary = row[3] bonus = row[4] local_service_allowance = row[5] meal_allowance = row[6] sacco = row[7] damage = row[8] salary_advance = row[9] police_fine = row[10] local_service_tax = row[11] employee = get_employee(employee_id) old_statutory_deduction = get_employee_statutory_deduction(employee) old_non_statutory_deduction = get_employee_deduction(employee) currency = get_currency_from_code(currency_code) new_employee = Employee(id=employee_id, currency=currency, basic_salary=basic_salary, bonus=bonus, local_service_tax=local_service_allowance, lunch_allowance=meal_allowance) employees.append(new_employee) new_statutory_deduction = StatutoryDeduction(id=old_statutory_deduction.id, employee=employee, local_service_tax=local_service_tax) statutory_deductions.append(new_statutory_deduction) non_statutory_deduction = Deduction(id=old_non_statutory_deduction.id, employee=employee, sacco=sacco, damage=damage, salary_advance=salary_advance, police_fine=police_fine) non_statutory_deductions.append(non_statutory_deduction) Employee.objects.bulk_update(employees, ['currency', 'basic_salary', 'bonus', 'local_service_tax', 'lunch_allowance']) StatutoryDeduction.objects.bulk_update(statutory_deductions, ['local_service_tax']) Deduction.objects.bulk_update(non_statutory_deductions, ['sacco', 'damage', 'salary_advance', 'police_fine'])
def add_new_department(request): if request.method == "POST": department_name = request.POST["department_name"] employee_id = request.POST["employee_id"] employee = get_employee(employee_id) department = Department.objects.filter(name=department_name) if department: messages.warning(request, f'Department {department_name} Already Exists') return redirect('manage_departments_page') else: department = Department(name=department_name, hod=employee) department.save() messages.success(request, f'Department {department_name} Successfully Saved') return redirect('manage_departments_page') return redirect('manage_departments_page')
def manage_job_contracts(request): if request.POST and request.FILES: reference_number = request.POST.get('reference_number') position_id = request.POST.get('position') employee_id = request.POST.get('employee') effective_date = request.POST.get('effective_date') expiry_date = request.POST.get('expiry_date') risk = request.POST.get('risk') contract_type = request.POST.get('contract_type') document = request.FILES.get('document') position = get_position(position_id) employee = get_employee(employee_id) try: new_contract = Contract.objects.create( reference_number=reference_number, position=position, employee=employee, effective_date=effective_date, expiry_date=expiry_date, risk=risk, type=contract_type, document=document) except IntegrityError: messages.warning(request, "The reference number needs to be unique") return HttpResponseRedirect(reverse(manage_job_contracts)) positions = get_all_positions() employees = get_active_employees() contracts = get_active_contracts() context = { "contracts_page": "active", "employees": employees, "positions": positions, "contracts": contracts, } return render(request, 'contracts/manage_job_contracts.html', context)
def add_overtime_schedule_page(request, overtime_plan_id): overtime_plan = get_overtime_plan(overtime_plan_id) if request.POST: employee_id = request.POST["employee"] employee = get_employee(employee_id) date = request.POST["date"] number_of_hours = request.POST["number_of_hours"] description = request.POST["description"] OvertimeSchedule.objects.create( employee=employee, overtime_plan=overtime_plan, date=date, number_of_hours=number_of_hours, description=description, ) return HttpResponseRedirect(reverse(add_overtime_schedule_page, args=[overtime_plan.id])) context = { "employees": get_active_employees(), "overtime_schedules": get_overtime_schedules(overtime_plan) } return render(request, 'overtime/add_employee_schedules.html', context)
def add_new_team(request): if request.method == "POST": team_name = request.POST["team_name"] supervisor_id = request.POST["supervisor_id"] department_id = request.POST["department_id"] supervisor = get_employee(supervisor_id) department = get_department(department_id) team = Team.objects.filter(name=team_name) if team: messages.warning(request, f'Team Already Exists') return redirect('manage_teams_page') else: team = Team(department=department, name=team_name, supervisor=supervisor) team.save() messages.success(request, f'Team {team_name} added Successfully Saved') return redirect('manage_teams_page') return redirect('manage_teams_page')
def edit_team_page(request, team_id): if request.POST: team = get_team(team_id) team_name = request.POST["team_name"] supervisor_id = request.POST["supervisor_id"] department_id = request.POST["department_id"] supervisor = get_employee(supervisor_id) department = get_department(department_id) team.department = department team.supervisor = supervisor team.name = team_name team.save() messages.success(request, f'Team Info changed Successfully') return redirect('manage_teams_page') context = { "user": request.user, "team": get_team(team_id), "employees": get_active_employees(), "departments": get_all_departments(), "organisation_page": "active" } return render(request, 'organisation_details/edit_team.html', context)