diff --git a/.gitignore b/.gitignore
index 005984e..280fb6b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,7 @@
/data/*
/data/logs/*
/data/tls/*
-/data/static/*
+/data/django_static/*
/data/profilepictures/*
/data/archive/*
!/data/logs/
diff --git a/README.md b/README.md
index f2a4bf6..74a7248 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Drinks Manager (Season 3)
+# Drinks Manager
Note: This software is tailored to my own needs.
I probably won't accept feature requests, and don't recommend you
diff --git a/app/db_queries.py b/app/db_queries.py
index 656bbda..dd79bbe 100644
--- a/app/db_queries.py
+++ b/app/db_queries.py
@@ -3,6 +3,7 @@
from django.conf import settings
from django.db import connection
from django.utils.translation import gettext
+from calendar import day_name
COMBINE_ALPHABET = "abcdefghijklmnopqrstuvwxyz"
@@ -15,7 +16,6 @@ def _db_select(sql_select:str):
result = cursor.fetchall()
return result
-
def _combine_results(results:list) -> dict:
'''
e.g.
@@ -80,8 +80,7 @@ def select_history(user, language_code="en") -> list:
result = [list(row) for row in result]
return result
-
-def orders_per_month(user) -> list:
+def select_orders_per_month(user) -> dict:
# number of orders per month (last 12 months)
result_user = _db_select(f"""
select
@@ -102,32 +101,35 @@ def orders_per_month(user) -> list:
group by "month"
order by "month" desc;
""")
- return _combine_results([result_user, result_all])
+ return _combine_results([result_all, result_user])
-
-def orders_per_weekday(user) -> list:
+def select_orders_per_weekday(user) -> list:
# number of orders per weekday (all time)
- result_user = _db_select(f"""
- select
- to_char(datetime, 'Day') as "day",
- sum(amount) as "count"
- from app_order
- where user_id = {user.pk}
- group by "day"
- order by "count" desc;
+ result = _db_select(f"""
+ with q_all as (
+ select
+ extract(isodow from datetime) as "d",
+ sum(amount) as "c"
+ from app_order
+ group by d
+ ), q_user as (
+ select
+ extract(isodow from datetime) as "d",
+ sum(amount) as "c"
+ from app_order
+ where user_id = {user.pk}
+ group by d
+ )
+ select q_all.d as "day", q_all.c, q_user.c from q_all full join q_user on q_all.d = q_user.d
+ group by day, q_all.c, q_user.c
+ order by day asc;
""")
- result_all = _db_select(f"""
- select
- to_char(datetime, 'Day') as "day",
- sum(amount) as "count"
- from app_order
- group by "day"
- order by "count" desc;
- """)
- return _combine_results([result_user, result_all])
+ for i in range(len(result)):
+ day_, all_, user_ = result[i]
+ result[i] = (day_name[int(day_)-1], all_, user_)
+ return result
-
-def orders_per_drink(user) -> list:
+def select_orders_per_drink(user) -> dict:
# number of orders per drink (all time)
result_user = _db_select(f"""
select
@@ -148,4 +150,31 @@ def orders_per_drink(user) -> list:
group by d.product_name
order by "data" desc;
""")
- return _combine_results([result_user, result_all])
+ return _combine_results([result_all, result_user])
+
+def select_order_sum_per_user_all_users() -> list:
+ # sum of all orders per user, for all users
+ result = _db_select(f"""
+ select
+ app_user.username as user,
+ sum(app_order.price_sum) as sum
+ from app_user
+ left outer join app_order on (app_user.id = app_order.user_id)
+ group by app_user.id
+ order by app_user asc;
+ """)
+ return result
+
+def select_deposit_sum_per_user_all_users() -> list:
+ # sum of all orders per user, for all users
+ result = _db_select(f"""
+ select
+ app_user.username as user,
+ sum(rt.transaction_sum) as sum
+ from app_user
+ left outer join app_registertransaction rt on (app_user.id = rt.user_id)
+ where rt.is_user_deposit is true or rt.is_user_deposit is null
+ group by app_user.id
+ order by app_user asc;
+ """)
+ return result
diff --git a/app/locales/de/LC_MESSAGES/django.mo b/app/locales/de/LC_MESSAGES/django.mo
index d7435cb..5d60623 100644
Binary files a/app/locales/de/LC_MESSAGES/django.mo and b/app/locales/de/LC_MESSAGES/django.mo differ
diff --git a/app/locales/de/LC_MESSAGES/django.po b/app/locales/de/LC_MESSAGES/django.po
index fe0dc95..278ff86 100644
--- a/app/locales/de/LC_MESSAGES/django.po
+++ b/app/locales/de/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2023-04-14 23:37+0200\n"
+"POT-Creation-Date: 2023-11-01 19:29+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Julian Müller (ChaoticByte)\n"
"Language: DE\n"
@@ -55,7 +55,7 @@ msgstr "Bestätigen"
msgid "Drinks - History"
msgstr "Getränke - Verlauf"
-#: app/templates/history.html:10 app/templates/userpanel.html:25
+#: app/templates/history.html:10 app/templates/userpanel.html:23
msgid "History"
msgstr "Verlauf"
@@ -165,49 +165,65 @@ msgstr "Wähle deinen Account"
msgid "Drinks - Statistics"
msgstr "Getränke - Statistiken"
-#: app/templates/statistics.html:10 app/templates/userpanel.html:26
+#: app/templates/statistics.html:10 app/templates/userpanel.html:24
msgid "Statistics"
msgstr "Statistiken"
#: app/templates/statistics.html:13
-msgid "Orders per drink"
-msgstr "Bestellungen pro Getränk"
+msgid "orders / drink"
+msgstr "Bestellungen / Getränk"
#: app/templates/statistics.html:16
msgid "drink"
msgstr "Getränk"
-#: app/templates/statistics.html:17 app/templates/statistics.html:34
-#: app/templates/statistics.html:51
-msgid "you"
-msgstr "Du"
-
-#: app/templates/statistics.html:18 app/templates/statistics.html:35
-#: app/templates/statistics.html:52
+#: app/templates/statistics.html:17 app/templates/statistics.html:36
+#: app/templates/statistics.html:53
msgid "all"
msgstr "Alle"
-#: app/templates/statistics.html:30
-msgid "Orders per month (last 12 months)"
-msgstr "Bestellungen pro Monat (letzte 12 Monate)"
+#: app/templates/statistics.html:18 app/templates/statistics.html:37
+#: app/templates/statistics.html:54
+msgid "you"
+msgstr "Du"
-#: app/templates/statistics.html:33
+#: app/templates/statistics.html:32
+msgid "orders / month"
+msgstr "Bestellungen / Monat"
+
+#: app/templates/statistics.html:35
msgid "month"
msgstr "Monat"
-#: app/templates/statistics.html:47
-msgid "Orders per weekday"
-msgstr "Bestellungen pro Wochentag"
+#: app/templates/statistics.html:49
+msgid "orders / weekday"
+msgstr "Bestellungen / Wochentag"
-#: app/templates/statistics.html:50
+#: app/templates/statistics.html:52
msgid "day"
msgstr "Tag"
+#: app/templates/statistics.html:69
+msgid "order sum"
+msgstr "Bestellungen"
+
+#: app/templates/statistics.html:72 app/templates/statistics.html:89
+msgid "user"
+msgstr "Benutzer"
+
+#: app/templates/statistics.html:73 app/templates/statistics.html:90
+msgid "sum"
+msgstr "Summe"
+
+#: app/templates/statistics.html:86
+msgid "deposit sum"
+msgstr "Einzahlungen"
+
#: app/templates/supply.html:7
msgid "Drinks - Supply"
msgstr "Getränke - Beschaffung"
-#: app/templates/supply.html:14 app/templates/userpanel.html:32
+#: app/templates/supply.html:14 app/templates/userpanel.html:30
msgid "Supply"
msgstr "Beschaffung"
@@ -228,7 +244,6 @@ msgid "You are not allowed to view this site."
msgstr "Dir fehlt die Berechtigung, diese Seite anzuzeigen."
#: app/templates/transfer.html:6
-#| msgid "Drinks - Order"
msgid "Drinks - Transfer"
msgstr "Getränke - Geld senden"
@@ -248,11 +263,11 @@ msgstr "Saldo"
msgid "Logout"
msgstr "Abmelden"
-#: app/templates/userpanel.html:30
+#: app/templates/userpanel.html:28
msgid "Transfer"
msgstr "Geld senden"
-#: app/templates/userpanel.html:34
+#: app/templates/userpanel.html:32
msgid "Change Password"
msgstr "Passwort ändern"
diff --git a/app/models.py b/app/models.py
index 681a433..717a1cf 100644
--- a/app/models.py
+++ b/app/models.py
@@ -40,6 +40,7 @@ class Drink(models.Model):
do_not_count = models.BooleanField(default=False)
def delete(self, *args, **kwargs):
+ # we flag the field as deleted.
self.deleted = True
super().save()
@@ -107,10 +108,9 @@ class Order(models.Model):
price_sum = models.DecimalField(max_digits=6, decimal_places=2, default=0, editable=False)
content_litres = models.DecimalField(max_digits=6, decimal_places=3, default=0, editable=False)
- # TODO: Add more comments on how and why the save & delete functions are implemented
- # address this in a refactoring issue.
-
def save(self, *args, **kwargs):
+ # saving this may affect other fields
+ # so we reimplement the save function
drink = Drink.objects.get(pk=self.drink.pk)
if self._state.adding and drink.available > 0:
if not drink.do_not_count:
@@ -126,6 +126,7 @@ class Order(models.Model):
raise ValidationError("This entry can't be changed.")
def delete(self, *args, **kwargs):
+ # when deleting, we affect other fields as well.
self.user.balance += self.price_sum
self.user.save()
drink = Drink.objects.get(pk=self.drink.pk)
diff --git a/app/static/js/main.js b/app/static/js/main.js
deleted file mode 100644
index 711aed8..0000000
--- a/app/static/js/main.js
+++ /dev/null
@@ -1,14 +0,0 @@
-document.addEventListener("DOMContentLoaded", () => {
- let dropdownmenuElement = document.getElementById("dropdownmenu");
- let dropdownmenuButtonElement = document.getElementById("dropdownmenu-button");
- if (dropdownmenuButtonElement != null) {
- dropdownmenuButtonElement.addEventListener("click", () => {
- if (dropdownmenuElement.classList.contains("dropdownvisible")) {
- dropdownmenuElement.classList.remove("dropdownvisible");
- }
- else {
- dropdownmenuElement.classList.add("dropdownvisible");
- }
- })
- }
-});
diff --git a/app/templates/baselayout.html b/app/templates/baselayout.html
index 5783cf9..97ac907 100644
--- a/app/templates/baselayout.html
+++ b/app/templates/baselayout.html
@@ -25,7 +25,7 @@
{% translate "An error occured. Please log out and log in again." %}
-
log out
+
log out
{% endif %}
diff --git a/app/templates/deposit.html b/app/templates/deposit.html
index bbce3e1..cf3dbc1 100644
--- a/app/templates/deposit.html
+++ b/app/templates/deposit.html
@@ -8,20 +8,16 @@
{% block headAdditional %}
-
+
{% endblock %}
{% block content %}
+
+
{% endblock %}
\ No newline at end of file
diff --git a/app/templates/footer.html b/app/templates/footer.html
index 89d58c6..63b51ec 100644
--- a/app/templates/footer.html
+++ b/app/templates/footer.html
@@ -2,6 +2,6 @@
\ No newline at end of file
diff --git a/app/templates/order.html b/app/templates/order.html
index 2cae204..2e5286f 100644
--- a/app/templates/order.html
+++ b/app/templates/order.html
@@ -11,31 +11,31 @@
{% if drink and drink.available > 0 and not drink.deleted %}
{% if user.balance > 0 or user.allow_order_with_negative_balance %}
+
+
{% else %}
-
+
{% endif %}
{% else %}
diff --git a/app/templates/registration/login.html b/app/templates/registration/login.html
index c9ba292..657c713 100644
--- a/app/templates/registration/login.html
+++ b/app/templates/registration/login.html
@@ -10,7 +10,7 @@
{% block headAdditional %}
-
+
{% endblock %}
{% block content %}
@@ -19,7 +19,7 @@
{% endif %}
-
{% translate "Log in" %}
+
-
+
{% translate "Choose your account" %}