diff --git a/cmd/http/public/transactions.html b/cmd/http/public/transactions.html
index b72388e..9475ec7 100644
--- a/cmd/http/public/transactions.html
+++ b/cmd/http/public/transactions.html
@@ -67,8 +67,8 @@
for (var delta of t) {
result += `
`
result += ` | ${delta.Name.split(":")[0]} :${delta.Name.split(":").slice(1, 100).join(":")} | `
- result += ` ${delta.Currency} | `
- result += ` ${delta.Value} | `
+ result += ` ${delta.Payee ? delta.Currency : ""} | `
+ result += ` ${delta.Payee ? delta.Value : ""} | `
result += `
`
}
result += ` `
diff --git a/src/ledger/transaction.go b/src/ledger/transaction.go
index 3ba747b..6eaf8e8 100644
--- a/src/ledger/transaction.go
+++ b/src/ledger/transaction.go
@@ -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 {
diff --git a/src/ledger/transaction_test.go b/src/ledger/transaction_test.go
index 69b86c3..e531792 100644
--- a/src/ledger/transaction_test.go
+++ b/src/ledger/transaction_test.go
@@ -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 {