diff --git a/abrechenbarkeit.lua b/abrechenbarkeit.lua index b296e52..fefbaa4 100755 --- a/abrechenbarkeit.lua +++ b/abrechenbarkeit.lua @@ -114,6 +114,8 @@ local translations = load_translations({ "en", config.language }) local stylesheet = io.open("style.css"):read("a") local script = io.open("script.js"):read("a") +local can_print = false + local function format(template, params) params = params or {} if template == nil then return "NIL TEMPLATE" end @@ -144,23 +146,23 @@ local function format_amount(amount, tag, classes) end local function format_list(list) - if list == nil then - return nil - end + if list == nil then + return nil + end - local not_first = false - local out = "" - for _, barcode in pairs(list) do - if not_first then - out = out .. ", " .. barcode - else - out = barcode - end + local not_first = false + local out = "" + for _, barcode in pairs(list) do + if not_first then + out = out .. ", " .. barcode + else + out = barcode + end - not_first = true - end + not_first = true + end - return out + return out end local function get_user_theme(username) @@ -225,6 +227,7 @@ local function respond(status, title, body) {+spus} {+products} {+log} + {print_button} {+about} ]], { @@ -232,7 +235,9 @@ local function respond(status, title, body) style = stylesheet, user_style = get_user_theme(path and path:sub(2)), script = script, - head_extra = config.head_extra or "" + head_extra = config.head_extra or "", + print_button = can_print and + [[]] or "" })) if config.header ~= nil then print(config.header) @@ -373,24 +378,24 @@ local function r_transaction_post() local pcode = data.pcode local pcount = tonumber(data.pcount) local comment = data.comment - local pname = data.pname - + local pname = data.pname + if pname ~= nil or (pcode ~= nil and pcode ~= "") then - -- check if barcode exists - 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 - if not exists then - return error_box("{+error.unknown_barcode}") - end + -- check if barcode exists + 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 + if not exists then + return error_box("{+error.unknown_barcode}") + end end - - -- check if product exists + + -- check if product exists local exists = false for p_amount, p_user, p_name in read_products() do if pname == p_name then @@ -403,11 +408,11 @@ local function r_transaction_post() end end if not exists then - return error_box("{+error.unknown_product}: "..pname) + return error_box("{+error.unknown_product}: " .. pname) end end - -- for outside money + -- for outside money user_src = user_src or "@Potential" if amount == nil then return error_box("{+error.invalid_amount}") @@ -469,8 +474,8 @@ local function r_user(username) { time = format_duration(os.time() - last_txn), username = urlencode(username) })) print([[]]) end - - print([[") + end + print(format([[") + name = name, + username = username, + sign = price >= 0 and "-" or "+", + amount = string.format("%.2f", math.abs(price / 100)), + unit = config.unit or "€", + })) + end + print("") - print("") - print(format([[ + print("") + print(format([[
  • {+user.form.transaction}

    @@ -552,13 +557,13 @@ local function r_user(username)

    {+user.form.transfer}

    @@ -579,8 +584,8 @@ local function r_user(username)
  • ]], { - username = username, - disable_class = is_special and "disabled" or "", + username = username, + disable_class = is_special and "disabled" or "", })) print("") end) @@ -591,6 +596,7 @@ local function r_log(filter) if method == "POST" then notif = r_transaction_post() end + can_print = true return respond(200, "Abrechnungen", function() if notif then print(notif) end print([[ {!username} @@ -715,31 +721,31 @@ local function r_users(show_special, filter_negative) })) end end - + if filter_negative ~= nil then - table.sort(users, function(a, b) - return a.balance < b.balance - end) + table.sort(users, function(a, b) + return a.balance < b.balance + end) end - + local inactive_cutoff = os.time() - (tonumber(config.inactive_cutoff) or (30 * 24 * 60 * 60)) local embezzlement = 0 - for _, user in ipairs(users) do + for _, user in ipairs(users) do if filter_negative or user.time > inactive_cutoff then - show_user(user) + show_user(user) - if user.name:sub(1,1) ~= "@" then - if user.balance < 0 then embezzlement = embezzlement - user.balance end - end + if user.name:sub(1, 1) ~= "@" then + if user.balance < 0 then embezzlement = embezzlement - user.balance end + end end end print("") if filter_negative ~= nil then - print(format([[
    {+users.embezzlement}
    ]], { - amount = format_amount(embezzlement) - })) + print(format([[
    {+users.embezzlement}
    ]], { + amount = format_amount(embezzlement) + })) - return + return end print(format([[
    {+users.inactive_list}
    ") end) end @@ -1063,7 +1070,7 @@ if path == "/" then elseif query.spus then return r_users(true, nil) elseif query.users and query.export then - return r_export_balances() + return r_export_balances() else return r_users(false, query.negative and (query.maximum or 0)) end diff --git a/locale/en.ini b/locale/en.ini index f20e252..0fd1d56 100644 --- a/locale/en.ini +++ b/locale/en.ini @@ -79,3 +79,4 @@ error.open_barcodes=Failed to open barcodes file error.no_path=No path users.inactive_list=Inactive Users users.embezzlement=A total of {amount} are currently under embezzlement. +print=Print \ No newline at end of file