aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiley L. <riley@e926.de>2025-07-29 23:39:51 +0200
committerRiley L. <riley@e926.de>2025-07-29 23:39:51 +0200
commite433181494e1145ba99a85da1896ca771b80ff20 (patch)
tree1e039774b047ad8e41e5adb3d8c9357a728927ea
parentf3562cf44ec056281488ccadb78d87f86dbcfce5 (diff)
downloadabrechenbarkeit-e433181494e1145ba99a85da1896ca771b80ff20.tar
abrechenbarkeit-e433181494e1145ba99a85da1896ca771b80ff20.tar.bz2
abrechenbarkeit-e433181494e1145ba99a85da1896ca771b80ff20.tar.zst
add warning at low balances
-rwxr-xr-xabrechenbarkeit.lua20
-rw-r--r--locale/de.ini3
-rw-r--r--locale/en.ini4
-rw-r--r--readme.md4
-rw-r--r--style.css18
5 files changed, 47 insertions, 2 deletions
diff --git a/abrechenbarkeit.lua b/abrechenbarkeit.lua
index cb9f30e..29de0ef 100755
--- a/abrechenbarkeit.lua
+++ b/abrechenbarkeit.lua
@@ -431,6 +431,19 @@ local function r_transaction_post()
return error_box("{+error.open_log}")
end
local time = os.time()
+
+ -- check if new balance would be less than ;min
+ local bal = balances()[user_dst]
+ if amount < 0 and (( bal + amount ) <= (tonumber(config.balance_min) or -99999)) then
+ return format([[
+ <div class="notif error"><p>{+user.form.transaction.funds}</p></div>
+ ]], {
+ balance = format_amount(bal, "span", ""),
+ threshold = format_amount(tonumber(config.balance_min), "span", ""),
+ })
+ end
+
+ -- add transaction
log:write(string.format("%d,%s,%s,%d,%s,%s,%s\n",
time, user_src, user_dst, amount,
pcode and (pcode .. (pname and " (" .. pname .. ")" or "")) or (pname or ""),
@@ -438,6 +451,7 @@ local function r_transaction_post()
comment))
log:flush()
log:close()
+
return format([[
<div class="notif"><p>{+user.form.transaction.success}: {amount} ({!comment})</p></div>
<audio src="{sound}" autoplay></audio>
@@ -464,6 +478,12 @@ local function r_user(username)
local new_user = balance == nil
balance = balance or 0
if notif then print(notif) end
+ if not is_special and balance <= (tonumber(config.balance_warning) or -99999) then
+ print(format([[<div class="notif warning"><p><i>{+user.balance.warning}</i></p></div>]], {
+ threshold = format_amount(tonumber(config["balance_warning"]), "span", ""),
+ threshold2 = format_amount(tonumber(config["balance_min"]), "span", ""),
+ }))
+ end
if is_special then
print(format([[<div class="notif"><p><i>{+user.special}</i></p></div>]]))
end
diff --git a/locale/de.ini b/locale/de.ini
index ad2068e..13c84d8 100644
--- a/locale/de.ini
+++ b/locale/de.ini
@@ -29,6 +29,9 @@ time.minutes=Minuten
time.second=Sekunde
time.seconds=Sekunden
user.balance=Kontostand
+user.balance.warning=Warnung:
+dein Kontostand ist unter {threshold}. Du wirst unter {threshold2} nichts mehr kaufen können.
+user.form.transaction.funds=Fehler: diese Transaktion würde dein Konto unter {threshold} bringen, sie wurde nicht durchgeführt. ( {balance} ).
user.shortcuts=Schnellzugriff
user.form.buy.submit=Kaufen
user.form.buy=Produkt kaufen
diff --git a/locale/en.ini b/locale/en.ini
index 03651b7..33f1516 100644
--- a/locale/en.ini
+++ b/locale/en.ini
@@ -61,6 +61,8 @@ time.minutes=minutes
time.second=second
time.seconds=seconds
user.balance=Current balance
+user.balance.warning=Warning: your balance is below {threshold}. You are not able to purchase anything, if it will lower your balance bellow {threshold2}.
+user.form.transaction.funds=Error: this transaction would push you bellow {threshold}, it was not applied ( {balance} ).
user.form.buy.submit=Buy
user.form.buy=Buy Product
user.form.restock.submit=Restock
@@ -79,4 +81,4 @@ user.view_log=View user log
users.embezzlement=A total of {amount} are currently under embezzlement.
users.filter=Filter
users.inactive_list=Inactive Users
-users=Users \ No newline at end of file
+users=Users
diff --git a/readme.md b/readme.md
index 544bb06..ba59815 100644
--- a/readme.md
+++ b/readme.md
@@ -16,6 +16,10 @@ useful for development or proxyless deployments.
- `products` stores the product list as CSV (`barcode,price,user,name`)
- `config` stores configuration parameters as ESV (`key=value`)
- `transaction_sound`: URL to sound played when creating a transaction
+ - `language`: Language code, e.g. de, en, es, ja_en, nl, pt_BR, zh_Hans
+ - `balance_warning`: balance in cents to show warning at
+ - `balance_min`: minimum balance to be held by all users, in cents
+ - `unit`: unit used in the UI, e.g. €, $, EUR
## Migration from Strichliste
diff --git a/style.css b/style.css
index ce7329c..42232fe 100644
--- a/style.css
+++ b/style.css
@@ -86,13 +86,29 @@ nav> :last-child {
}
.notif.error {
- background-color: rgb(118, 13, 13);
+ background-color: #8c2121;
+}
+
+.notif.error i {
+ color: black;
+}
+
+.notif.warning i {
+ /* color: black; */
+}
+
+.notif.warning {
+ background-color: #9b6501;
}
.notif p {
margin: 5px;
}
+.notif.warning {
+ background-color
+}
+
/* landing page */
.section {
background-color: var(--b2);