Пример #1
0
def create_new_employee():
    if request.method == "POST":
        name = request.form['name']
        gender = request.form['gender']
        email = request.form['email']
        kra_pin = request.form['kra']
        basic_salary = request.form['basicsalary']
        benefits = request.form['benefits']

        if EmployeesModel.check_existing_kra(
                kra_pin) or EmployeesModel.check_existing_email(email):
            flash("Email or KRA already exists")
            return redirect(url_for('home'))

        #create object of class EmployeesModel
        emp = EmployeesModel(name=name,
                             email=email,
                             gender=gender,
                             kra_pin=kra_pin,
                             basic_salary=basic_salary,
                             benefits=benefits)
        emp.insert_method()
        #redirect to home page

    return redirect(url_for('home'))
Пример #2
0
def edit_employee(id):
    name = request.form['name']
    email = request.form['email']
    kra_pin = request.form['kra']
    basic_salary = request.form['basicsalary']
    benefits = request.form['benefits']

    current_user = EmployeesModel.fetch_by_id(id)

    if EmployeesModel.check_existing_kra(
            kra_pin
    ) and kra_pin != current_user.kra_pin or EmployeesModel.check_existing_email(
            email) and email != current_user.email:
        flash("Email/Kra Pin already exists")

    EmployeesModel.update_by_id(id=id,
                                name=name,
                                email=email,
                                kra=kra_pin,
                                salary=basic_salary,
                                benefits=benefits)
    return redirect(url_for('home'))