From 0b975df3e498853a4dbf85cc197e0e147fbc1315 Mon Sep 17 00:00:00 2001 From: "Riley L." Date: Thu, 2 Jan 2025 00:40:33 +0100 Subject: fix delete barcode functionality; fix styling of product menus --- abrechenbarkeit.lua | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'abrechenbarkeit.lua') diff --git a/abrechenbarkeit.lua b/abrechenbarkeit.lua index 2ebafc3..dee8b4d 100755 --- a/abrechenbarkeit.lua +++ b/abrechenbarkeit.lua @@ -698,6 +698,26 @@ end local function r_products_post() local data = form_data() + + if data.deletebarcode then + local barcode = data.barcode + + -- remove barcode + local new_barcodes = io.open("barcodes.new", "w+") + if new_barcodes == nil then + return error_box("{+error.open_new_barcodes}") + end + for name, a_barcode in read_barcodes() do + if barcode ~= a_barcode then + new_barcodes:write(string.format("%s,%s\n", name, a_barcode)) + end + end + new_barcodes:flush() + new_barcodes:close() + os.rename("barcodes.new", "barcodes") + return + end + local name = data.name if name == nil or name:match("^[%w_-]*$") == nil then return error_box("{+error.invalid_name}") @@ -710,7 +730,7 @@ local function r_products_post() end for price, user, a_name in read_products() do if name ~= a_name then - new_products:write(string.format("%d,%s,%s\n", price, user, name)) + new_products:write(string.format("%d,%s,%s\n", price, user, a_name)) end end new_products:flush() @@ -785,7 +805,7 @@ local function r_products() currency = config.unit or "€", })) for _, _, name in read_products() do - print(format([[]], { + print(format([[]], { name = name, })) end @@ -804,7 +824,7 @@ local function r_products() currency = config.unit or "€", })) for _, _, name in read_products() do - print(format([[]], { + print(format([[]], { name = name, })) end @@ -814,7 +834,7 @@ local function r_products()

{+products.form.removebarcode}

- +
-- cgit v1.2.3-70-g09d2