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([[
Time | Username | Amount | P.-Barcode | P.-Count | Comment | |
---|---|---|---|---|---|---|
Time | +Username | +Amount | +P.-Barcode | +P.-Count | +Comment | +Actions | +%s | %.02f€ | %s | -%s | +%s %s | %s |