From 2ee9089583dfa83bce479ccc9061f094484dcd1a Mon Sep 17 00:00:00 2001 From: Bernhard Stampfer Date: Fri, 26 Feb 2016 18:07:31 +0100 Subject: [PATCH] - added deposits --- app/database.py | 19 +++++++++++++++++++ app/deposit.py | 10 ++++++++++ app/templates/personal.html | 2 +- app/views.py | 13 +++++++++++-- doc/database.sql | 10 ++++++++++ test/database.db | Bin 57344 -> 58368 bytes 6 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 app/deposit.py 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 5726cc13fdffa4cc04a2fa9e0c08a76e444c3fd1..cfbeef29f0ea5c49e99a726d2547b0fef34ced09 100644 GIT binary patch delta 695 zcmZ{gPiPZC6vk)fB~3QL|B9NWFh!9B64~tRCe0kI`7?>pZ6e9$Af8&1;G(tCr06ZF z-u7h8S&v?%^bqLDfV7u_^r+_|SWpmp_u?e6kcxdU%rL+AeKYUteuC~UyjIU0B7{a4aJD^8sjOSUM83N4jwTB=!Abkwu3w7mMXO{IxNb0VLv zSvJ*fYGc@TmKroC?d{^chz3T2e7Pcug%Z6d9)!ov5vk6LiYR48mDZ}FQVl!xNFcIS zhT+e9kMQU9tq=VjGUq+LhdeMq@CAOsJ`DOZo(<>?f@d$tLH)xx6zoNp6eZ&{R{HzF z>$~CecoV@l_z3Ud1v~^3&X6B6owuY*7D>G@H%-#@DLy=Ay?>U>m`A q*p{hm!L1qMMZ>1s_utE=W^;1BB-eCqnpb7+3TE|5l;Eb!X7&$dG@V`m delta 159 zcmZoT!Q60wd4jayMFs{23m}F8u8BIv!WS8IpE2<=88a|5Y-3PXG$^Y(C6n&&qd$frWW51M^wtx6BWi_ik2XS<5_mFSmd&CnGC^C?}^= zW@-^o0|&^4%@4R$PDpSu&1GPI#Jq=j9&-hAG_xr)KhsO5!%TC5S{s=*&%Kt+2>|4< BD0Kh;