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([[]]) end - print([[ - ") 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 - products:write(string.format("%d,%s,%s\n", price, user, name)) - products:flush() - products:close() + 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 + + new_products:flush() + new_products:close() + os.rename("products.new", "products") end end diff --git a/locale/de.ini b/locale/de.ini index ac89608..139d272 100644 --- a/locale/de.ini +++ b/locale/de.ini @@ -29,6 +29,7 @@ time.minutes=Minuten time.second=Sekunde time.seconds=Sekunden user.balance=Kontostand +user.shortcuts=Schnellzugriff user.form.buy.submit=Kaufen user.form.buy=Produkt kaufen user.form.restock.submit=Wiederauffüllen diff --git a/locale/en.ini b/locale/en.ini index a2cdb16..29de51a 100644 --- a/locale/en.ini +++ b/locale/en.ini @@ -41,6 +41,7 @@ time.minutes=minutes time.second=second time.seconds=seconds user.balance=Current balance +user.shortcuts=Shortcuts user.form.buy.submit=Buy user.form.buy=Buy Product user.form.restock.submit=Restock diff --git a/style.css b/style.css index e1f7a74..bcb9ca8 100644 --- a/style.css +++ b/style.css @@ -220,7 +220,7 @@ h1 { list-style-type: none; } -input.button { +.button { place-content: center; padding: 0.8em 0.5em; border: none; @@ -257,7 +257,7 @@ input.amount-neg { color: #00e1ff; } -input.amount-ntr { +.amount-ntr { background-color: #0e646f; } @@ -291,6 +291,53 @@ ul.userforms > li { width: 36em; } +/* shortcuts */ +.shortcuts > label { + display: inline-flex; + /* dunno why, but will otherwise clip the headline ¯\_(ツ)_/¯ */ +} + +.shortcuts > label > div > span { + display: block; + margin: .25em; + user-select: none; +} + +.shortcuts > label > div > ul { + display: none; +} + +.shortcuts > label > input:checked + div > span { + border: none; + text-decoration: underline; + font-weight: bold; +} + +.shortcuts > label > input:checked + div > ul { + display: inherit; +} + +.shortcuts input.button { + font-size: 1.2rem; + margin: .5rem; +} + +.shortcuts ul { + content: ''; + display: table; + clear: both; + list-style: none; + margin-left: 0.5rem; + padding: 0; +} + +.shortcuts li { + width: fit-content; + float: left; + padding: 0.1rem; +} + + /* create transaction box */ .box { display: grid; @@ -350,7 +397,6 @@ form.disabled input { } @media print { - nav, .container { display: none;