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)
def add_purchase_guide(): unit = request.form["purchase-unit"] price = request.form["purchase-price"] brand_id = request.form['brand-id'] brand = Brand.read_one(Brand, brand_id) PurchaseGuide(unit, price, brand) return redirect(url_for('brand.get_brands'))
def get_purchases(): kitchen_purchases = KitchenStockPurchase.read(KitchenStockPurchase) kitchen_items = KitchenStock.read(KitchenStock) drink_items = Brand.read(Brand) brand_purchases = Purchase.read(Purchase) total_purchases = KitchenStockPurchase.get_total_price(KitchenStockPurchase) + Purchase.get_total_price(Purchase) return render_template("manager/purchases.html", mod=module, total_purchases=total_purchases, kitchen_purchases=kitchen_purchases, kitchen_items=kitchen_items, drink_items=drink_items, brand_purchases=brand_purchases)
def add_sale_guide(): 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-id'] brand = Brand.read_one(Brand, brand_id) SaleGuide(unit, price, quantity_in_purchase_unit, brand) return redirect(url_for('brand.get_brands'))
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))
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)
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'))
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": 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 get_edit_order_data(id): data = dict() foods = Food.read(Food) drinks = Brand.read(Brand) # get sale items dict sale_items_dict = utils.build_sale_items_dict(foods, drinks) data["sale_items"] = sale_items_dict # get order dict order = Order.read_one(Order, id) order_dict = utils.build_order_dict(order) data["order"] = order_dict return jsonify(data)
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)
def filter_sales(): if request.method == "GET": cashiers = Cashier.read(Cashier) waiters = Waiter.read(Waiter) items = Food.read(Food) + Brand.read(Brand) 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(9999, 12, 31) 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("manager/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))
def filter(): if request.method == "GET": kitchen_items = KitchenStock.read(KitchenStock) drink_items = Brand.read(Brand) kitchen_purchases = [] brand_purchases = [] item = request.args.get("item") _from = request.args.get("from") to = request.args.get("to") place = request.args.get("place") filter_kitchen, filter_bar = True, True if place == "kitchen": filter_bar = False elif place == "bar": filter_kitchen = False 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: item_type, id = item.split("-") if item_type == "kitchen": kitchen_purchases = KitchenStockPurchase.filter2(KitchenStockPurchase, id, _from, to, filter_kitchen) elif item_type == "drink": brand_purchases = Purchase.filter(Purchase, id, _from, to, filter_bar) else: kitchen_purchases = KitchenStockPurchase.filter2(KitchenStockPurchase, "", _from, to, filter_kitchen) brand_purchases = Purchase.filter(Purchase, "", _from, to, filter_bar) print(">>>>>>>>>>>>>>>>>", kitchen_purchases, brand_purchases) total_purchases = KitchenStockPurchase.get_total_price(KitchenStockPurchase, purchases=kitchen_purchases) + Purchase.get_total_price(Purchase, purchases=brand_purchases) return render_template("manager/purchases.html", mod=module, kitchen_purchases=kitchen_purchases, total_purchases=total_purchases, kitchen_items=kitchen_items, drink_items=drink_items, item_id=item, brand_purchases=brand_purchases, tomorrow=to, today=_from)
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"))
def get_sale_items(): foods = Food.read(Food) drinks = Brand.read(Brand) sale_items = utils.build_sale_items_dict(foods, drinks) return jsonify(sale_items)
def edit_order(id): if request.method == "GET": order = Order.read_one(Order, id) if order.open: # get drink categories dict drink_categories = Category.read(Category) # get food categories dict food_categories = FoodCategory.read(FoodCategory) # get_order sold_items = {"food_items": {}, "drink_items": {}} for sale in order.sales: if sale.food_id: sold_items["food_items"][sale.food_id] = sale.quantity elif sale.brand_id: sold_items["drink_items"][sale.brand_id] = [sale.sale_guide_id, sale.quantity] return render_template('cashier/edit-order.html', order_id=id, categories=drink_categories, food_categories=food_categories, order=order, sold_items=sold_items, mod=module) return redirect(url_for('order.get_order', id=id)) elif request.method == "POST": order = Order.read_one(Order, id) old_sales = order.sales for sale in old_sales: sale_quantity = sale.quantity sale_guide = SaleGuide.read_one(SaleGuide, id=sale.sale_guide_id) if sale_guide: # convert to sale_quantity to purchase unit purchase_unit_quantity = sale_quantity/sale_guide.quantity_in_purchase_unit brand = Brand.read_one(Brand, id=sale.brand_id) brand.update_quantity(purchase_unit_quantity) else: units = sale.quantity food = Food.read_one(Food, id=sale.food_id) food.update_units(units) # delete the sale session.delete(sale) session.commit() sales = request.form["sales"] 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"]) sale_guide = SaleGuide.read_one(SaleGuide, id=drink_sale["sale_guide_id"]) reduce_quantity = float(drink_sale["quantity"]) / float(sale_guide.quantity_in_purchase_unit) Sale(drink_sale["sale_unit"], drink_sale["sale_price"], drink_sale["quantity"], order, order.waiter, order.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"]) Sale(food_sale["sale_unit"], food_sale["sale_price"], food_sale["quantity"], order, order.waiter, order.cashier, food=food, reduce_quantity=reduce_quantity) verified_bill += int(food_sale["quantity"]) * int(food_sale["sale_price"]) order.bill = verified_bill session.commit() return redirect(url_for('order.get_order', id=id))
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'))
def get_brands(): brands = Brand.read(Brand) categories = Category.read(Category) return render_template("manager/brands.html", mod=module, brands=brands, categories=categories)