aboutsummaryrefslogtreecommitdiff
path: root/abrechenbarkeit.lua
diff options
context:
space:
mode:
authorRiley L. <riley@e926.de>2025-05-12 12:34:19 +0200
committerRiley L. <riley@e926.de>2025-05-12 12:34:19 +0200
commit868fa10610a4341e7c0d634310049930a33fa9e0 (patch)
tree4fd5a74dec645365db7b0b4b280fd2ab37b62ecb /abrechenbarkeit.lua
parent48cbf9adcdd70e7da84e28f39b037cc077465e86 (diff)
downloadabrechenbarkeit-868fa10610a4341e7c0d634310049930a33fa9e0.tar
abrechenbarkeit-868fa10610a4341e7c0d634310049930a33fa9e0.tar.bz2
abrechenbarkeit-868fa10610a4341e7c0d634310049930a33fa9e0.tar.zst
add shortcuts to user list to purchase items without scanning
slight mirgation, i.e. sorting products by user is necessary
Diffstat (limited to 'abrechenbarkeit.lua')
-rwxr-xr-xabrechenbarkeit.lua113
1 files changed, 87 insertions, 26 deletions
diff --git a/abrechenbarkeit.lua b/abrechenbarkeit.lua
index 0210865..4820094 100755
--- a/abrechenbarkeit.lua
+++ b/abrechenbarkeit.lua
@@ -373,25 +373,27 @@ local function r_transaction_post()
local pcode = data.pcode
local pcount = tonumber(data.pcount)
local comment = data.comment
- local barcode_name = nil
+ local pname = data.pname
- if pcode ~= nil and pcode ~= "" then
+ if pname ~= nil or (pcode ~= nil and pcode ~= "") then
-- check if barcode exists
- local exists = false
- for p_name, p_barcode in read_barcodes() do
- if p_barcode == pcode then
- exists = true
- barcode_name = p_name
+ if pname == nil then
+ local exists = false
+ for p_name, p_barcode in read_barcodes() do
+ if p_barcode == pcode then
+ exists = true
+ pname = p_name
+ end
end
- end
- if not exists then
- return error_box("{+error.unknown_barcode}")
+ if not exists then
+ return error_box("{+error.unknown_barcode}")
+ end
end
-- check if product exists
local exists = false
for p_amount, p_user, p_name in read_products() do
- if barcode_name == p_name then
+ if pname == p_name then
pcount = (tonumber(data.pcount) or 1) * (data.negate_pcount ~= nil and -1 or 1)
amount = amount or pcount * p_amount
user_src = user_src or p_user
@@ -401,7 +403,7 @@ local function r_transaction_post()
end
end
if not exists then
- return error_box("{+error.unknown_product}"..barcode_name)
+ return error_box("{+error.unknown_product}: "..pname)
end
end
@@ -467,8 +469,8 @@ local function r_user(username)
{ time = format_duration(os.time() - last_txn), username = urlencode(username) }))
print([[</div>]])
end
- print([[
- <ul class="userforms"><li>
+
+ print([[<ul class="userforms"><li>
<div class="amount-presets backgroundbox">]])
for _, type in ipairs({ 1, -1 }) do
for _, amount in ipairs({ 50, 100, 150, 200, 500, 1000 }) do
@@ -488,6 +490,44 @@ local function r_user(username)
end
end
print("</div></li>")
+
+ print(format([[<li><div class="backgroundbox shortcuts">
+ <h3>{+user.shortcuts}</h3>]]))
+ local lastcategory = nil
+ -- user is category; @ is removed for ZSKs
+ for price, category, name in read_products() do
+ if lastcategory ~= category then
+ if lastcategory ~= nil then
+ print("</ul></div></label>")
+ end
+ print(format([[<label>
+ <input type="checkbox" hidden />
+ <div>
+ <span class="button amount-ntr">{c}</span>
+ <ul>]], {
+ c = category:gsub("@", ""),
+ }))
+
+ lastcategory = category
+ end
+
+ print(format([[<li><form method="POST">
+ <input type="text" name="user_dst" value="{!username}" hidden />
+ <input type="number" name="pcount" value="-1" hidden />
+ <input type="text" name="pname" value="{name}" hidden />
+ <input class="button amount-ntr" value="{name}
+{+price.amount}" type="submit" />
+ </form></li>]], {
+ name = name,
+ username = username,
+ sign = price >= 0 and "-" or "+",
+ amount = string.format("%.2f", math.abs(price / 100)),
+ unit = config.unit or "€",
+ }))
+ end
+ print("</ul></div></label>")
+
+ print("</div></li>")
print(format([[
<li><form class="transaction box backgroundbox {disable_class}" action="" method="POST">
<h3>{+user.form.transaction}</h3>
@@ -516,11 +556,10 @@ local function r_user(username)
local users = get_active_users();
for _, u in ipairs(users) do
if u.name ~= username then
- print(format("<option value={!name}>{name}</option>", { name = u.name }))
+ print(format([[<option value="{!name}">{name}</option>]], { name = u.name }))
end
end
- print(format([[
- </select>
+ print(format([[</select>
<input type="text" name="user_src" value="{!username}" hidden />
<label for="amount">{+field.amount}: </label>
<input type="number" name="amount" id="amount" />
@@ -538,8 +577,11 @@ local function r_user(username)
<label for="pcode">{+field.barcode}: </label>
<input type="text" name="pcode" id="pcode" />
<input type="submit" value="{+user.form.restock.submit}" class="button amount-pos" />
- </form></li>
- ]], { username = username, disable_class = is_special and "disabled" or "" }))
+ </form></li>]],
+ {
+ username = username,
+ disable_class = is_special and "disabled" or "",
+ }))
print("</ul>")
end)
end
@@ -743,7 +785,8 @@ local function r_products_post()
if name == nil or name:match("^" .. matchers.name .. "$") == nil then
return error_box("{+error.invalid_name}")
end
-
+
+ -- delete product
if data.delete then
local new_products = io.open("products.new", "w+")
if new_products == nil then
@@ -798,13 +841,31 @@ local function r_products_post()
if user == nil or user:match(matchers_global.user) == nil then
return error_box("{+error.invalid_user}")
end
- local products = io.open("products", "a+")
- if products == nil then
- return error_box("{+error.open_products}")
+ -- add product
+ local new_products = io.open("products.new", "w+")
+ if new_products == nil then
+ return error_box("{+error.open_new_products}")
+ end
+ local wrote = nil
+ -- prepend to any block in the file containing products of the same user
+ -- the shortcuts feature expects this!
+ for a_price, a_user, a_name in read_products() do
+ if user == a_user and not wrote then
+ wrote = true
+ products:write(string.format("%d,%s,%s\n", price, user, name))
+ end
+
+ new_products:write(string.format("%d,%s,%s\n", a_price, a_user, a_name))
+ end
+
+ -- append if not wrote already
+ if not wrote then
+ products:write(string.format("%d,%s,%s\n", price, user, name))
end
- products:write(string.format("%d,%s,%s\n", price, user, name))
- products:flush()
- products:close()
+
+ new_products:flush()
+ new_products:close()
+ os.rename("products.new", "products")
end
end