WERKS EZ PZ

This commit is contained in:
Bel LaPointe
2023-10-24 12:49:42 -06:00
parent 26b8174fb3
commit 24d0e829b3
2 changed files with 50 additions and 7 deletions

View File

@@ -12,6 +12,26 @@ func NewFile(p string) (File, error) {
return f, err
}
func (file File) Balances(like ...Like) (map[string]map[Currency]float64, error) {
deltas, err := file.Deltas(like...)
if err != nil {
return nil, err
}
result := make(map[string]map[Currency]float64)
for _, delta := range deltas {
if _, ok := result[delta.Account]; !ok {
result[delta.Account] = make(map[Currency]float64)
}
if _, ok := result[delta.Account][delta.Currency]; !ok {
result[delta.Account][delta.Currency] = 0
}
result[delta.Account][delta.Currency] += delta.Value
}
return result, nil
}
func (file File) Deltas(like ...Like) ([]Delta, error) {
transactions, err := file.transactions()
if err != nil {