From 2ce78d2b429c62be8747b00d7230e36593d42f05 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Sat, 20 Jul 2024 11:40:06 -0600 Subject: [PATCH] got transactions into rows in transactions.html, now gotta fix column with for description then go for editable --- cmd/http/public/transactions.html | 41 +++++++++++++++++++------------ cmd/http/router.go | 8 +++--- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/cmd/http/public/transactions.html b/cmd/http/public/transactions.html index 40bacc2..d36dd8c 100644 --- a/cmd/http/public/transactions.html +++ b/cmd/http/public/transactions.html @@ -15,6 +15,7 @@ } xmlhttp.send(body); } + function callback(responseBody, responseStatus) { } //var f = String(window.location).split("/transactions.html")[1] @@ -22,6 +23,7 @@ // f = "/ledger.dat" //} //f = "." + f + function init() { const zeroPad = (num, places) => String(num).padStart(places, '0') var d = new Date() @@ -32,14 +34,16 @@ load() } + function load() { http("GET", "/api/transactions" /*?f="+f*/, (body, status) => { var d = JSON.parse(body) console.log("loading", d) loadBalances(d.balances) - loadDeltas(d.deltas) + loadTransactions(d.transactions) }) } + function loadBalances(balances) { console.log("loading balances", balances) var result = `` @@ -49,27 +53,32 @@ result += `
` document.getElementById("bal").innerHTML = result } - function loadDeltas(deltas) { - console.log(deltas[0]) - for (var i = 0; i < deltas.length/2; i++) { - tmp = deltas[i] - deltas[i] = deltas[deltas.length-1-i] - deltas[deltas.length-1-i] = tmp - } - console.log(deltas[0]) + + function loadTransactions(transactions) { + transactions.reverse() + console.log(transactions[0]) + var result = `` - for (var k of deltas) { + for (var t of transactions) { result += `` - result += ` ` - result += ` ` - result += ` ` - result += ` ` - result += ` ` + result += ` ` + result += ` ` + result += ` ` result += `` } result += `
${k.Date}${k.Description}${k.Name}${k.Currency}${k.Value}${t[0].Date}${t[0].Description}` + for (var delta of t) { + result += ` ` + result += ` ` + result += ` ` + result += ` ` + result += ` ` + } + result += `
${delta.Name}${delta.Currency}${delta.Value}
` + document.getElementById("reg").innerHTML = result } + function stage(who, contributesToHouse) { var d = new Date() const zeroPad = (num, places) => String(num).padStart(places, '0') @@ -114,7 +123,7 @@ -
+
Register
diff --git a/cmd/http/router.go b/cmd/http/router.go index af85e7f..f398b70 100644 --- a/cmd/http/router.go +++ b/cmd/http/router.go @@ -94,16 +94,18 @@ func (router Router) APITransactions(w http.ResponseWriter, r *http.Request) { houseRelatedDeltas := deltas.Like(ledger.LikeTransactions( deltas.Like(ledger.LikeName(`^House`))..., )) - sixMonths := time.Hour * 24 * 365 / 2 + recent := time.Hour * 24 * 365 / 6 json.NewEncoder(w).Encode(map[string]any{ "deltas": houseRelatedDeltas. - Like(ledger.LikeAfter(time.Now().Add(-1 * sixMonths).Format("2006-01"))), + Like(ledger.LikeAfter(time.Now().Add(-1 * recent).Format("2006-01"))), "balances": houseRelatedDeltas.Balances(). Like(`^(Zach|Bel|House[^:]*:Debts:)`). Group(`^[^:]*`). WithBPIs(bpis), - "transactions": houseRelatedDeltas.Transactions(), + "transactions": houseRelatedDeltas. + Like(ledger.LikeAfter(time.Now().Add(-1 * recent).Format("2006-01"))). + Transactions(), }) }