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)
def update_shift(): if request.method == "GET": id = request.args.get("id") restaurantID = request.args["restaurantID"] restaurant = restaurants.get_restaurant(restaurantID) shift = restaurants.get_shift(id) return render_template("update_shift.html", shift=shift, restaurant=restaurant) if request.method == "POST": id = request.form["id"] new_name = request.form["new_name"] new_role = request.form["new_role"] new_date = request.form["new_date"] new_start_time = request.form["new_start_time"] new_duration = request.form["new_duration"] restaurantID = request.form["restaurantID"] keep_employee = request.form["keep_employee"] if restaurants.update_shift(id, new_name, new_role, new_date, new_start_time, new_duration, keep_employee): flash("Työvuoron päivitys onnistui!") return redirect(url_for('restaurant', id=restaurantID)) else: return render_template("error.html", message="Työvuoron muokkaus epäonnistui")
def restaurant(id): restaurant = restaurants.get_restaurant(id) shifts = restaurants.get_shifts(id) all_employees = employees.get_employees(id) return render_template("restaurant.html", restaurant=restaurant, shifts=shifts, employees=all_employees)
def staff_strength_calendar(): week = request.args["week"] restaurantID = request.args["restaurantID"] calendar = restaurants.create_staff_strength_calendar(week, restaurantID) restaurant = restaurants.get_restaurant(restaurantID) return render_template("staff_strength_calendar.html", calendar=calendar, week=week, restaurant=restaurant)
def restaurant_dayview(): id = request.args["id"] date = request.args["date"] restaurant = restaurants.get_restaurant(id) shifts = restaurants.get_shifts_by_date(id, date) return render_template('restaurant_dayview.html', restaurant=restaurant, shifts=shifts, date=date)
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)
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)
def roster(): week = request.args["week"] restaurantID = request.args["restaurantID"] restaurant = restaurants.get_restaurant(restaurantID) (roster, unused_hours, assigned_shifts, not_assigned) = restaurants.create_roster(week, restaurant.id) return render_template("roster.html", roster=roster, unused_hours=unused_hours, week=week, restaurant=restaurant, assigned_shifts=assigned_shifts, not_assigned=not_assigned)
def update_restaurant(): if request.method == "GET": restaurantID = request.args["restaurantID"] restaurant = restaurants.get_restaurant(restaurantID) return render_template("update_restaurant.html", restaurant=restaurant) if request.method == "POST": id = request.form["id"] new_name = request.form["new_name"] if restaurants.update_restaurant(id, new_name): flash("Ravintolan päivitys onnistui!") return redirect(url_for('restaurant', id=id)) else: return render_template("error.html", message="Ravintolan muokkaus epäonnistui")
def remove_restaurant(): if request.method == "GET": restaurantID = request.args["restaurantID"] restaurant = restaurants.get_restaurant(restaurantID) return render_template("remove_restaurant.html", id=id, restaurant=restaurant) if request.method == "POST": id = request.form["id"] if restaurants.remove_restaurant(id): flash("Ravintolan poisto onnistui!") return redirect("/") else: return render_template("error.html", message="Ravintolan poisto epäonnistui")
def own_shifts(employeeID, week): employee = get_employee(employeeID) restaurant = restaurants.get_restaurant(employee[3]) shifts = restaurants.get_shifts_by_employee_and_week( restaurant[0], employeeID, week) date = datetime.strptime(week + '-1', "%G-W%V-%u").strftime("%Y-%m-%d") schedule = [[]] * 7 # For each day this week, add shifts to schedule which will be returned for i in range(7): schedule[i] = (i, None) for shift in shifts: if str(shift.date) == date: schedule[i] = (i, shift) modified_date = datetime.strptime(date, "%Y-%m-%d") + timedelta(days=1) date = modified_date.strftime("%Y-%m-%d") return schedule
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 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")
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")
def add_employee(): if request.method == "GET": restaurantID = request.args["restaurantID"] restaurant = restaurants.get_restaurant(restaurantID) return render_template("add_employee.html", restaurant=restaurant) if request.method == "POST": firstname = request.form["firstname"] lastname = request.form["lastname"] restaurantID = request.form["restaurantID"] role = request.form["role"] max_hours = request.form["max_hours"] if employees.add_employee(firstname, lastname, restaurantID, role, max_hours): flash("Työntekijän lisäys onnistui!") return redirect(url_for("restaurant", id=restaurantID)) else: return render_template("error.html", message="Työntekijän lisäys epäonnistui")
def add_shift(): if request.method == "GET": restaurantID = request.args["restaurantID"] restaurant = restaurants.get_restaurant(restaurantID) return render_template("add_shift.html", restaurant=restaurant) if request.method == "POST": name = request.form["name"] restaurantID = request.form["restaurantID"] role = request.form["role"] date = request.form["date"] start_time = request.form["start_time"] duration = request.form["duration"] reps = request.form["reps"] repetition = request.form["repetition"] if restaurants.add_shift(name, restaurantID, role, date, start_time, duration, reps, repetition): flash("Työvuoron lisäys onnistui!") return redirect(url_for("restaurant", id=restaurantID)) else: return render_template("error.html", message="Työvuoron lisäys epäonnistui")
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")