- added deposits
This commit is contained in:
@@ -4,6 +4,7 @@ from app import app
|
|||||||
from user import User
|
from user import User
|
||||||
from product import Product
|
from product import Product
|
||||||
from consumption import Consumption
|
from consumption import Consumption
|
||||||
|
from deposit import Deposit
|
||||||
import random as rand
|
import random as rand
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
@@ -183,6 +184,24 @@ def add_consume(username, productid):
|
|||||||
|
|
||||||
return
|
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
|
##for testing only
|
||||||
def generate_test_users():
|
def generate_test_users():
|
||||||
|
|
||||||
|
|||||||
10
app/deposit.py
Normal file
10
app/deposit.py
Normal file
@@ -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
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<h1> Abrechnung </h1>
|
<h1> Abrechnung </h1>
|
||||||
<div>
|
<div>
|
||||||
<h2>Gesamt</h2>
|
<h2>Gesamt</h2>
|
||||||
<p>Einzahlungen (TODO): {{ "%0.2f" % deposited }} €</p>
|
<p>Einzahlungen: {{ "%0.2f" % deposited }} €</p>
|
||||||
<p>Konsumationen: {{ "%0.2f" % owed }} €</p>
|
<p>Konsumationen: {{ "%0.2f" % owed }} €</p>
|
||||||
<p>Total: {{ "%0.2f" % (deposited - owed)}} €</p>
|
<p>Total: {{ "%0.2f" % (deposited - owed)}} €</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
13
app/views.py
13
app/views.py
@@ -242,11 +242,20 @@ def consume():
|
|||||||
@requires_login
|
@requires_login
|
||||||
def personal():
|
def personal():
|
||||||
name = session.get('name')
|
name = session.get('name')
|
||||||
consumed=get_consumed(name)
|
user=get_user_by_name(name)
|
||||||
|
|
||||||
|
consumed = get_consumed(name)
|
||||||
owed = 0
|
owed = 0
|
||||||
for consumption in consumed:
|
for consumption in consumed:
|
||||||
owed += consumption.price
|
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'])
|
@app.route('/billing', methods=['POST', 'GET'])
|
||||||
@requires_baron
|
@requires_baron
|
||||||
|
|||||||
@@ -64,6 +64,16 @@ CREATE TABLE Consumed(
|
|||||||
FOREIGN KEY(consumer) REFERENCES USERS(id)
|
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
|
-- The table Config stores basic config data, this is for the admins and the barons
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
BIN
test/database.db
BIN
test/database.db
Binary file not shown.
Reference in New Issue
Block a user