Files
ana-ledger/ledger/delta.go
2023-10-22 22:03:26 -06:00

39 lines
590 B
Go

package ledger
import (
"time"
"github.com/howeyc/ledger"
)
type Currency string
const (
USD = Currency("$")
)
type Delta struct {
Date time.Time
Account string
Value float64
Currency Currency
}
func newDeltas(t *ledger.Transaction) []Delta {
result := make([]Delta, len(t.AccountChanges))
for i, a := range t.AccountChanges {
result[i] = newDelta(t.Date, a)
}
return result
}
func newDelta(d time.Time, a ledger.Account) Delta {
value, _ := a.Balance.Float64()
return Delta{
Date: d,
Account: a.Name,
Value: value,
Currency: USD, // TODO
}
}