Esempio n. 1
0
def reset_password():
    if request.method == "POST":
        cashier_id = request.form["cashier"]
        password = request.form["password"]
        password1 = request.form["password-1"]
        if password != password1:
            flash('Passwords do not match!', "warning")
            cashier = Cashier.read_one(Cashier, cashier_id)
            return render_template("manager/cashiers.html",
                                   mod=module,
                                   cashier_to_edit=cashier)
        cashier = Cashier.read_one(Cashier, cashier_id)
        cashier.update_password(password)
        session.close()
        flash('Password changed successfully!', "success")
        return redirect(url_for('cashier.get_cashiers'))
Esempio n. 2
0
def filter_sessions():
    if request.method == "GET":
        cashiers = Cashier.read(Cashier)

        cashier = request.args["cashier"]
        _from = request.args["from"]
        to = request.args["to"]

        if _from:
            _from = utils.convert_date_from_html(_from)
        else:
            _from = datetime.datetime(2000, 1, 1)
        if to:
            to = utils.convert_date_from_html(to)
        else:
            to = datetime.datetime(3000, 1, 1)

        sessions = Session.filter(Session, cashier, _from, to)

        # Avoid error on changing str to int
        if cashier == "":
            cashier = 0

        return render_template("manager/cashier-session.html",
                               mod=module,
                               sessions=sessions,
                               cashiers=cashiers,
                               cashier_id=int(cashier),
                               today=_from,
                               tomorrow=to)
Esempio n. 3
0
def edit_cashier():
    if request.method == "POST":
        cashier_id = request.form["cashier"]
        first_name = request.form["first-name"]
        last_name = request.form["last-name"]
        username = request.form["username"]
        cashier = Cashier.read_one(Cashier, cashier_id)
        cashier.update(first_name, last_name, username)
        session.close()
        return redirect(url_for('cashier.get_cashiers'))

    elif request.method == "GET":
        cashier_id = request.args["cashier"]
        cashier = Cashier.read_one(Cashier, cashier_id)
        return render_template("manager/cashiers.html",
                               mod=module,
                               cashier_to_edit=cashier)
Esempio n. 4
0
def add_sales():
    if request.method == "POST":
        sales = request.form["sales"]
        waiter_id = request.form["waiter"]
        cashier_id = request.form["cashier"]
        customer = request.form["customer"]

        waiter = Waiter.read_one(Waiter, waiter_id)
        cashier = Cashier.read_one(Cashier, cashier_id)

        new_order = Order(customer, waiter, cashier)

        sales = json.loads(sales)
        food_sales = sales["food_items"]
        drink_sales = sales["drink_items"]

        verified_bill = 0

        for drink_sale in drink_sales.values():
            brand = Brand.read_one(Brand, drink_sale["id"])
            reduce_quantity = float(drink_sale["quantity"]) / float(
                drink_sale["quantity_ratio"])
            Sale(drink_sale["sale_unit"],
                 drink_sale["sale_price"],
                 drink_sale["quantity"],
                 new_order,
                 waiter,
                 cashier,
                 brand=brand,
                 reduce_quantity=reduce_quantity,
                 sale_guide_id=drink_sale["sale_guide_id"])
            verified_bill += int(drink_sale["quantity"]) * int(
                drink_sale["sale_price"])

        for food_sale in food_sales.values():
            food = Food.read_one(Food, food_sale["id"])
            reduce_quantity = float(food_sale["quantity"]) / float(
                food_sale["quantity_ratio"])
            Sale(food_sale["sale_unit"],
                 food_sale["sale_price"],
                 food_sale["quantity"],
                 new_order,
                 waiter,
                 cashier,
                 food=food,
                 reduce_quantity=reduce_quantity)
            verified_bill += int(food_sale["quantity"]) * int(
                food_sale["sale_price"])

        new_order.bill = verified_bill
        current_session = Session.get_current_session(Session,
                                                      current_user.cashier)
        current_session.orders.append(new_order)
        session.commit()
        flash("Order submitted successfully", "success")
        order_id = new_order.id
        session.close()
        return redirect(url_for('order.get_order', id=order_id))
