示例#1
0
def employee():
    id = request.args["id"]
    employee = employees.get_employee(id)
    restaurant = restaurants.get_restaurant(employee[3])
    return render_template("employee.html",
                           employee=employee,
                           restaurant=restaurant)
示例#2
0
def work_report():
    week = request.args["week"]
    employeeID = request.args["employeeID"]
    restaurantID = request.args["restaurantID"]
    restaurant = restaurants.get_restaurant(restaurantID)
    employee = employees.get_employee(employeeID)
    hours = employees.work_report(restaurantID, employeeID, week)
    return render_template("workreport.html",
                           hours=hours,
                           week=week,
                           employee=employee,
                           restaurant=restaurant)
示例#3
0
def personal_schedule():
    week = request.args["week"]
    employeeID = request.args["employeeID"]
    restaurantID = request.args["restaurantID"]
    restaurant = restaurants.get_restaurant(restaurantID)
    employee = employees.get_employee(employeeID)
    schedule = employees.own_shifts(employeeID, week)
    return render_template("personal_schedule.html",
                           schedule=schedule,
                           week=week,
                           employee=employee,
                           restaurant=restaurant)
示例#4
0
def remove_employee():
    if request.method == "GET":
        id = request.args.get("id")
        restaurantID = request.args["restaurantID"]
        restaurant = restaurants.get_restaurant(restaurantID)
        employee = employees.get_employee(id)
        return render_template("remove_employee.html",
                               employee=employee,
                               restaurant=restaurant)
    if request.method == "POST":
        id = request.form["id"]
        if employees.remove_employee(id):
            flash("Työntekijän poisto onnistui!")
            return redirect("/")
        else:
            return render_template("error.html",
                                   message="Työntekijän poisto epäonnistui")
def create_roster(week, restaurantID):
    date = datetime.strptime(week + '-1', "%G-W%V-%u").strftime("%Y-%m-%d")
    roster = [[]] * 7
    assigned_shifts = []
    not_assigned = []
    assigned_hours = 0
    for i in range(7):
        shifts = get_shifts_by_date(restaurantID, date)
        this_day_shifts = []
        for shift in shifts:
            # employees are shuffled to create randomness in picking employee
            fit_employees = employees.get_employees_by_role(
                restaurantID, shift.role)
            fit_employees = random.sample(fit_employees, len(fit_employees))
            for employee in fit_employees:
                current_shifts = get_shifts_by_employee_and_week(
                    restaurantID, employee.id, week)
                hours = 0
                for current_shift in current_shifts:
                    hours += int(current_shift.duration)
                able_to_work = not employees.has_shift(
                    employee.id, shift.date) and not employees.has_dayoff(
                        employee.id, shift.date)
                # If employee is already assigned to this shift, information is salvaged so it can be shown to user.
                if is_assigned(shift.id) == employee.id:
                    assigned_hours += shift.duration
                    assigned_to = employees.get_employee(is_assigned(shift.id))
                    assigned_shifts.append((shift, assigned_to))
                if hours + shift.duration <= employee.max_hours and able_to_work and not is_assigned(
                        shift.id):
                    # If shift is successfully assigned, move to next shift
                    if assign__shift(shift.id, employee.id):
                        this_day_shifts.append((shift, employee))
                        break
            # If shift is not successfully assigned, information is salvaged so it can be shown to user.
            if not is_assigned(shift.id):
                not_assigned.append(shift)

        roster[i] = this_day_shifts
        modified_date = datetime.strptime(date, "%Y-%m-%d") + timedelta(days=1)
        date = modified_date.strftime("%Y-%m-%d")
    print(roster)
    return (roster,
            max(unused_hours(week, restaurantID, roster) - assigned_hours,
                0), assigned_shifts, not_assigned)
示例#6
0
def remove_dayoff():
    if request.method == "GET":
        employeeID = request.args.get("id")
        employee = employees.get_employee(employeeID)
        restaurant = restaurants.get_restaurant(employee[3])
        return render_template("remove_dayoff.html",
                               employee=employee,
                               restaurant=restaurant)
    if request.method == "POST":
        date = request.form["date"]
        employeeID = request.form["employeeID"]
        restaurantID = request.form["restaurantID"]
        if employees.remove_dayoff(employeeID, date):
            flash("Sisäänkirjautuminen onnistui!")
            return redirect("/")
        else:
            return render_template("error.html",
                                   message="Vapaapäivän poisto epäonnistui")
示例#7
0
def add_dayoff():
    if request.method == "GET":
        id = request.args.get("id")
        employee = employees.get_employee(id)
        restaurant = restaurants.get_restaurant(employee[3])
        return render_template("add_dayoff.html",
                               employee=employee,
                               restaurant=restaurant)
    if request.method == "POST":
        date = request.form["date"]
        reason = request.form["reason"]
        employeeID = request.form["employeeID"]
        restaurantID = request.form["restaurantID"]
        if employees.add_dayoff(employeeID, date, reason):
            flash("Vapaapäivän lisääminen onnistui!")
            return redirect(url_for("restaurant", id=restaurantID))
        else:
            return render_template("error.html",
                                   message="Vapaapäivän lisäys epäonnistui")
示例#8
0
def update_employee():
    if request.method == "GET":
        id = request.args.get("id")
        restaurantID = request.args["restaurantID"]
        restaurant = restaurants.get_restaurant(restaurantID)
        employee = employees.get_employee(id)
        return render_template("update_employee.html",
                               employee=employee,
                               restaurant=restaurant)

    if request.method == "POST":
        id = request.form["id"]
        new_firstname = request.form["new_firstname"]
        new_lastname = request.form["new_lastname"]
        new_role = request.form["new_role"]
        new_max_hours = request.form["new_max_hours"]
        restaurantID = request.form["restaurantID"]
        if employees.update_employee(id, new_firstname, new_lastname, new_role,
                                     new_max_hours):
            flash("Työntekijän päivitys onnistui!")
            return redirect("/")
        else:
            return render_template("error.html",
                                   message="Työntekijän muokkaus epäonnistui")