diff --git a/app/database.py b/app/database.py index 716f7e2..b44f3c3 100644 --- a/app/database.py +++ b/app/database.py @@ -170,6 +170,7 @@ def get_consumed(user=None, startdate=None, enddate=None): consumed.append(c) return consumed + def add_consume(username, productid): consumerid = query_db("SELECT ID FROM USERS WHERE NAME = ?", [username], one=True) @@ -184,6 +185,19 @@ def add_consume(username, productid): return + +def get_debt(name=None): + consumptions = get_consumed(name) + debt = 0 + for consumption in consumptions: + debt += consumption.price + + deposits = get_deposits(get_user_by_name(name).id) + for deposit in deposits: + debt -= deposit.amount + return debt + + def get_deposits(userid = None): #ID|USERID|AMOUNT|TIME if userid == None: diff --git a/app/templates/billing.html b/app/templates/billing.html index 879b3e4..a8eecf3 100644 --- a/app/templates/billing.html +++ b/app/templates/billing.html @@ -22,7 +22,7 @@
Total: {{ "%0.2f" % (deposited - owed)}} €
| Datum | diff --git a/app/views.py b/app/views.py index 0cf7b31..3a92d4c 100644 --- a/app/views.py +++ b/app/views.py @@ -264,7 +264,10 @@ def billing(): if request.method == 'POST': return render_template('billing.html', users=users, success="Not Implemented", dept=0, user=get_user_by_name(session.get('name'))) if request.method == 'GET': - return render_template('billing.html', users=users, dept=0, user=get_user_by_name(session.get('name'))) + debt = [0 for user in users] + for user in users: + debt[user.id-1] = get_debt(user.name) + return render_template('billing.html', users=users, debt=debt, user=get_user_by_name(session.get('name'))) @app.route('/billing/send_personal_bill/
|---|