예제 #1
0
def delete_kitchen_purchase():
    purchase_id = request.form["kitchen-purchase-id"]
    purchase = KitchenStockPurchase.read_one(KitchenStockPurchase, purchase_id)
    KitchenStockPurchase.delete(purchase)
    session.close()
    flash("Kitchen Purchase ("+ purchase_id +") was deleted successfully", "info")
    return redirect(url_for('purchase.get_purchases'))
예제 #2
0
def delete_sale_guide():
    sale_guide_id = request.form["sale-guide-id"]
    sg = SaleGuide.read_one(SaleGuide, sale_guide_id)
    brand_id = sg.brand.id
    SaleGuide.delete(sg)
    session.close()
    return redirect('/brand/sale-guides?brand=' + str(brand_id))
예제 #3
0
def delete_purchase():
    purchase_id = request.form["purchase-id"]
    purchase = Purchase.read_one(Purchase, purchase_id)
    Purchase.delete(purchase)
    session.close()
    flash("Purchase ("+ purchase_id +") was deleted successfully", "info")
    return redirect(url_for('purchase.get_purchases'))
def reduce_kitchen_stock():
    if request.method == "POST":
        quantity = request.form['quantity']
        stock_id = request.form['stock']
        stock = KitchenStock.read_one(KitchenStock, stock_id)
        try:
            if int(quantity) < 1:
                flash("Invalid Input!", 'danger')
            else:
                stock.add_quantity(0 - int(quantity))
                flash(
                    "Reduced " + quantity + " units of " + stock.name +
                    " from kitchen stock", 'info')
                session.close()
                return redirect(url_for('kitchen_stock.get_kitchen_stock'))
        except Exception as e:
            flash("Invalid Input!", 'danger')
        return redirect(
            url_for('kitchen_stock.reduce_stock') + '?kitchen-stock=' +
            stock_id)
    else:
        stock_id = request.args['kitchen-stock']
        stock = KitchenStock.read_one(KitchenStock, stock_id)
        return render_template("manager/reduce-kitchen-stock.html",
                               mod=module,
                               stock=stock)
예제 #5
0
def add_waiter():
    if request.method == "POST":
        first_name = request.form["first-name"]
        last_name = request.form["last-name"]
        waiter = Waiter(first_name, last_name)
        session.close()

    return redirect(url_for('waiter.get_waiters'))
def add_kitchen_stock():
    if request.method == "POST":
        name = request.form["kitchen-item"]
        usage_unit = request.form["usage-unit"]
        KitchenStock(name, usage_unit)
        session.close()
        flash(name + " has been registered as Kitchen Stock", "success")
        return redirect(url_for('kitchen_stock.get_kitchen_stock'))
def delete_kitchen_stock():
    if request.method == "POST":
        kitchen_stock_id = request.form["kitchen-stock"]
        stock = KitchenStock.read_one(KitchenStock, kitchen_stock_id)
        KitchenStock.delete(stock)
        flash("Item has been deleted", "info")
        session.close()
        return redirect(url_for('kitchen_stock.get_kitchen_stock'))
예제 #8
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))
예제 #9
0
def add_brand():
    if request.method == "POST":
        brand_name = request.form["brand"]
        category_id = request.form["category"]
        purchase_unit = request.form["purchase-unit"]
        purchase_price = request.form["purchase-price"]
        category = Category.read_one(Category, category_id)
        purchase_guide = PurchaseGuide(purchase_unit, purchase_price)
        Brand(brand_name, 0, category, purchase_guide)
        session.close()
        return redirect(url_for('brand.get_brands'))
예제 #10
0
def sale_guides():
    if request.method == "POST":
        unit = request.form["sale-unit"]
        price = request.form["sale-price"]
        quantity_in_purchase_unit = request.form["quantity-in-purchase-unit"]
        brand_id = request.form['brand']
        brand = Brand.read_one(Brand, brand_id)
        SaleGuide(unit, price, quantity_in_purchase_unit, brand)
        session.close()
        return redirect('/brand/sale-guides?brand=' + str(brand_id))
    else:
        brand_id = request.args["brand"]
        brand = Brand.read_one(Brand, brand_id)
        return render_template("manager/sale-guides.html", mod=module, brand=brand)
예제 #11
0
def edit_manager():
    if request.method == "POST":
        first_name = request.form["first-name"]
        last_name = request.form["last-name"]
        email = request.form["email"]
        username = request.form["username"]
        boss_email = request.form["boss-email"]
        manager = Manager.update(current_user.manager, first_name, last_name,
                                 email, username, boss_email)
        flash("Manager details upadated successfully", "success")
        session.close()
        return redirect(url_for('manager.edit_manager'))
    if request.method == "GET":
        return render_template('manager/manager.html')
예제 #12
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'))
예제 #13
0
def edit_waiter():
    if request.method == "POST":
        waiter_id = request.form["waiter"]
        first_name = request.form["first-name"]
        last_name = request.form["last-name"]
        waiter = Waiter.read_one(Waiter, waiter_id)
        waiter.update(first_name, last_name)
        session.close()
        return redirect(url_for('waiter.get_waiters'))

    elif request.method == "GET":
        waiter_id = request.args["waiter"]
        waiter = Waiter.read_one(Waiter, waiter_id)
        return render_template("manager/waiters.html",
                               mod=module,
                               waiter_to_edit=waiter)
