mirror of
https://codeberg.org/metamuffin/abrechenbarkeit.git
synced 2024-12-29 00:04:35 +00:00
restock form
This commit is contained in:
parent
7b07957b6e
commit
f7af00c0d2
2 changed files with 39 additions and 21 deletions
|
@ -172,30 +172,27 @@ end
|
|||
|
||||
local function r_user_post(username)
|
||||
local data = form_data()
|
||||
local amount = nil
|
||||
local comment = ""
|
||||
local amount = tonumber(data.amount)
|
||||
local comment = data.comment
|
||||
local pcode = nil
|
||||
local pcount = nil
|
||||
if data.product then
|
||||
if data.pcode then
|
||||
for p_barcode, p_amount, p_name in read_products() do
|
||||
if p_barcode == data.product then
|
||||
pcount = tonumber(data.count) or -1
|
||||
if p_barcode == data.pcode then
|
||||
pcount = (tonumber(data.pcount) or 1) * (data.negate_pcount ~= nil and -1 or 1)
|
||||
pcode = p_barcode
|
||||
amount = pcount * p_amount
|
||||
comment = p_name
|
||||
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
|
||||
end
|
||||
end
|
||||
if amount == nil then
|
||||
return error_box("unknown product")
|
||||
end
|
||||
else
|
||||
amount = tonumber(data.amount)
|
||||
comment = data.comment or ""
|
||||
end
|
||||
if amount == nil then
|
||||
return error_box("amount invalid")
|
||||
end
|
||||
if comment:match("^[%w_ -]*$") == nil then
|
||||
if comment == nil or comment:match("^[%w_ -]*$") == nil then
|
||||
return error_box("comment invalid")
|
||||
end
|
||||
local log = io.open("log", "a+")
|
||||
|
@ -241,7 +238,7 @@ local function r_user(username)
|
|||
]], format_duration(os.time() - last_txn), username))
|
||||
end
|
||||
print([[<div class="transactions container firstchildlarge">]])
|
||||
print([[<div class="amount-presets backgroundbox">]])
|
||||
print([[<div class="amount-presets backgroundbox">]])
|
||||
for _, type in ipairs({ 1, -1 }) do
|
||||
for _, amount in ipairs({ 50, 100, 150, 200, 500, 1000 }) do
|
||||
print(string.format([[
|
||||
|
@ -266,10 +263,23 @@ local function r_user(username)
|
|||
</form>
|
||||
<form class="transaction box backgroundbox" action="" method="POST" id="buy_product">
|
||||
<h3>Buy Product</h3>
|
||||
<label for="product">Product: </label>
|
||||
<input type="text" name="product" id="product" />
|
||||
<input type="text" name="negate_pcount" value="1" hidden />
|
||||
<label for="pcount">Count: </label>
|
||||
<input type="number" name="pcount" id="pcount" value="1" />
|
||||
<label for="pcode">Product Barcode: </label>
|
||||
<input type="text" name="pcode" id="pcode" />
|
||||
<input class="amount-neg button" type="submit" value="Buy" />
|
||||
</form>
|
||||
<form class="transaction box backgroundbox" action="" method="POST" id="buy_product">
|
||||
<h3>Restock Product</h3>
|
||||
<label for="pcount">Count: </label>
|
||||
<input type="number" name="pcount" id="pcount" value="1" />
|
||||
<label for="amount">Upstream price: </label>
|
||||
<input type="number" name="amount" id="amount" />
|
||||
<label for="pcode">Product Barcode: </label>
|
||||
<input type="text" name="pcode" id="pcode" />
|
||||
<input type="submit" value="Restock" />
|
||||
</form>
|
||||
]])
|
||||
print("</div>")
|
||||
end)
|
||||
|
@ -278,7 +288,15 @@ end
|
|||
local function r_log(filter)
|
||||
return respond(200, "Abrechnungen", function()
|
||||
print([[<table class="log">]])
|
||||
print("<tr><th>Time</th><th>Username</th><th>Amount</th><th>P.-Barcode</th><th>P.-Count</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>
|
||||
<th>Actions</th>
|
||||
</tr>]])
|
||||
for time, username, amount, pcode, pcount, comment in read_log() do
|
||||
if filter == nil or filter == username then
|
||||
print(string.format([[
|
||||
|
@ -287,7 +305,7 @@ local function r_log(filter)
|
|||
<td>%s</td>
|
||||
<td class="amount-%s">%.02f€</td>
|
||||
<td>%s</td>
|
||||
<td>%s</td>
|
||||
<td>%s %s</td>
|
||||
<td>%s</td>
|
||||
<td>
|
||||
<form action="/%s" method="POST">
|
||||
|
@ -302,7 +320,7 @@ local function r_log(filter)
|
|||
escape(username),
|
||||
amount >= 0 and "pos" or "neg", amount / 100,
|
||||
escape(pcode) or "",
|
||||
pcount and tostring(pcount) or "",
|
||||
pcount and (pcount < 0 and "buy" or "stock") or "", pcount and tostring(math.abs(pcount)) or "",
|
||||
escape(comment),
|
||||
escape(username),
|
||||
-amount,
|
||||
|
@ -399,12 +417,12 @@ local function r_products()
|
|||
<div class="container">
|
||||
<form action="/?products" method="POST" class="box backgroundbox">
|
||||
<h3>Add Product</h3>
|
||||
<label for="barcode">Barcode: </label>
|
||||
<input type="text" name="barcode" id="barcode" />
|
||||
<label for="name">Name: </label>
|
||||
<input type="text" name="name" id="name" />
|
||||
<label for="price">Price (ct): </label>
|
||||
<input type="number" name="price" id="price" />
|
||||
<label for="barcode">Barcode: </label>
|
||||
<input type="text" name="barcode" id="barcode" />
|
||||
<input type="submit" value="Add" class="amount-ntr button" />
|
||||
</form>
|
||||
<form action="/?products" method="POST" class="box backgroundbox">
|
||||
|
@ -423,7 +441,7 @@ local function r_products()
|
|||
<tr><td>%s</td><td class="amount-%s">%.02f€</td><td>%s</td><td>%s</td></tr>
|
||||
]],
|
||||
name,
|
||||
price >= 0 and "pos" or "neg", price / 100,
|
||||
-price >= 0 and "pos" or "neg", -price / 100,
|
||||
barcode,
|
||||
pbals[barcode] or "0"
|
||||
))
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
document.addEventListener("keypress", ev => {
|
||||
if (!(document.activeElement instanceof HTMLInputElement)) {
|
||||
if (ev.code.startsWith("Digit"))
|
||||
document.forms.buy_product.product.value += ev.code.substring(5)
|
||||
document.forms.buy_product.pcode.value += ev.code.substring(5)
|
||||
if (ev.code == "Enter")
|
||||
document.forms.buy_product.submit()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue