transactions.html omits non-payee currency and value table cells
cicd / ci (push) Successful in 1m3s Details

main
bel 2024-07-20 20:45:31 -06:00
parent 59205fba4c
commit 45c4d7b684
3 changed files with 47 additions and 5 deletions

View File

@ -67,8 +67,8 @@
for (var delta of t) {
result += ` <tr>`
result += ` <td><span style="font-variant: petite-caps;">${delta.Name.split(":")[0]}</span><span style="opacity: 0.6;"> :${delta.Name.split(":").slice(1, 100).join(":")}</span></td>`
result += ` <td style="text-align: right; width: 2em;">${delta.Currency}</td>`
result += ` <td style="text-align: right; width: 5em;">${delta.Value}</td>`
result += ` <td style="text-align: right; width: 2em;">${delta.Payee ? delta.Currency : ""}</td>`
result += ` <td style="text-align: right; width: 5em;">${delta.Payee ? delta.Value : ""}</td>`
result += ` </tr>`
}
result += ` </table></td>`

View File

@ -45,6 +45,11 @@ func (transaction Transaction) Payee() string {
candidates := []string{}
for name, balance := range balances {
deltas := Deltas(transaction).Like(LikeName(`^` + name + `$`))
if len(deltas) != 1 {
continue
}
everyoneElse := balances.NotLike(`^` + name + `$`).Group(`^`)[""]
matches := true
for currency, value := range balance {
@ -192,7 +197,18 @@ func readTransaction(name string, r *bufio.Reader) (transaction, error) {
sumPerRecipient[recipient.name] += recipient.value
}
slices.Sort(recipients)
for _, k := range recipients {
n := 0
for i := range result.recipients {
if result.recipients[i].name == k {
n += 1
}
}
if n != 1 {
continue
}
v := sumPerRecipient[k]
everyoneElse := 0.0
for j := range sumPerRecipient {

View File

@ -10,13 +10,13 @@ import (
func TestTransactionPayee(t *testing.T) {
given := Transaction{
Delta{Name: "x", Transaction: "a", Value: 1},
Delta{Name: "y", Transaction: "a", Value: 2},
Delta{Name: "x", Transaction: "a", Value: 9},
Delta{Name: "Withdrawal:z", Transaction: "a", Value: -3},
Delta{Name: "Withdrawal:z", Transaction: "a", Value: -6},
}
got := given.Payee()
if got != "Withdrawal:z" {
if got != "x" {
t.Error(got)
}
}
@ -76,6 +76,32 @@ func TestReadTransaction(t *testing.T) {
},
err: io.EOF,
},
"multi send": {
input: `
2003-04-05 Reasoning here
A:B $1.00
A:B $2.00
C:D
`,
want: transaction{
date: "2003-04-05",
description: "Reasoning here",
payee: "C:D",
recipients: []transactionRecipient{
{
name: "A:B",
value: 1.0,
currency: "$",
},
{
name: "A:B",
value: 2.0,
currency: "$",
},
},
},
err: io.EOF,
},
}
for name, d := range cases {