예제 #14
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'))
예제 #15
0
def reset_password():
    if request.method == "POST":
        chef_id = request.form["chef"]
        password = request.form["password"]
        password1 = request.form["password-1"]

        if password != password1:
            flash('Passwords do not match!')
            chef = Chef.read_one(Chef, chef_id)
            return render_template("manager/chefs.html",
                                   mod=module,
                                   chef_to_edit=chef)

        chef = Chef.read_one(Chef, chef_id)
        chef.update_password(password)
        session.close()
        return redirect(url_for('chef.get_chefs'))
예제 #16
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)
예제 #17
0
def edit_brand():
    if request.method == "POST":
        category_id = request.form["category"]
        brand_id = request.form["brand-id"]
        brand_name = request.form["brand"]
        purchase_unit = request.form["purchase-unit"]
        purchase_price = request.form["purchase-price"]
        c = Category.read_one(Category, category_id)
        b = Brand.read_one(Brand, brand_id)
        pg = PurchaseGuide.read_one(PurchaseGuide, b.purchase_guide_id)
        Brand.update(b, brand_name, c)
        pg.update(purchase_unit, purchase_price)
        session.close()
        return redirect(url_for('brand.get_brands'))
    else:
        brand_id = request.args["brand"]
        brand = Brand.read_one(Brand, brand_id)
        categories = Category.read(Category)
        return render_template("manager/edit-brand.html", mod=module, brand=brand, categories=categories)
예제 #18
0
def change_password():
    if request.method == "POST":
        current_password = request.form["c-password"]
        new_password = request.form["n-password"]
        confirm_password = request.form["r-password"]

        user = User.find_user(User, current_user.username, current_password)
        if user:
            if new_password == confirm_password:
                user.manager.update_password(new_password)
                flash("Passsword resset successfully", "success")
            else:
                flash("Passwords do not match", "danger")
        else:
            flash("Incorrect current password", "danger")
        session.close()
        return redirect(url_for('manager.edit_manager'))
    if request.method == "GET":
        return render_template('manager/manager.html')
예제 #19
0
def add_chef():
    if request.method == "POST":
        first_name = request.form["first-name"]
        last_name = request.form["last-name"]
        admin = request.form.get("admin")
        username = request.form["username"]
        password = request.form["password"]
        password1 = request.form["password-1"]
        if admin: admin = True
        else: admin = False

        if password != password1:
            flash('Passwords do not match!')
            return redirect(url_for('chef.get_chefs'))
        user = User(username, password)
        Chef(first_name, last_name, admin, user)
        session.close()

    return redirect(url_for('chef.get_chefs'))
예제 #20
0
def add_manager():
    if request.method == "POST":
        first_name = request.form["first-name"]
        last_name = request.form["last-name"]
        email = request.form["email"]
        username = request.form["username"]
        boss_email = request.form["boss-email"]

        password = request.form["password"]
        password1 = request.form["password-1"]
        if password != password1:
            flash('Error. Passwords do not match! Please Try again', "warning")
            return redirect(url_for('user.login'))

        user = User(username, password)
        Manager(first_name, last_name, email, boss_email, user)

        flash("Manager was created successfully", "success")
        session.close()
        return redirect(url_for('user.login'))
예제 #21
0
def edit_chef():
    if request.method == "POST":
        chef_id = request.form["chef"]
        first_name = request.form["first-name"]
        last_name = request.form["last-name"]
        admin = request.form.get("admin")
        username = request.form["username"]
        if admin: admin = True
        else: admin = False
        chef = Chef.read_one(Chef, chef_id)
        chef.update(first_name, last_name, admin, username)
        session.close()
        return redirect(url_for('chef.get_chefs'))

    elif request.method == "GET":
        chef_id = request.args["chef"]
        chef = Chef.read_one(Chef, chef_id)
        return render_template("manager/chefs.html",
                               mod=module,
                               chef_to_edit=chef)
예제 #22
0
def reduce_stock():
    if request.method == "POST":
        quantity = request.form['quantity']
        brand_id = request.form['brand']
        brand = Brand.read_one(Brand, brand_id)
        try:
            if int(quantity) < 1:
                flash("Invalid Input!", 'danger')
            else:
                brand.add_quantity(0-int(quantity))
                flash("Reduced "+quantity+" units of "+brand.name+" from stock", 'info')
                session.close()
                return redirect(url_for('brand.get_brands'))
        except Exception as e:
            flash("Invalid Input!", 'danger')
        return redirect(url_for('brand.reduce_stock')+'?brand=1')
    else:
        brand_id = request.args["brand"]
        brand = Brand.read_one(Brand, brand_id)
        return render_template("manager/reduce-stock.html", mod=module, brand=brand)
