48 lines
781 B
Go
48 lines
781 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 {
|
|
value, _ := a.Balance.Float64()
|
|
result[i] = newDelta(t.Date, a.Name, value)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func newDelta(d time.Time, a string, v float64) Delta {
|
|
return Delta{
|
|
Date: d,
|
|
Account: a,
|
|
Value: v,
|
|
Currency: USD, // TODO
|
|
}
|
|
}
|
|
|
|
func (delta Delta) Plus(other Delta) Delta {
|
|
return Delta{
|
|
Date: other.Date,
|
|
Account: delta.Account,
|
|
Value: delta.Value + other.Value,
|
|
Currency: other.Currency,
|
|
}
|
|
}
|