This commit is contained in:
@@ -39,6 +39,35 @@ func (deltas Deltas) Transactions() Transactions {
|
||||
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 {
|
||||
date string
|
||||
description string
|
||||
|
||||
Reference in New Issue
Block a user