Compare commits

...

2 Commits

Author SHA1 Message Date
bel
45c4d7b684 transactions.html omits non-payee currency and value table cells
All checks were successful
cicd / ci (push) Successful in 1m3s
2024-07-20 20:45:31 -06:00
bel
59205fba4c ledger.Delta.Payee = true 2024-07-20 20:25:37 -06:00
6 changed files with 61 additions and 9 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

@@ -16,9 +16,10 @@ type Delta struct {
Description string
isSet bool
Transaction string
Payee bool
}
func newDelta(transaction string, d, desc, name string, v float64, c string, isSet bool) Delta {
func newDelta(transaction string, payee bool, d, desc, name string, v float64, c string, isSet bool) Delta {
return Delta{
Date: d,
Name: name,
@@ -27,11 +28,12 @@ func newDelta(transaction string, d, desc, name string, v float64, c string, isS
Description: desc,
isSet: isSet,
Transaction: transaction,
Payee: payee,
}
}
func (delta Delta) Debug() string {
return fmt.Sprintf("{@%s %s:\"%s\" %s%.2f %s}", delta.Date, delta.Name, delta.Description, func() string {
return fmt.Sprintf("{@%s %s(payee=%v):\"%s\" %s%.2f %s}", delta.Date, delta.Name, delta.Payee, delta.Description, func() string {
if !delta.isSet {
return ""
}

View File

@@ -6,11 +6,14 @@ import (
func TestDelta(t *testing.T) {
d := "2099-08-07"
delta := newDelta("x", d, "", "name", 34.56, "$", false)
delta := newDelta("x", true, d, "", "name", 34.56, "$", false)
if delta.Transaction != "x" {
t.Error(delta.Transaction)
}
if !delta.Payee {
t.Error(delta.Payee)
}
if delta.Date != d {
t.Error(delta.Date)
}

View File

@@ -144,9 +144,10 @@ func TestFileAmend(t *testing.T) {
t.Fatal(err)
} else if filtered := deltas.Like(func(d Delta) bool {
c.old.Transaction = d.Transaction
c.old.Payee = d.Payee
return d == c.old
}); len(filtered) != 1 {
t.Fatalf("input %s didnt include old %+v in %+v", c.from, c.old, deltas)
t.Fatalf("input \n\t%s \ndidnt include old \n\t%+v \nin \n\t%+v: \n\t%+v", c.from, c.old, deltas, filtered)
}
if err := files.Amend(c.old, c.now); err != nil {
@@ -371,6 +372,7 @@ func TestFileDeltas(t *testing.T) {
Value: -97.92,
Currency: USD,
Description: "Electricity / Power Bill TG2PJ-2PLP5",
Payee: true,
},
{
Date: "2022-12-12",
@@ -385,6 +387,7 @@ func TestFileDeltas(t *testing.T) {
Value: -1.00,
Currency: USD,
Description: "Test pay chase TG32S-BT2FF",
Payee: true,
},
{
Date: "2022-12-12",

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 {
@@ -94,6 +99,7 @@ func (t transaction) deltas() Deltas {
sums[recipient.currency] += recipient.value
result = append(result, newDelta(
t.name,
true,
t.date,
t.description,
recipient.name,
@@ -111,6 +117,7 @@ func (t transaction) deltas() Deltas {
} else {
result = append(result, newDelta(
t.name,
false,
t.date,
t.description,
t.payee,
@@ -190,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 {