예제 #1
0
def purchases_summery():
    purchases = query_all(Stocks)
    items = query_all(Items)
    price = {}
    quantity = {}

    for purchase in purchases:
        if purchase.item_purchased in price.keys():
            price[
                purchase.
                item_purchased] += purchase.quantity_purchased * purchase.unit_price
        else:
            price[
                purchase.
                item_purchased] = purchase.quantity_purchased * purchase.unit_price

    for purchase in purchases:
        if purchase.item_purchased in quantity.keys():
            quantity[purchase.item_purchased] += purchase.quantity_purchased
        else:
            quantity[purchase.item_purchased] = purchase.quantity_purchased

    return render_template("purchases_summery.html",
                           price=price,
                           quantity=quantity,
                           items=items,
                           purchases=purchases)
예제 #2
0
def sales_summery():
    sales = query_all(Sales)
    items = query_all(Items)
    price = {}
    quantity = {}
    unit_price = {}
    for sale in sales:
        if sale.item_sold in price.keys():
            price[sale.item_sold] += sale.quantity_sold * sale.unit_price
        else:
            price[sale.item_sold] = sale.quantity_sold * sale.unit_price

    for sale in sales:
        if sale.item_sold in unit_price.keys():
            unit_price[sale.item_sold] += sale.quantity_sold * sale.unit_price
        else:
            unit_price[sale.item_sold] = sale.quantity_sold * sale.unit_price

    for sale in sales:
        if sale.item_sold in quantity.keys():
            quantity[sale.item_sold] += sale.quantity_sold
        else:
            quantity[sale.item_sold] = sale.quantity_sold

    return render_template("sales_summery.html",
                           price=price,
                           quantity=quantity,
                           items=items,
                           sales=sales)
예제 #3
0
def current_stock():
    val = {}
    purchases = query_all(Stocks)
    sales = query_all(Sales)
    for x in purchases:
        if x.item_purchased in val.keys():
            val[x.item_purchased] = val[x.item_purchased] + x.quantity_purchased
        else:
            val[x.item_purchased] = x.quantity_purchased
    for y in sales:
        val[y.item] = val[y.item] - y.quantity
    return val
예제 #4
0
def profits():
    sales = query_all(Sales)
    purchases = Stocks.query.order_by(Stocks.id.desc()).all()
    purchase_dict = {}
    sale_quantity_dict = {}
    sale_dict = {}
    profit = {}
    for purchase in purchases:
        if purchase.item_purchased in purchase_dict.keys():
            continue
        else:
            purchase_dict[purchase.item_purchased] = purchase.unit_price

    for sale in sales:
        if sale.item_sold in sale_quantity_dict.keys():
            sale_quantity_dict[sale.item_sold] += sale.quantity_sold
            sale_dict[sale.item_sold] += sale.quantity_sold * sale.unit_price
        else:
            sale_quantity_dict[sale.item_sold] = sale.quantity_sold
            sale_dict[sale.item_sold] = sale.quantity_sold * sale.unit_price

    for purchase in purchase_dict.keys():
        if purchase in sale_quantity_dict.keys():
            profit[purchase] = sale_dict[purchase] - purchase_dict[
                purchase] * sale_quantity_dict[purchase]

    return profit
예제 #5
0
def dashboard():
    profit = profits()
    sales = query_all(Sales)
    purchases = query_all(Stocks)
    total_sales = 0
    total_purchases = 0
    for sale in sales:
        total_sales += (sale.unit_price * sale.quantity_sold)

    for purchase in purchases:
        total_purchases += (purchase.unit_price * purchase.quantity_purchased)

    return render_template("dashboard.html",
                           total_purchases=total_purchases,
                           total_sales=total_sales,
                           loss=abs(sum(profit.values())),
                           profits=sum(profit.values()))
예제 #6
0
def profit_details():
    profit = profits()
    items = query_all(Items)
    total = sum(profit.values())
    loss = abs(sum(profit.values()))
    return render_template(
        "profits_summary.html",
        profits=profit,
        items=items,
        p_total=total,
        l_total=abs(sum(profit.values())),
    )
예제 #7
0
def single_sales_details(_id):
    sales = Sales.query.filter_by(item_sold=_id).all()
    items = query_all(Items)
    return render_template("single_sales_details.html",
                           sales=sales,
                           items=items)
예제 #8
0
def single_purchases_details(_id):
    purchases = Stocks.query.filter_by(item_purchased=_id).all()
    items = query_all(Items)
    return render_template("single_purchases_summery.html",
                           purchases=purchases,
                           items=items)