diff --git a/abrechenbarkeit.lua b/abrechenbarkeit.lua index 77d7fd0..9244484 100755 --- a/abrechenbarkeit.lua +++ b/abrechenbarkeit.lua @@ -167,30 +167,21 @@ local function last_txns() end local function get_active_users() - local user_balances = {} + local user_balances = {} for time, username, amount, _, _, _ in read_log() do user_balances[username] = { - time = time, - username = username, - balance = (user_balances[username] or {balance = 0}).balance + amount + time = time, + username = username, + balance = (user_balances[username] or { balance = 0 }).balance + amount } end - local users = {} - for _, user in pairs(user_balances) do - table.insert(users, user) - end - - table.sort(users, function(a,b) return a.time > b.time end) - for k, user in pairs(users) do - io.stderr:write(string.format("%s %s %s %s\n", - k, - os.date("!%Y-%m-%dT%H:%M:%SZ", user.time), - user.username, - user.balance - )) - end - + local users = {} + for _, user in pairs(user_balances) do + table.insert(users, user) + end + + table.sort(users, function(a, b) return a.time > b.time end) return users end @@ -210,7 +201,8 @@ local function r_user_post(username) pcount = (tonumber(data.pcount) or 1) * (data.negate_pcount ~= nil and -1 or 1) pcode = p_barcode 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 + 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 @@ -331,7 +323,7 @@ local function r_log(filter) if filter == nil or filter == username then print(string.format([[ - %d (%s ago) + %s (%s ago) %s %.02f€ %s @@ -346,7 +338,7 @@ local function r_log(filter) ]], - time, format_duration(os.time() - time), + os.date("!%Y-%m-%dT%H:%M:%SZ", time), format_duration(os.time() - time), escape(username), amount >= 0 and "pos" or "neg", amount / 100, escape(pcode) or "", @@ -373,7 +365,7 @@ local function r_index() ]]) print("