WERKS EZ PZ
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user