a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package ledger
|
|
|
|
import "time"
|
|
|
|
// AccountKind classifies an account in the double-entry ledger.
|
|
type AccountKind int
|
|
|
|
const (
|
|
AccountAsset AccountKind = iota
|
|
AccountLiability
|
|
AccountEquity
|
|
AccountRevenue
|
|
AccountExpense
|
|
)
|
|
|
|
// Money is a minor-unit monetary amount in a fixed currency.
|
|
type Money struct {
|
|
Minor int64
|
|
Currency string
|
|
}
|
|
|
|
// Account is a single ledger account.
|
|
type Account struct {
|
|
ID string
|
|
Name string
|
|
Kind AccountKind
|
|
Balance Money
|
|
Created time.Time
|
|
}
|
|
|
|
// Entry is one leg of a transaction posted against an account.
|
|
type Entry struct {
|
|
AccountID string
|
|
Amount Money
|
|
Memo string
|
|
}
|
|
|
|
// Transaction is a balanced set of entries.
|
|
type Transaction struct {
|
|
ID string
|
|
Posted time.Time
|
|
Entries []Entry
|
|
Memo string
|
|
}
|
|
|
|
// Add returns the sum of two amounts in the same currency.
|
|
func (m Money) Add(other Money) Money {
|
|
return Money{Minor: m.Minor + other.Minor, Currency: m.Currency}
|
|
}
|
|
|
|
// Sub returns the difference of two amounts in the same currency.
|
|
func (m Money) Sub(other Money) Money {
|
|
return Money{Minor: m.Minor - other.Minor, Currency: m.Currency}
|
|
}
|
|
|
|
// IsZero reports whether the amount is exactly zero.
|
|
func (m Money) IsZero() bool {
|
|
return m.Minor == 0
|
|
}
|
|
|
|
// Negate flips the sign of an amount.
|
|
func (m Money) Negate() Money {
|
|
return Money{Minor: -m.Minor, Currency: m.Currency}
|
|
}
|