Esempio n. 5
0
def logout():
    cashier_id = request.form["cashier"]
    cashier = Cashier.read_one(Cashier, cashier_id)
    current_session = Session.get_current_session(Session, cashier)
    if current_session:
        current_session.update(0)
    else:
        logout_user()
        flash("Login to start a new session", "info")
    return redirect(url_for('user.login'))
Esempio n. 6
0
def get_order(id):
    if request.method == "GET":
        order = Order.read_one(Order, id)
        if current_user.manager:
            cashiers = Cashier.read(Cashier)
            waiters = Waiter.read(Waiter)
            return render_template("manager/order.html", mod=module, order=order, waiters=waiters, cashiers=cashiers)
        elif current_user.cashier:
            return render_template("cashier/order.html", mod=module, order=order)
        elif current_user.chef:
            return render_template("chef/order.html", mod=module, order=order)
Esempio n. 7
0
def get_sessions():
    if request.method == "GET":
        sessions = Session.read(Session)
        session_page = Session.read_limit(Session, 1, 10)
        cashiers = Cashier.read(Cashier)
        return render_template('manager/cashier-session.html',
                               sessions=sessions,
                               session_page=session_page,
                               mod=module,
                               cashiers=cashiers)
    elif request.method == "POST":
        return redirect(url_for('session.get_sessions'))
Esempio n. 8
0
def add_cashier():
    if request.method == "POST":
        first_name = request.form["first-name"]
        last_name = request.form["last-name"]
        username = request.form["username"]
        password = request.form["password"]
        password1 = request.form["password-1"]
        if password != password1:
            flash('Passwords do not match!', "warning")
            return redirect(url_for('cashier.get_cashiers'))
        user = User(username, password)
        Cashier(first_name, last_name, user)
        session.close()

    return redirect(url_for('cashier.get_cashiers'))
Esempio n. 9
0
def get_order_page():
    page = request.args.get("page")
    if page:
        page = int(page)
        if page == 0:
            return redirect(url_for('order.get_orders'))
        order_page = Order.read_limit(Order, page, 10)
        orders = order_page.items
        cashiers = Cashier.read(Cashier)
        waiters = Waiter.read(Waiter)
        total_bill, total_paid = utils.compute_total_bill_and_total_paid_from_orders(orders)
        print(">>>>>>>>>>>>>>>", total_bill, total_paid)
        return render_template("manager/orders.html", mod=module, orders=orders, total_bill=total_bill, total_paid=total_paid, order_page=order_page, current_page=page, cashiers=cashiers, waiters=waiters)
    else:
        return redirect(url_for("order.get_orders"))
Esempio n. 10
0
def search():
    if request.method == "GET":
        search_string = request.args.get("search-string")

        if current_user.cashier:
            current_session = Session.get_current_session(Session, current_user.cashier)

            orders = Order.search_customer(Order, search_string, current_session.id)

            total_bill, total_paid = utils.compute_total_bill_and_total_paid_from_orders(orders)

            cashiers = Cashier.read(Cashier)
            waiters = Waiter.read(Waiter)

            return render_template("cashier/orders.html", mod=module, orders=orders, total_bill=total_bill,
                                       total_paid=total_paid, cashiers=cashiers, waiters=waiters)
        else:
            orders = Order.search_customer(Order, search_string, None)
            total_bill, total_paid = utils.compute_total_bill_and_total_paid_from_orders(orders)

            cashiers = Cashier.read(Cashier)
            waiters = Waiter.read(Waiter)
            return render_template("manager/orders.html", mod=module, orders=orders, total_bill=total_bill,
                                   total_paid=total_paid, cashiers=cashiers, waiters=waiters)
