Compare commits
2 Commits
2ce78d2b42
...
1d18cb50c5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d18cb50c5 | ||
|
|
bd85dcc86a |
@@ -62,13 +62,13 @@
|
|||||||
for (var t of transactions) {
|
for (var t of transactions) {
|
||||||
result += `<tr>`
|
result += `<tr>`
|
||||||
result += ` <td style="width: 6em;">${t[0].Date}</td>`
|
result += ` <td style="width: 6em;">${t[0].Date}</td>`
|
||||||
result += ` <td>${t[0].Description}</td>`
|
result += ` <td style="width: 10em;">${t[0].Description}</td>`
|
||||||
result += ` <td><table>`
|
result += ` <td><table style="margin: 0;">`
|
||||||
for (var delta of t) {
|
for (var delta of t) {
|
||||||
result += ` <tr>`
|
result += ` <tr>`
|
||||||
result += ` <td>${delta.Name}</td>`
|
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">${delta.Currency}</td>`
|
result += ` <td style="text-align: right; width: 2em;">${delta.Currency}</td>`
|
||||||
result += ` <td style="text-align: right">${delta.Value}</td>`
|
result += ` <td style="text-align: right; width: 5em;">${delta.Value}</td>`
|
||||||
result += ` </tr>`
|
result += ` </tr>`
|
||||||
}
|
}
|
||||||
result += ` </table></td>`
|
result += ` </table></td>`
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ func (balances Balances) Group(pattern string) Balances {
|
|||||||
result := make(Balances)
|
result := make(Balances)
|
||||||
p := regexp.MustCompile(pattern)
|
p := regexp.MustCompile(pattern)
|
||||||
for k, v := range balances {
|
for k, v := range balances {
|
||||||
k2 := p.FindString(k)
|
k2 := k
|
||||||
if k2 == "" {
|
if p.MatchString(k) {
|
||||||
k2 = k
|
k2 = p.FindString(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
was := result[k2]
|
was := result[k2]
|
||||||
|
|||||||
@@ -39,6 +39,35 @@ func (deltas Deltas) Transactions() Transactions {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (transaction Transaction) Payee() string {
|
||||||
|
balances := Deltas(transaction).Balances()
|
||||||
|
|
||||||
|
candidates := []string{}
|
||||||
|
|
||||||
|
for name, balance := range balances {
|
||||||
|
everyoneElse := balances.NotLike(`^` + name + `$`).Group(`^`)[""]
|
||||||
|
matches := true
|
||||||
|
for currency, value := range balance {
|
||||||
|
matches = matches && everyoneElse[currency]*-1 == value
|
||||||
|
}
|
||||||
|
if matches {
|
||||||
|
candidates = append(candidates, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
slices.Sort(candidates)
|
||||||
|
|
||||||
|
if len(candidates) == 0 {
|
||||||
|
panic(balances)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, candidate := range candidates {
|
||||||
|
if strings.HasPrefix(candidate, "Withdrawal") {
|
||||||
|
return candidate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return candidates[len(candidates)-1]
|
||||||
|
}
|
||||||
|
|
||||||
type transaction struct {
|
type transaction struct {
|
||||||
date string
|
date string
|
||||||
description string
|
description string
|
||||||
|
|||||||
@@ -8,6 +8,19 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestTransactionPayee(t *testing.T) {
|
||||||
|
given := Transaction{
|
||||||
|
Delta{Name: "x", Transaction: "a", Value: 1},
|
||||||
|
Delta{Name: "y", Transaction: "a", Value: 2},
|
||||||
|
Delta{Name: "Withdrawal:z", Transaction: "a", Value: -3},
|
||||||
|
}
|
||||||
|
|
||||||
|
got := given.Payee()
|
||||||
|
if got != "Withdrawal:z" {
|
||||||
|
t.Error(got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDeltasTransactions(t *testing.T) {
|
func TestDeltasTransactions(t *testing.T) {
|
||||||
given := Deltas{
|
given := Deltas{
|
||||||
Delta{Date: "2", Name: "x", Transaction: "a"},
|
Delta{Date: "2", Name: "x", Transaction: "a"},
|
||||||
|
|||||||
Reference in New Issue
Block a user