def add_stock():
    if request.method == "POST":
        added_stock_quantity = request.form['added-stock-quantity']
        stock_id = request.form['stock']
        stock = KitchenStock.read_one(KitchenStock, stock_id)

        try:
            if int(added_stock_quantity) < 1:
                flash("Invalid Stock Added!", 'danger')
                return redirect(
                    url_for('kitchen_stock.add_stock') + '?kitchen-stock=' +
                    stock_id)
            else:
                # record purchase
                purchase_unit = request.form['purchase-unit']
                unit_price = request.form['unit-price']
                purchase_quantity = request.form['purchase-quantity']
                KitchenStockPurchase(purchase_unit, unit_price,
                                     purchase_quantity, added_stock_quantity,
                                     stock.usage_unit, current_user, stock)
                flash("Registered Purchase of " + stock.name + " successfully",
                      'success')
                session.close()
                return redirect(url_for('kitchen_stock.get_kitchen_stock'))
        except ValueError:
            flash("Invalid Stock Added!", 'danger')
            return redirect(
                url_for('kitchen_stock.add_stock') + '?kitchen-stock=' +
                stock_id)

    elif request.method == "GET":
        stock_id = request.args['kitchen-stock']
        stock = KitchenStock.read_one(KitchenStock, stock_id)
        if current_user.manager:
            return render_template("manager/add-kitchen-stock.html",
                                   mod=module,
                                   stock=stock)
        elif current_user.chef:
            return render_template("chef/add-kitchen-stock.html",
                                   mod=module,
                                   stock=stock)
예제 #24
0
def add_stock():
    if request.method == "POST":
        quantity = request.form['quantity']
        brand_id = request.form['brand']
        brand = Brand.read_one(Brand, brand_id)
        try:
            if int(quantity) < 1:
                flash("Invalid Input!", 'danger')
            else:
                brand.add_quantity(quantity)
                Purchase(brand.purchase_guide.purchase_unit, brand.purchase_guide.purchase_price, quantity, brand)
                flash("Added "+quantity+" units of "+brand.name+" successfully", 'success')
                session.close()
                return redirect(url_for('brand.get_brands'))
        except Exception as e:
            flash("Invalid Input!", 'danger')
        return redirect(url_for('brand.add_stock')+'?brand='+brand_id)
    else:
        brand_id = request.args["brand"]
        brand = Brand.read_one(Brand, brand_id)
        return render_template("manager/add-stock.html", mod=module, brand=brand)
def edit_kitchen_stock():
    if request.method == "POST":
        kitchen_stock_id = request.form["kitchen-stock"]
        name = request.form["kitchen-item"]
        usage_unit = request.form["usage-unit"]
        stock = KitchenStock.read_one(KitchenStock, kitchen_stock_id)
        stock.update(name, usage_unit)
        session.close()
        flash("Item has been edited", "success")
        return redirect(url_for('kitchen_stock.get_kitchen_stock'))
    elif request.method == "GET":
        kitchen_stock_id = request.args["kitchen-stock"]
        stock = KitchenStock.read_one(KitchenStock, kitchen_stock_id)
        if current_user.manager:
            return render_template("manager/edit-kitchen-stock.html",
                                   mod=module,
                                   stock=stock)
        elif current_user.chef:
            return render_template("chef/edit-kitchen-stock.html",
                                   mod=module,
                                   stock=stock)
예제 #26
0
def login():
    if request.method == "POST":
        username = request.form['username']
        password = request.form['password']
        user = User.find_user(User, username, password)
        if user:
            role = user.get_role()
            if role == "cashier":
                if not Session.get_current_session(Session, user.cashier):
                    login_user(user, True)
                    Session(user.cashier)
                    return redirect(url_for('user.login'))
                else:
                    flash(
                        "You are logged in another location. Please logout before logging in again",
                        "info")
                    session.close()
                    return redirect(url_for('user.login'))
            elif role == "manager":
                login_user(user, True)
                session.close()
                return redirect(url_for('email.send_email'))
            elif role == "chef":
                login_user(user, True)
                session.close()
                return redirect(url_for('sale.get_food_sales'))
            flash("User not found", "danger")
            session.close()
            return redirect(url_for('user.login'))
        else:
            flash("User not found", "danger")
            session.close()
            return redirect(url_for('user.login'))
    elif request.method == "GET":
        if current_user.is_authenticated:
            if current_user.cashier_id:
                session.close()
                return redirect(url_for('order.get_orders'))
            elif current_user.manager_id:
                session.close()
                return redirect(url_for('sale.get_sales'))
            elif current_user.chef_id:
                session.close()
                return redirect(url_for('sale.get_food_sales'))
        else:
            managers = Manager.read(Manager)
            manager_available = True
            if len(managers) == 0:
                manager_available = False
            session.close()
            return render_template('global/login.html',
                                   mod=module,
                                   manager_available=manager_available)
예제 #27
0
def delete_brand():
    brand_id = request.form["brand-id"]
    b = Brand.read_one(Brand, brand_id)
    Brand.delete(b)
    session.close()
    return redirect(url_for('brand.get_brands'))