Esempio n. 11
0
def get_sales():
    sales = Sale.read(Sale)
    sale_page = Sale.read_limit(Sale, 1, 10)
    cashiers = Cashier.read(Cashier)
    waiters = Waiter.read(Waiter)
    items = Food.read(Food) + Brand.read(Brand)
    total_sales = utils.compute_sales(sales)
    return render_template("manager/sales.html",
                           mod=module,
                           sales=sales,
                           sale_page=sale_page,
                           total_sales=total_sales,
                           cashiers=cashiers,
                           waiters=waiters,
                           items=items)
Esempio n. 12
0
def edit_order_info(id):
    if request.method == "POST":
        order = Order.read_one(Order, id)
        if order.open:
            cashier_id = request.form['cashier']
            customer = request.form['customer']
            waiter_id = request.form['waiter']
            paid = request.form['paid']
            if int(paid) > order.bill:
                flash("Invalid Payment", "danger")
                return redirect(url_for('order.get_order', id=id))
            cashier = Cashier.read_one(Cashier, cashier_id)
            waiter = Waiter.read_one(Waiter, waiter_id)
            order.update_info(cashier, waiter, customer, paid)
            flash("Order info was edited successfully", "success")
        return redirect(url_for('order.get_order', id=id))
Esempio n. 13
0
def get_session_page():
    page = request.args.get("page")
    if page:
        page = int(page)
        if page == 0:
            return redirect(url_for('session.get_sessions'))
        session_page = Session.read_limit(Session, page, 10)
        sessions = session_page.items
        cashiers = Cashier.read(Cashier)
        return render_template("manager/cashier-session.html",
                               mod=module,
                               sessions=sessions,
                               session_page=session_page,
                               current_page=page,
                               cashiers=cashiers)
    else:
        return redirect(url_for("order.get_sessions"))
Esempio n. 14
0
def filter_food():
    if request.method == "GET":
        cashiers = Cashier.read(Cashier)
        waiters = Waiter.read(Waiter)
        items = Food.read(Food)

        item = request.args["item"]
        cashier = request.args["cashier"]
        waiter = request.args["waiter"]
        _from = request.args["from"]
        to = request.args["to"]

        if _from:
            _from = utils.convert_date_from_html(_from)
        else:
            _from = datetime.datetime(2000, 1, 1)
        if to:
            to = utils.convert_date_from_html(to)
        else:
            to = datetime.datetime(3000, 1, 1)

        if item == '0':
            return redirect(url_for('sale.get_food_sales'))

        sales = Sale.filter(Sale, item, cashier, waiter, _from, to)
        total_sales = utils.compute_sales(sales)

        # Avoid error on changing str to int
        if cashier == "":
            cashier = 0
        if waiter == "":
            waiter = 0

        return render_template("chef/food-sales.html",
                               mod=module,
                               sales=sales,
                               total_sales=total_sales,
                               cashiers=cashiers,
                               waiters=waiters,
                               items=items,
                               today=_from,
                               tomorrow=to,
                               item_id=item,
                               cashier_id=int(cashier),
                               waiter_id=int(waiter))
Esempio n. 15
0
def filter_orders():
    if request.method == "GET":
        cashiers = Cashier.read(Cashier)
        waiters = Waiter.read(Waiter)
        
        cashier = request.args.get("cashier")
        if not cashier and current_user.cashier:
            cashier = str(current_user.cashier.id)
        elif not cashier and not current_user.cashier:
            cashier = ""

        open = request.args.get("open")

        waiter = request.args.get("waiter")
        if not waiter:
            waiter = ""
        _from = request.args["from"]
        to = request.args["to"]

        if _from:
            _from = utils.convert_date_from_html(_from)
        else:
            _from = datetime.datetime(2000,1,1)
        if to:
            to = utils.convert_date_from_html(to)
        else:
            to = datetime.datetime(3000,1,1)

        orders = Order.filter(Order, open, cashier, waiter, _from, to)

        # Avoid error on changing str to int
        if cashier == "":
            cashier = 0
        if waiter == "":
            waiter = 0

        total_bill, total_paid = utils.compute_total_bill_and_total_paid_from_orders(orders)

        if current_user.manager:  
            return render_template("manager/orders.html", mod=module, orders=orders, total_bill=total_bill, total_paid=total_paid, cashiers=cashiers, waiters=waiters, cashier_id=int(cashier), waiter_id=int(waiter), today=_from, tomorrow=to)
        elif current_user.cashier:
            return render_template("cashier/orders.html", mod=module, orders=orders, total_bill=total_bill, total_paid=total_paid, cashiers=cashiers, waiters=waiters, cashier_id=int(cashier), waiter_id=int(waiter), today=_from, tomorrow=to)
