diff --git a/abrechenbarkeit.lua b/abrechenbarkeit.lua index 79a4951..0358055 100755 --- a/abrechenbarkeit.lua +++ b/abrechenbarkeit.lua @@ -172,30 +172,27 @@ end local function r_user_post(username) local data = form_data() - local amount = nil - local comment = "" + local amount = tonumber(data.amount) + local comment = data.comment local pcode = nil local pcount = nil - if data.product then + if data.pcode then for p_barcode, p_amount, p_name in read_products() do - if p_barcode == data.product then - pcount = tonumber(data.count) or -1 + if p_barcode == data.pcode then + pcount = (tonumber(data.pcount) or 1) * (data.negate_pcount ~= nil and -1 or 1) pcode = p_barcode - amount = pcount * p_amount - comment = p_name + if amount == nil then amount = pcount * p_amount end + if comment == nil then comment = string.format("%s %d %s", pcount < 0 and "Buy" or "Restock", math.abs(pcount), p_name) end end end if amount == nil then return error_box("unknown product") end - else - amount = tonumber(data.amount) - comment = data.comment or "" end if amount == nil then return error_box("amount invalid") end - if comment:match("^[%w_ -]*$") == nil then + if comment == nil or comment:match("^[%w_ -]*$") == nil then return error_box("comment invalid") end local log = io.open("log", "a+") @@ -241,7 +238,7 @@ local function r_user(username) ]], format_duration(os.time() - last_txn), username)) end print([[
]]) - print([[
]]) + print([[
]]) for _, type in ipairs({ 1, -1 }) do for _, amount in ipairs({ 50, 100, 150, 200, 500, 1000 }) do print(string.format([[ @@ -266,10 +263,23 @@ local function r_user(username)

Buy Product

- - + + + + +
+
+

Restock Product

+ + + + + + + +
]]) print("
") end) @@ -278,7 +288,15 @@ end local function r_log(filter) return respond(200, "Abrechnungen", function() print([[]]) - print("") + print([[ + + + + + + + + ]]) for time, username, amount, pcode, pcount, comment in read_log() do if filter == nil or filter == username then print(string.format([[ @@ -287,7 +305,7 @@ local function r_log(filter) - + ]], name, - price >= 0 and "pos" or "neg", price / 100, + -price >= 0 and "pos" or "neg", -price / 100, barcode, pbals[barcode] or "0" )) diff --git a/script.js b/script.js index 46f8961..1a494b8 100644 --- a/script.js +++ b/script.js @@ -3,7 +3,7 @@ document.addEventListener("keypress", ev => { if (!(document.activeElement instanceof HTMLInputElement)) { if (ev.code.startsWith("Digit")) - document.forms.buy_product.product.value += ev.code.substring(5) + document.forms.buy_product.pcode.value += ev.code.substring(5) if (ev.code == "Enter") document.forms.buy_product.submit() }
TimeUsernameAmountP.-BarcodeP.-CountComment
TimeUsernameAmountP.-BarcodeP.-CountCommentActions
%s %.02f€ %s%s%s %s %s
@@ -302,7 +320,7 @@ local function r_log(filter) escape(username), amount >= 0 and "pos" or "neg", amount / 100, escape(pcode) or "", - pcount and tostring(pcount) or "", + pcount and (pcount < 0 and "buy" or "stock") or "", pcount and tostring(math.abs(pcount)) or "", escape(comment), escape(username), -amount, @@ -399,12 +417,12 @@ local function r_products()

Add Product

- - + +
@@ -423,7 +441,7 @@ local function r_products()
%s%.02f€%s%s