mirror of
https://codeberg.org/metamuffin/abrechenbarkeit.git
synced 2025-01-01 09:14:34 +00:00
add optional owners to products to realise different cash pools
This commit is contained in:
parent
292a8f0de7
commit
3922bb59f5
1 changed files with 34 additions and 12 deletions
|
@ -163,8 +163,8 @@ local function read_products()
|
||||||
if l == "" or l == nil then
|
if l == "" or l == nil then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
local barcode, price, name = string.match(l, "([%w_-]+),(-?%d+),([%w_ -]*)")
|
local barcode, price, name, owner = string.match(l, "([%w_-]+),(-?%d+),([%w_ -]*),([%w_ -]*)")
|
||||||
return barcode, tonumber(price), name
|
return barcode, tonumber(price), name, owner
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -223,14 +223,24 @@ local function r_user_post(username)
|
||||||
local comment = data.comment
|
local comment = data.comment
|
||||||
local pcode = nil
|
local pcode = nil
|
||||||
local pcount = nil
|
local pcount = nil
|
||||||
|
local powner = nil
|
||||||
if data.pcode then
|
if data.pcode then
|
||||||
for p_barcode, p_amount, p_name in read_products() do
|
for p_barcode, p_amount, p_name, p_owner in read_products() do
|
||||||
if p_barcode == data.pcode then
|
if p_barcode == data.pcode then
|
||||||
|
powner = p_owner
|
||||||
pcount = (tonumber(data.pcount) or 1) * (data.negate_pcount ~= nil and -1 or 1)
|
pcount = (tonumber(data.pcount) or 1) * (data.negate_pcount ~= nil and -1 or 1)
|
||||||
pcode = p_barcode
|
pcode = p_barcode
|
||||||
if amount == nil then amount = pcount * p_amount end
|
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",
|
if comment == nil then
|
||||||
math.abs(pcount), p_name) end
|
comment = string.format("%s %d %s", pcount < 0 and "Buy" or "Restock",
|
||||||
|
math.abs(pcount), p_name)
|
||||||
|
|
||||||
|
powner_comment = string.format("%s %d %s %s %s",
|
||||||
|
pcount < 0 and "Sell" or "Restock", -- TOOD: look for name
|
||||||
|
math.abs(pcount), p_name,
|
||||||
|
pcount < 0 and "to" or "by",
|
||||||
|
username)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if amount == nil then
|
if amount == nil then
|
||||||
|
@ -248,7 +258,12 @@ 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()
|
||||||
|
-- subtract from buyer
|
||||||
log:write(string.format("%d,%s,%d,%s,%s,%s\n", time, username, amount, pcode or "", pcount or "", comment))
|
log:write(string.format("%d,%s,%d,%s,%s,%s\n", time, username, amount, pcode or "", pcount or "", comment))
|
||||||
|
-- add to owner
|
||||||
|
if powner then
|
||||||
|
log:write(string.format("%d,%s,%d,%s,%s,%s\n", time, powner, -amount, pcode or "", pcount or "", powner_comment))
|
||||||
|
end
|
||||||
log:flush()
|
log:flush()
|
||||||
log:close()
|
log:close()
|
||||||
return string.format([[
|
return string.format([[
|
||||||
|
@ -429,9 +444,9 @@ local function r_products_post()
|
||||||
if new_products == nil then
|
if new_products == nil then
|
||||||
return error_box("failed to open new products")
|
return error_box("failed to open new products")
|
||||||
end
|
end
|
||||||
for a_barcode, price, name in read_products() do
|
for a_barcode, price, name, owner in read_products() do
|
||||||
if barcode ~= a_barcode then
|
if barcode ~= a_barcode then
|
||||||
new_products:write(string.format("%s,%d,%s\n", a_barcode, price, name))
|
new_products:write(string.format("%s,%d,%s,%s\n", a_barcode, price, name, owner))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
new_products:flush()
|
new_products:flush()
|
||||||
|
@ -450,7 +465,11 @@ local function r_products_post()
|
||||||
if products == nil then
|
if products == nil then
|
||||||
return error_box("failed to open products")
|
return error_box("failed to open products")
|
||||||
end
|
end
|
||||||
products:write(string.format("%s,%d,%s\n", barcode, price, name))
|
local owner = data.owner or ""
|
||||||
|
if name:match("^[%w_ -]*$") == nil then
|
||||||
|
return error_box("owner invalid")
|
||||||
|
end
|
||||||
|
products:write(string.format("%s,%d,%s,%s\n", barcode, price, name, owner))
|
||||||
products:flush()
|
products:flush()
|
||||||
products:close()
|
products:close()
|
||||||
end
|
end
|
||||||
|
@ -472,6 +491,8 @@ local function r_products()
|
||||||
<input type="text" name="name" id="name" />
|
<input type="text" name="name" id="name" />
|
||||||
<label for="price">Price (ct): </label>
|
<label for="price">Price (ct): </label>
|
||||||
<input type="number" name="price" id="price" />
|
<input type="number" name="price" id="price" />
|
||||||
|
<label for="owner">Owner: </label>
|
||||||
|
<input type="text" name="owner" id="owner" />
|
||||||
<label for="barcode">Barcode: </label>
|
<label for="barcode">Barcode: </label>
|
||||||
<input type="text" name="barcode" id="barcode" />
|
<input type="text" name="barcode" id="barcode" />
|
||||||
<input type="submit" value="Add" class="amount-ntr button" />
|
<input type="submit" value="Add" class="amount-ntr button" />
|
||||||
|
@ -485,16 +506,17 @@ local function r_products()
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
]])
|
]])
|
||||||
print([[<table class="productlist"><tr><th>Name</th><th>Price</th><th>Barcode</th><th>Count</th></tr>]])
|
print([[<table class="productlist"><tr><th>Name</th><th>Price</th><th>Barcode</th><th>Count</th><th>Owner</th></tr>]])
|
||||||
local pbals = product_balances()
|
local pbals = product_balances()
|
||||||
for barcode, price, name in read_products() do
|
for barcode, price, name, owner in read_products() do
|
||||||
print(string.format([[
|
print(string.format([[
|
||||||
<tr><td>%s</td><td class="amount-%s">%.02f€</td><td>%s</td><td>%s</td></tr>
|
<tr><td>%s</td><td class="amount-%s">%.02f€</td><td>%s</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"
|
pbals[barcode] or "0",
|
||||||
|
owner
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
print("</table>")
|
print("</table>")
|
||||||
|
|
Loading…
Reference in a new issue