Esempio n. 16
0
def get_orders():
    cashiers = Cashier.read(Cashier)
    waiters = Waiter.read(Waiter)
    order_page = Order.read_limit(Order, 1, 10)

    if current_user.manager:
        orders = Order.read(Order)
        total_bill, total_paid = utils.compute_total_bill_and_total_paid_from_orders(orders)
        return render_template("manager/orders.html", order_page=order_page, mod=module, orders=orders, total_bill=total_bill, total_paid=total_paid, waiters=waiters, cashiers=cashiers)
    elif current_user.cashier:
        current_session = Session.get_current_session(Session, current_user.cashier)
        if current_session:
            orders = current_session.orders
            orders.reverse()
            total_bill, total_paid = utils.compute_total_bill_and_total_paid_from_orders(orders)
            return render_template("cashier/orders.html", mod=module, orders=orders, waiters=waiters, total_bill=total_bill, total_paid=total_paid)
        flash("No session was found! Login to start a new session", "info")
        return redirect(url_for('user.logout'))
    elif current_user.chef:
        orders = Order.read(Order)
        return render_template("chef/orders.html", mod=module, orders=orders, waiters=waiters)
Esempio n. 17
0
def get_food_sales():
    if request.args.get("page"):
        page = int(request.args.get("page"))
        if page == 0:
            return redirect(url_for('sale.get_food_sales'))
    else:
        page = 1
    sale_page = Sale.read_food_sales(Sale, page, 10)
    sales = sale_page.items
    cashiers = Cashier.read(Cashier)
    waiters = Waiter.read(Waiter)
    items = Food.read(Food)
    total_sales = utils.compute_sales(sales)
    return render_template("chef/food-sales.html",
                           mod=module,
                           sales=sales,
                           sale_page=sale_page,
                           current_page=page,
                           total_sales=total_sales,
                           cashiers=cashiers,
                           waiters=waiters,
                           items=items)
Esempio n. 18
0
def get_sale_page():
    page = request.args.get("page")
    if page:
        page = int(page)
        if page == 0:
            return redirect(url_for('sale.get_sales'))
        sale_page = Sale.read_limit(Sale, page, 10)
        sales = sale_page.items
        cashiers = Cashier.read(Cashier)
        waiters = Waiter.read(Waiter)
        items = Food.read(Food) + Brand.read(Brand)
        total_sales = utils.compute_sales(sales)
        return render_template("manager/sales.html",
                               mod=module,
                               sales=sales,
                               sale_page=sale_page,
                               current_page=page,
                               total_sales=total_sales,
                               cashiers=cashiers,
                               waiters=waiters,
                               items=items)
    else:
        return redirect(url_for("sale.get_sales"))
Esempio n. 19
0
def get_cashiers():
    cashiers = Cashier.read(Cashier)
    return render_template("manager/cashiers.html",
                           mod=module,
                           cashiers=cashiers)
Esempio n. 20
0
def delete_cashier():
    if request.method == "POST":
        cashier_id = request.form["cashier"]
        cashier = Cashier.read_one(Cashier, cashier_id)
        Cashier.delete(cashier)
        return redirect(url_for('cashier.get_cashiers'))