Compare commits

...

2 Commits

Author SHA1 Message Date
Bel LaPointe
768ce8e92e cumulative bal in reg includes bpis
All checks were successful
cicd / ci (push) Successful in 59s
2025-04-03 12:25:39 -06:00
Bel LaPointe
757afa603e hide zeros only in bal 2025-04-03 12:11:32 -06:00
4 changed files with 8 additions and 8 deletions

View File

@@ -97,7 +97,7 @@ func Main() {
transactions := deltas.Transactions() transactions := deltas.Transactions()
for i, transaction := range transactions { for i, transaction := range transactions {
balances := ledger.Deltas(transaction).Like(q).Group(group).Balances().WithBPIs(bpis) balances := ledger.Deltas(transaction).Like(q).Group(group).Balances().WithBPIsAt(bpis, transaction[0].Date).Nonzero()
shouldPrint := false shouldPrint := false
shouldPrint = shouldPrint || len(balances) > 2 shouldPrint = shouldPrint || len(balances) > 2
if config.Query.NoExchanging { if config.Query.NoExchanging {
@@ -110,7 +110,7 @@ func Main() {
} }
if shouldPrint { if shouldPrint {
fmt.Printf("%s\t%s\n", transaction[0].Date, transaction[0].Description) fmt.Printf("%s\t%s\n", transaction[0].Date, transaction[0].Description)
FPrintBalances(os.Stdout, "\t\t", balances, transactions[:i+1].Deltas().Like(q).Group(group).Balances()) FPrintBalances(os.Stdout, "\t\t", balances, transactions[:i+1].Deltas().Like(q).Group(group).Balances().WithBPIsAt(bpis, transaction[0].Date).Nonzero())
} }
} }
default: default:

View File

@@ -157,7 +157,7 @@ func (balances Balances) WithBPIsAt(bpis BPIs, date string) Balances {
if k2 == USD { if k2 == USD {
result[k][USD] = result[k][USD] + v2 result[k][USD] = result[k][USD] + v2
} else if scalar := bpis[k2].Lookup(date); scalar != nil { } else if scalar := bpis[k2].Lookup(date); scalar != nil {
result[k][USD] = result[k][USD] + *scalar*v2 result[k][USD] = result[k][USD] + v2*(*scalar)
} else { } else {
result[k][k2] = result[k][k2] + v2 result[k][k2] = result[k][k2] + v2
} }

View File

@@ -57,10 +57,7 @@ func (deltas Deltas) Balances() Balances {
} }
result[delta.Name][delta.Currency] += delta.Value result[delta.Name][delta.Currency] += delta.Value
if result[delta.Name][delta.Currency] < 0.000000001 && result[delta.Name][delta.Currency] > -0.000000001 { if result[delta.Name][delta.Currency] < 0.000000001 && result[delta.Name][delta.Currency] > -0.000000001 {
delete(result[delta.Name], delta.Currency) result[delta.Name][delta.Currency] = 0
if len(result[delta.Name]) == 0 {
delete(result, delta.Name)
}
} }
} }
return result return result

View File

@@ -38,9 +38,12 @@ func TestDeltas(t *testing.T) {
} }
balances := deltas.Balances() balances := deltas.Balances()
if len(balances) != 1 { if len(balances) != 2 {
t.Error(len(balances), balances) t.Error(len(balances), balances)
} }
if balances["a"][""] != 0 {
t.Error(balances["a"])
}
if balances["b"][""] != 1.3 { if balances["b"][""] != 1.3 {
t.Error(balances["b"]) t.Error(balances["b"])
} }