def editEmployee(id): first_name = request.form['first_name'] second_name = request.form['second_name'] gender = request.form['gender'] national_id = request.form['national_id'] kra_pin = request.form['kra_pin'] email = request.form['email'] departmentID = int(request.form['dpt_name']) basic_salary = request.form['basic_salary'] allowances = request.form['allowances'] if gender == "na": gender = None if departmentID == "0": departmentID = None EmployeeModel.update_by_id(id=id, first_name=first_name, second_name=second_name, gender=gender, national_id=national_id, kra_pin=kra_pin, email=email, departmentID=departmentID, basic_salary=basic_salary, allowances=allowances) this_emp = EmployeeModel.fetch_by_id(emp_id=id) this_dept = this_emp.department return redirect(url_for('employees', dpt_id=this_dept.id))
def editEmployee(id): name_of_employee = request.form['name'] kra_pin = request.form['kra_pin'] gender = request.form['gender'] email = request.form['email'] department = int(request.form['department']) basic_salary = request.form['basic_salary'] benefits = request.form['benefits'] national_id = request.form['national_id'] if gender == "na": gender = None if department == "0": department = None EmployeeModel.update_by_id(id=id, full_name=name_of_employee, gender=gender, kra_pin=kra_pin, email=email, national_id=national_id, department_id=department, basic_salary=basic_salary, benefits=benefits) this_emp = EmployeeModel.fetch_by_id(id=id) this_dept = this_emp.department return redirect(url_for('employees', dept_id=this_dept.department_id))
def newEmployee(): first_name = request.form['first_name'] second_name = request.form['second_name'] gender = request.form['gender'] national_id = request.form['national_id'] kra_pin = request.form['kra_pin'] email = request.form['email'] departmentID = int(request.form['dpt_name']) basic_salary = request.form['basic_salary'] allowances = request.form['allowances'] if EmployeeModel.fetch_by_id(national_id): flash("That user with national id no " + national_id + " already added") return redirect(url_for('employees')) employee = EmployeeModel(first_name=first_name, second_name=second_name, gender=gender, national_id=national_id, kra_pin=kra_pin, email=email, departmentID=departmentID, basic_salary=basic_salary, allowances=allowances) employee.instert_into_database() return redirect(url_for('employees', dpt_id=departmentID))
def newPayroll(emp_id): this_employee = EmployeeModel.fetch_by_id(emp_id) payroll = Payroll(this_employee.first_name + this_employee.second_name, this_employee.basic_salary, this_employee.allowances) payroll_month = request.form['payroll_month'] gross_salary = payroll.gross_salary employee_id = emp_id dept_name = request.form['dept_name'] nssf_deductions = payroll.nssf_deductions nhif_deductions = payroll.nhif_deductions PAYE = payroll.payee taxable_income = payroll.taxable_income overtime = request.form['overtime'] salary_advance = request.form['salary_advance'] other_deductions = request.form['other_deductions'] net_salary = payroll.net_salary emp_payroll = PayrollsModel(employee_id=employee_id, dept_name=dept_name, payroll_month=payroll_month, gross_salary=gross_salary, nssf_deductions=nssf_deductions, nhif_deductions=nhif_deductions, taxable_income=taxable_income, PAYE=PAYE, overtime=overtime, salary_advance=salary_advance, other_deductions=other_deductions, net_salary=net_salary) emp_payroll.instert_into_database() return redirect(url_for('payrolls', emp_id=emp_id))
def newEmployee(): name_of_employee = request.form['name'] kra_pin = request.form['kra_pin'] gender = request.form['gender'] email = request.form['email'] department = int(request.form['department']) basic_salary = request.form['basic_salary'] benefits = request.form['benefits'] national_id = request.form['national_id'] emp = EmployeeModel(full_name=name_of_employee, gender=gender, kra_pin=kra_pin, email=email, national_id=national_id, department_id=department, basic_salary=basic_salary, benefits=benefits) emp.insert_to_db() return redirect(url_for('hello_world'))
def generate_payroll(id): #if request.method == 'POST': this_employee = EmployeeModel.fetch_by_id(id) payroll = Payroll(this_employee.basic_salary, this_employee.benefits) name_of_employee = request.form['name'] month = request.form['month'] overtime = request.form['overtime'] loan = request.form['loan'] salary_advance = request.form['salary_advance'] gross_salary = payroll.gross_salary taxable_income = payroll.taxable_income nssf = round(payroll.nssf_deductions, 2) paye = round(payroll.payee, 2) personal_relief = payroll.personal_relief #tax_net_off_relief = round(payroll.after_relief, 2) nhif = payroll.nhif_deductions net_salary = round(payroll.net_salary, 2) take_home_pay = net_salary - (float(loan) + float(salary_advance) + float(overtime)) payslip = PayrollsModel(full_name=name_of_employee, month=month, overtime=overtime, loan_deducted=loan, salary_advance=salary_advance, gross_salary=gross_salary, nssf=nssf, taxable_income=taxable_income, paye=paye, personal_relief=personal_relief, nhif=nhif, net_salary=net_salary, take_home_pay=take_home_pay, employee_id=this_employee.id) payslip.insert_to_db() #payslip.fetch_by_employee(id=id) #flash('Payslip for ' + this_employee.full_name + ' has been successfully generated', 'success') #return redirect(url_for('payrolls', emp_id=this_employee.id)),render_template('payroll.html') return redirect(url_for('hello_world'))
def hello_world(): departments = DepartmentModel.fetch_all() all_employees = EmployeeModel.fetch_all() male = 0 female = 0 others = 0 for each in all_employees: if each.gender == 'm': male += 1 elif each.gender == 'f': female += 1 else: others += 1 pie_chart = pygal.Pie() pie_chart.title = 'Comparing Company Employee by Gender' pie_chart.add('Male', male) pie_chart.add('Female', female) pie_chart.add('Others', others) graph = pie_chart.render_data_uri() #print(graph) line_chart = pygal.Bar() line_chart.title = 'Salary Cost per Department' for each_dept in departments: line_chart.add( each_dept.name, DepartmentModel.fetch_total_payrol_by_id(each_dept.department_id)) bar_graph = line_chart.render_data_uri() return render_template('index.html', idara=departments, graph=graph, bar_graph=bar_graph)
def payrolls(emp_id): # this_employee = EmployeeModel.fetch_by_id(emp_id) # emp_payroll = PayrollsModel.fetch_all() this_employee = EmployeeModel.fetch_by_id(emp_id) return render_template('payrolls.html', this_employee=this_employee)
def departments(): employees = EmployeeModel.fetch_all() departments = DepartmentModel.fetch_all() return render_template('departments.html', employees=employees, departments=departments)
def deleteEmployee(id): this_emp = EmployeeModel.fetch_by_id(emp_id=id) this_dept = this_emp.department EmployeeModel.delete_by_id(id=id) return redirect(url_for('employees', dpt_id=this_dept.id))
def deleteDepartment(department_id): this_dept = DepartmentModel.delete_by_dept_id(department_id) employees = EmployeeModel.delete_by_id(id) return redirect(url_for('hello_world'))
def payrolls(emp_id): this_employee = EmployeeModel.fetch_by_id(emp_id) payroll = this_employee.payrolls return render_template('payroll.html', this_employee=this_employee)