mirror of
https://codeberg.org/metamuffin/abrechenbarkeit.git
synced 2024-12-29 16:14:36 +00:00
add columns for product txns
This commit is contained in:
parent
79657b9e94
commit
20c3a25e43
1 changed files with 32 additions and 11 deletions
|
@ -118,8 +118,9 @@ local function read_log()
|
||||||
if l == "" or l == nil then
|
if l == "" or l == nil then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
local time, username, amount, comment = string.match(l, "(%d+),([%w_ -]+),(-?%d+),([%w_ -]*)")
|
local time, username, amount, pcode, pcount, comment = string.match(l,
|
||||||
return tonumber(time), username, tonumber(amount), comment
|
"(%d+),([%w_ -]+),(-?%d+),([%w_-]*),(-?%d*),([%w_ -]*)")
|
||||||
|
return tonumber(time), username, tonumber(amount), pcode, tonumber(pcount), comment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -141,15 +142,25 @@ end
|
||||||
|
|
||||||
local function balances()
|
local function balances()
|
||||||
local users = {}
|
local users = {}
|
||||||
for _, username, amount, _ in read_log() do
|
for _, username, amount, _, _, _ in read_log() do
|
||||||
users[username] = (users[username] or 0) + amount
|
users[username] = (users[username] or 0) + amount
|
||||||
end
|
end
|
||||||
return users
|
return users
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function product_balances()
|
||||||
|
local products = {}
|
||||||
|
for _, _, _, pcode, pcount, _ in read_log() do
|
||||||
|
if pcode ~= nil and pcount ~= nil then
|
||||||
|
products[pcode] = (products[pcode] or 0) + pcount
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return products
|
||||||
|
end
|
||||||
|
|
||||||
local function last_txns()
|
local function last_txns()
|
||||||
local users = {}
|
local users = {}
|
||||||
for time, username, _, _ in read_log() do
|
for time, username, _, _, _, _ in read_log() do
|
||||||
users[username] = time
|
users[username] = time
|
||||||
end
|
end
|
||||||
return users
|
return users
|
||||||
|
@ -163,10 +174,14 @@ local function r_user_post(username)
|
||||||
local data = form_data()
|
local data = form_data()
|
||||||
local amount = nil
|
local amount = nil
|
||||||
local comment = ""
|
local comment = ""
|
||||||
|
local pcode = nil
|
||||||
|
local pcount = nil
|
||||||
if data.product then
|
if data.product then
|
||||||
for p_barcode, p_amount, p_name in read_products() do
|
for p_barcode, p_amount, p_name in read_products() do
|
||||||
if p_barcode == data.product then
|
if p_barcode == data.product then
|
||||||
amount = p_amount
|
pcount = tonumber(data.count) or -1
|
||||||
|
pcode = p_barcode
|
||||||
|
amount = pcount * p_amount
|
||||||
comment = p_name
|
comment = p_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -188,7 +203,7 @@ local function r_user_post(username)
|
||||||
return error_box("failed to open log")
|
return error_box("failed to open log")
|
||||||
end
|
end
|
||||||
local time = os.time()
|
local time = os.time()
|
||||||
log:write(string.format("%d,%s,%d,%s\n", time, username, amount, comment))
|
log:write(string.format("%d,%s,%d,%s,%s,%s\n", time, username, amount, pcode or "", pcount or "", comment))
|
||||||
log:flush()
|
log:flush()
|
||||||
log:close()
|
log:close()
|
||||||
return string.format([[
|
return string.format([[
|
||||||
|
@ -263,8 +278,8 @@ end
|
||||||
local function r_log(filter)
|
local function r_log(filter)
|
||||||
return respond(200, "Abrechnungen", function()
|
return respond(200, "Abrechnungen", function()
|
||||||
print("<table>")
|
print("<table>")
|
||||||
print("<tr><th>Time</th><th>Username</th><th>Amount</th><th>Comment</th></tr>")
|
print("<tr><th>Time</th><th>Username</th><th>Amount</th><th>P.-Barcode</th><th>P.-Count</th><th>Comment</th></tr>")
|
||||||
for time, username, amount, comment in read_log() do
|
for time, username, amount, pcode, pcount, comment in read_log() do
|
||||||
if filter == nil or filter == username then
|
if filter == nil or filter == username then
|
||||||
print(string.format([[
|
print(string.format([[
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -272,6 +287,8 @@ local function r_log(filter)
|
||||||
<td>%s</td>
|
<td>%s</td>
|
||||||
<td class="amount-%s">%.02f€</td>
|
<td class="amount-%s">%.02f€</td>
|
||||||
<td>%s</td>
|
<td>%s</td>
|
||||||
|
<td>%s</td>
|
||||||
|
<td>%s</td>
|
||||||
<td>
|
<td>
|
||||||
<form action="/%s" method="POST">
|
<form action="/%s" method="POST">
|
||||||
<input type="number" name="amount" id="amount" value="%d" hidden />
|
<input type="number" name="amount" id="amount" value="%d" hidden />
|
||||||
|
@ -284,6 +301,8 @@ local function r_log(filter)
|
||||||
time, format_duration(os.time() - time),
|
time, format_duration(os.time() - time),
|
||||||
escape(username),
|
escape(username),
|
||||||
amount >= 0 and "pos" or "neg", amount / 100,
|
amount >= 0 and "pos" or "neg", amount / 100,
|
||||||
|
escape(pcode) or "",
|
||||||
|
pcount and tostring(pcount) or "",
|
||||||
escape(comment),
|
escape(comment),
|
||||||
escape(username),
|
escape(username),
|
||||||
-amount,
|
-amount,
|
||||||
|
@ -397,14 +416,16 @@ local function r_products()
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
]])
|
]])
|
||||||
print("<table><tr><th>Name</th><th>Price</th><th>Barcode</th></tr>")
|
print("<table><tr><th>Name</th><th>Price</th><th>Barcode</th><th>Count</th></tr>")
|
||||||
|
local pbals = product_balances()
|
||||||
for barcode, price, name in read_products() do
|
for barcode, price, name in read_products() do
|
||||||
print(string.format([[
|
print(string.format([[
|
||||||
<tr><td>%s</td><td class="amount-%s">%.02f€</td><td>%s</td></tr>
|
<tr><td>%s</td><td class="amount-%s">%.02f€</td><td>%s</td><td>%s</td></tr>
|
||||||
]],
|
]],
|
||||||
name,
|
name,
|
||||||
price >= 0 and "pos" or "neg", price / 100,
|
price >= 0 and "pos" or "neg", price / 100,
|
||||||
barcode
|
barcode,
|
||||||
|
pbals[barcode] or "0"
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
print("</table>")
|
print("</table>")
|
||||||
|
|
Loading…
Reference in a new issue