From bccab824ba3c62bbdd7c957819ecdba75e648f44 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 31 Oct 2024 02:00:42 +0100 Subject: product list --- strichliste.lua | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'strichliste.lua') diff --git a/strichliste.lua b/strichliste.lua index be31ed0..004d276 100755 --- a/strichliste.lua +++ b/strichliste.lua @@ -3,10 +3,12 @@ local function escape(s) return s:gsub("<", "<"):gsub("<", "<") end + local function urldecode(s) if s == nil then return nil end return s:gsub("+", " "):gsub("%%20", " ") end + local function urlencode(s) if s == nil then return nil end return s:gsub(" ", "%%20") @@ -90,7 +92,8 @@ local function respond(status, title, body) ]], escape(title), stylesheet, script, config.head_extra or "")) @@ -136,6 +139,7 @@ local function read_log() return tonumber(time), username, tonumber(amount), comment end end + local function read_products() local log = io.open("products", "r") if log == nil then @@ -159,6 +163,7 @@ local function balances() end return users end + local function last_txns() local users = {} for time, username, _, _ in read_log() do @@ -338,6 +343,23 @@ local function r_create_user() return redirect(string.format("/%s", urlencode(username))) end +local function r_products() + respond(200, "Product List", function() + print("

Product List

") + print("") + for barcode, price, name in read_products() do + print(string.format([[ + + ]], + name, + price >= 0 and "pos" or "neg", price / 100, + barcode + )) + end + print("
NamePriceAmount
%s%.02f€%s
") + end) +end + local function extract_username() if path == nil then return respond_error("no path") @@ -350,7 +372,9 @@ local function extract_username() end if path == "/" then - if query.log then + if query.products then + return r_products() + elseif query.log then return r_log() elseif query.create_user then return r_create_user() -- cgit v1.2.3-70-g09d2