diff --git a/app/database.py b/app/database.py index a9c8365..716f7e2 100644 --- a/app/database.py +++ b/app/database.py @@ -4,6 +4,7 @@ from app import app from user import User from product import Product from consumption import Consumption +from deposit import Deposit import random as rand import datetime @@ -183,6 +184,24 @@ def add_consume(username, productid): return +def get_deposits(userid = None): + #ID|USERID|AMOUNT|TIME + if userid == None: + rows = query_db("SELECT * FROM DEPOSITS") + else: + rows = query_db("SELECT * FROM DEPOSITS WHERE USERID = ?", [str(userid)]) + deposits = [] + if rows == None: + return deposits + for row in rows: + d = Deposit() + d.id = row[0] + d.userid = row[1] + d.amount = row[2] + d.time = datetime.datetime.strptime(row[3], "%Y-%m-%d %H:%M:%S") + deposits.append(d) + return deposits + ##for testing only def generate_test_users(): diff --git a/app/deposit.py b/app/deposit.py new file mode 100644 index 0000000..809b34d --- /dev/null +++ b/app/deposit.py @@ -0,0 +1,10 @@ +import datetime as dt + +class Deposit: + + def __init__(self): + #ID|USERID|AMOUNT|TIME + self.id = 0 + self.userid = 0 + self.amount = 0.0 + self.time = dt.datetime \ No newline at end of file diff --git a/app/templates/personal.html b/app/templates/personal.html index 60feb65..ccbaaf5 100644 --- a/app/templates/personal.html +++ b/app/templates/personal.html @@ -13,7 +13,7 @@

Abrechnung

Gesamt

-

Einzahlungen (TODO): {{ "%0.2f" % deposited }} €

+

Einzahlungen: {{ "%0.2f" % deposited }} €

Konsumationen: {{ "%0.2f" % owed }} €

Total: {{ "%0.2f" % (deposited - owed)}} €

diff --git a/app/views.py b/app/views.py index 549d3e9..0cf7b31 100644 --- a/app/views.py +++ b/app/views.py @@ -242,11 +242,20 @@ def consume(): @requires_login def personal(): name = session.get('name') - consumed=get_consumed(name) + user=get_user_by_name(name) + + consumed = get_consumed(name) owed = 0 for consumption in consumed: owed += consumption.price - return render_template('personal.html', user=get_user_by_name(name), consumed=consumed, products=get_products(), deposited=555.55, owed=owed) + + deposits = get_deposits(user.id) + deposited = 0 + for deposit in deposits: + deposited += deposit.amount + + return render_template('personal.html', user=user, consumed=consumed, + products=get_products(), deposits=deposits, deposited=deposited, owed=owed) @app.route('/billing', methods=['POST', 'GET']) @requires_baron diff --git a/doc/database.sql b/doc/database.sql index 2edee39..b4f09d2 100644 --- a/doc/database.sql +++ b/doc/database.sql @@ -64,6 +64,16 @@ CREATE TABLE Consumed( FOREIGN KEY(consumer) REFERENCES USERS(id) ); +-- The table Deposits contains all money deposits done by the users +CREATE TABLE Deposits( + id INTEGER PRIMARY KEY, + userid INTEGER NOT NULL, + amount REAL DEFAULT 0.0, + time DATETIME, + + FOREIGN KEY(userid) REFERENCES USERS(id) +); + -- The table Config stores basic config data, this is for the admins and the barons diff --git a/test/database.db b/test/database.db index 5726cc1..cfbeef2 100644 Binary files a/test/database.db and b/test/database.db differ