Documentation ¶
Overview ¶
Package fin declares basic types used in personal finance.
Package fin declares basic types used in personal finance.
Index ¶
- Constants
- Variables
- func FormatUSD(x int64) string
- func ParseUSD(s string) (v int64, e error)
- type Account
- type AccountDelta
- type AccountDeltas
- type AccountSet
- type Cat
- type CatFilter
- type CatPayment
- func (c *CatPayment) CatRecByIndex(idx int) CatRec
- func (c *CatPayment) CatRecCount() int
- func (c *CatPayment) CatRecs() []CatRec
- func (c *CatPayment) Marshall(m Marshaller, ptr interface{})
- func (c *CatPayment) PaymentId() int64
- func (c *CatPayment) Reconcile(id int64) bool
- func (c *CatPayment) Reconciled() bool
- func (c *CatPayment) SetSingleCat(cat Cat) bool
- func (c *CatPayment) Total() int64
- func (c *CatPayment) Unmarshall(ptr interface{}, u Unmarshaller) error
- func (c *CatPayment) WithCat(f CatFilter) bool
- func (c *CatPayment) WithPayment(id int64) bool
- type CatPaymentBuilder
- func (c *CatPaymentBuilder) AddCatRec(cr CatRec) *CatPaymentBuilder
- func (c *CatPaymentBuilder) Build() CatPayment
- func (c *CatPaymentBuilder) ClearCatRecs() *CatPaymentBuilder
- func (c *CatPaymentBuilder) Set(cp *CatPayment) *CatPaymentBuilder
- func (c *CatPaymentBuilder) SetPaymentId(x int64) *CatPaymentBuilder
- func (c *CatPaymentBuilder) SetReconciled(x bool) *CatPaymentBuilder
- type CatPopularity
- type CatRec
- type CatSet
- type CatTotals
- type CatType
- type Entry
- type EntryBalance
- type EntryUpdater
- type Marshaller
- type Permission
- type RecurringEntry
- type RecurringEntryUpdater
- type RecurringPeriod
- type RecurringUnit
- type ReviewStatus
- type Unmarshaller
- type User
Constants ¶
const ( Reviewed ReviewStatus = 1 NotReviewed = 0 ReviewInProgress = -1 )
Variables ¶
var ( // Expense is the top level expense category. Expense = Cat{Type: ExpenseCat} // Income is the top level income category. Income = Cat{Type: IncomeCat} )
Functions ¶
Types ¶
type Account ¶
type Account struct { // Unique Id Id int64 // Name Name string Active bool // Ending balance Balance int64 // Reconciled balance RBalance int64 // Count of all transactions Count int // Count of reconciled transactions RCount int // Auto import should ignore transactions before this date. ImportSD time.Time }
Account represents an account for payment.
type AccountDelta ¶
type AccountDelta struct { // Balance is change in overall balance in cents. Balance int64 // RBalance is change in overall reconciled balance in cents. RBalance int64 // Count is the change in number of transactions. Count int // RCount is the change in number of reconciled transactions. RCount int }
AccountDelta represents changes in a single account.
func (*AccountDelta) String ¶
func (a *AccountDelta) String() string
type AccountDeltas ¶
type AccountDeltas map[int64]*AccountDelta
AccountDeltas represents changes in multiple accounts.
func (AccountDeltas) Exclude ¶
func (a AccountDeltas) Exclude(catPayment *CatPayment)
Exclude excludes catPayment in these deltas.
func (AccountDeltas) Include ¶
func (a AccountDeltas) Include(catPayment *CatPayment)
Include includes catPayment in these deltas.
type AccountSet ¶
AccountSet represents a set of account ids.
func (AccountSet) Include ¶
func (a AccountSet) Include(catPayment CatPayment)
type Cat ¶
A Cat specifies a raw category.
func CatFromString ¶
CatFromString converts a string e.g 0:4 to a Cat instance
func NewCat ¶
NewCat creates a Cat value from a string e.g 0:4. If string cannot be parsed, returns the zero value.
type CatFilter ¶
CatFilter filters categories. c is the category. Returns true if c should be included or false otherwise.
type CatPayment ¶
type CatPayment struct {
// contains filtered or unexported fields
}
CatPayment specifies category, amount, and payment information for a single Entry. CatPayment consist of one payment method and zero or more CatRecs. The zero value of CatPayment has no CatRecs, a payment ID of zero, and is not reconciled. CatPayment works like a value type with the assignment operator, but to test for equality use reflect.DeepEqual.
func NewCatPayment ¶
func NewCatPayment(cat Cat, amount int64, reconciled bool, paymentId int64) CatPayment
NewCatPayment returns a new CatPayment having payment of paymentId and single category of cat with given amount. reconciled indicates whether or not new instance should be reconciled under paymentId. Using this function is faster than using CatPaymentBuilder, but this function can only create CatPayment instances with a single category. Note that Total() on returned CatPayment will return -amount.
func (*CatPayment) CatRecByIndex ¶
func (c *CatPayment) CatRecByIndex(idx int) CatRec
func (*CatPayment) CatRecCount ¶
func (c *CatPayment) CatRecCount() int
CatRecCount returns the number of CatRecs
func (*CatPayment) CatRecs ¶
func (c *CatPayment) CatRecs() []CatRec
func (*CatPayment) Marshall ¶
func (c *CatPayment) Marshall(m Marshaller, ptr interface{})
Marshall writes this value to a database row. ptr is the database row.
func (*CatPayment) PaymentId ¶
func (c *CatPayment) PaymentId() int64
func (*CatPayment) Reconcile ¶
func (c *CatPayment) Reconcile(id int64) bool
Marks as reconciled. id is a payment Id. Returns true on success or false if id does not match payment ID or any of the CatRecs.
func (*CatPayment) Reconciled ¶
func (c *CatPayment) Reconciled() bool
Reconciled returns the reconcile flag.
func (*CatPayment) SetSingleCat ¶
func (c *CatPayment) SetSingleCat(cat Cat) bool
SetSingleCat changes this instance to a single category clearing any previous split transaction. SetSingleCat does not change the value Total() returns. Returns true on success. If cat represents the paymentId of this instance, then SetSingleCat makes no change and returns false.
func (*CatPayment) Total ¶
func (c *CatPayment) Total() int64
Total returns the total. Negative means debit, positive means credit for the payment ID.
func (*CatPayment) Unmarshall ¶
func (c *CatPayment) Unmarshall(ptr interface{}, u Unmarshaller) error
Unmarshall sets this value to what is in the database row. ptr is the database row.
func (*CatPayment) WithCat ¶
func (c *CatPayment) WithCat(f CatFilter) bool
WithCat changes this value so that it contains only the CatRecs that match f. If there are no such CatRecs, WithCat leaves this value unchanged and returns false.
func (*CatPayment) WithPayment ¶
func (c *CatPayment) WithPayment(id int64) bool
WithPayment changes this CatPayment so that the payment id matches id. If id is not the payment Id and it does not correspond to any payment ids in the CatRecs, then WithPayment returns false and leaves this value unchanged.
type CatPaymentBuilder ¶
type CatPaymentBuilder struct {
// contains filtered or unexported fields
}
CatPaymentBuilder builds the specifications for a CatPayment value.
func (*CatPaymentBuilder) AddCatRec ¶
func (c *CatPaymentBuilder) AddCatRec(cr CatRec) *CatPaymentBuilder
AddCatRec Adds a CatRec. It merges CatRecs having the same category.
func (*CatPaymentBuilder) Build ¶
func (c *CatPaymentBuilder) Build() CatPayment
Build returns a new CatPayment instance, and resets this builder.
func (*CatPaymentBuilder) ClearCatRecs ¶
func (c *CatPaymentBuilder) ClearCatRecs() *CatPaymentBuilder
Clears all the added CatRecs from this builder
func (*CatPaymentBuilder) Set ¶
func (c *CatPaymentBuilder) Set(cp *CatPayment) *CatPaymentBuilder
Set sets this CatPaymentBuilder to cp so that calling Build on it will return a value equivalent to cp.
func (*CatPaymentBuilder) SetPaymentId ¶
func (c *CatPaymentBuilder) SetPaymentId(x int64) *CatPaymentBuilder
SetPaymentId sets the payment id.
func (*CatPaymentBuilder) SetReconciled ¶
func (c *CatPaymentBuilder) SetReconciled(x bool) *CatPaymentBuilder
SetReconciled sets the reconciled flag.
type CatPopularity ¶
CatPopularity values are immutable by contract. The key is the category; the value is greater than or equal to zero and indicates popularity of the category.
type CatRec ¶
type CatRec struct { // Cat is the category. Cat Cat // Amount is amount in one cent increments. Positive means expense; negative // means income. Amount int64 // Reconciled is reconcile flag, only applicable for categories of // AccountCat type. Reconciled bool }
CatRec specifies a category, amount, and reconciled flag.
type CatTotals ¶
CatTotals represents category totals
func (CatTotals) Include ¶
func (c CatTotals) Include(catPayment CatPayment)
type Entry ¶
type Entry struct { // Unique Id Id int64 Date time.Time Name string Desc string CheckNo string CatPayment Status ReviewStatus Etag uint64 }
Entry represents a transaction entry.
type EntryBalance ¶
EntryBalance is an Entry with an ending balance
type EntryUpdater ¶
EntryUpdater updates an Entry in place and returns true if successful.
type Marshaller ¶
Marshaller marshalls a CatPayment to database columns. ptr represents database columns; cr, id, and r are the CatRec slice, payment ID, and reconcile flag respectively. Functions of this type must not modify cr in-place in any way.
type Permission ¶
type Permission int
Permission represents a user's permission to the database
const ( // Represents full control. This is always first and zero. AllPermission Permission = iota // Represents read-only permission. ReadPermission // Represents no permissions. This is always last. New permissions must // be inserted right before this one. NonePermission )
func ToPermission ¶
func ToPermission(x int) (Permission, bool)
ToPermission takes an int that ToInt returned and converts it back to a Permission. On success, returns the permission and true. If x is out of range, returns NonePermission and false.
func (Permission) String ¶
func (p Permission) String() string
func (Permission) ToInt ¶
func (p Permission) ToInt() int
ToInt maps a permission to an int in a way that is suitable for persistent storage. In particular, NonePermission ==> -1 because the actual value of NonePermission can change as it is always last.
type RecurringEntry ¶
type RecurringEntry struct { // The entry, the date field in this entry corresponds to the date of the // next entry that the Advance method generates. Entry // The period of time between each generated entries Period RecurringPeriod // The number of entries left to generate, a negative number means // unlimited. NumLeft int }
RecurringEntry represents a recurring entry.
func (*RecurringEntry) Advance ¶
func (r *RecurringEntry) Advance( currentDate time.Time, appendedNewEntries *[]*Entry) (advanced bool)
Advance advances this recurring entry through the current date adding the generated entries to appendedNewEntries. After this returns, the date of this instance is after currentDate unless the NumLeft field reached zero before this instance could be advanced passed currentDate. Returns true if Advance generated new entries or false otherwise.
func (*RecurringEntry) AdvanceOnce ¶
func (r *RecurringEntry) AdvanceOnce(newEntry *Entry) (advanced bool)
AdvanceOnce advances this recurring entry exactly once storing the generated entry at newEntry. newEntry may be nil. Returns true if this instance advanced or false if it did not. This instance won't advance if NumLeft is already 0.
type RecurringEntryUpdater ¶
type RecurringEntryUpdater func(entry *RecurringEntry) bool
RecurringEntryUpdater updates a RecurringEntry in place and returns true if successful.
type RecurringPeriod ¶
type RecurringPeriod struct { // The count of units. Count int // The time unit. Unit RecurringUnit // Specifies the desired day of the month. Relevant only when Unit is Months. // If <= 0 when Unit is Months, then RecurringPeriod works just like // time.AddDate(0, Count, 0) DayOfMonth int }
RecurringPeriod represents the time period between recurring entries.
type RecurringUnit ¶
type RecurringUnit int
RecurringUnit represents a unit of time for recurring entries. The zero value is equivalent to 'months'.
const ( Months RecurringUnit = iota Years Days Weeks // Placeholder for unit count. Does not represent an actual unit. // New units must be inserted right before this one. RecurringUnitCount )
func ToRecurringUnit ¶
func ToRecurringUnit(x int) (RecurringUnit, bool)
ToRecurringUnit takes an int that ToInt returned and converts it back to a RecurringUnit. On success, returns the RecurringUnit and true. If x is out of range, returns RecurringUnitCount and false.
func (RecurringUnit) String ¶
func (r RecurringUnit) String() string
func (RecurringUnit) ToInt ¶
func (r RecurringUnit) ToInt() int
ToInt maps a RecurringUnit to an int in a way that is suitable for persistent storage.
type Unmarshaller ¶
Unmarshaller builds components of CatPayment from database columns. ptr represents database columns; cr is where the new CatRec slice is to be stored; id is where type payment ID is to be stored; r is where the reconcile flag for the payment is to be stored.
Directories ¶
Path | Synopsis |
---|---|
Package aggregators contains aggregators of fin.Entry and fin.CatPayment values.
|
Package aggregators contains aggregators of fin.Entry and fin.CatPayment values. |
Package autoimport provides support for importing transactions from banks
|
Package autoimport provides support for importing transactions from banks |
csv
Package csv provides processing of csv files
|
Package csv provides processing of csv files |
qfx
Package qfx provides processing of QFX files
|
Package qfx provides processing of QFX files |
qfx/qfxdb
Package qfxdb provides the data structures for storing which fitIds have been processed.
|
Package qfxdb provides the data structures for storing which fitIds have been processed. |
qfx/qfxdb/fixture
Package fixture provides test suites to test implementations of the qfxdb.Store interface.
|
Package fixture provides test suites to test implementations of the qfxdb.Store interface. |
qfx/qfxdb/for_sqlite
Package for_sqlite provides a sqlite implementation for storing processed QFX file fitIds.
|
Package for_sqlite provides a sqlite implementation for storing processed QFX file fitIds. |
reconcile
Package reconcile provides functionality for reconciling entries imported from a bank with existing entries that have not yet been reconciled.
|
Package reconcile provides functionality for reconciling entries imported from a bank with existing entries that have not yet been reconciled. |
reconcile/match
package match matches two sorted arrays of int values together: matchTo and matchFrom.
|
package match matches two sorted arrays of int values together: matchTo and matchFrom. |
Package categories maintains metadata on spending categories.
|
Package categories maintains metadata on spending categories. |
categoriesdb
Package categoriesdb contains the persistence layer for the categories package.
|
Package categoriesdb contains the persistence layer for the categories package. |
categoriesdb/fixture
Package fixture provides test suites to test implementations of the interfaces in the categoriesdb package.
|
Package fixture provides test suites to test implementations of the interfaces in the categoriesdb package. |
categoriesdb/for_sqlite
Package for_sqlite stores types in categories package in a sqlite database.
|
Package for_sqlite stores types in categories package in a sqlite database. |
Package checks contains routines for processing check numbers.
|
Package checks contains routines for processing check numbers. |
Package consumers contains useful consumers
|
Package consumers contains useful consumers |
Package envelopes manages envelopes for tracking spending.
|
Package envelopes manages envelopes for tracking spending. |
Package filters contains useful search filters.
|
Package filters contains useful search filters. |
Package findb contains the persistence layer for the fin package.
|
Package findb contains the persistence layer for the fin package. |
fixture
Package fixture provides test suites to test implementations of the interfaces in the findb package.
|
Package fixture provides test suites to test implementations of the interfaces in the findb package. |
for_sqlite
Package for_sqlite stores types in fin package in a sqlite database.
|
Package for_sqlite stores types in fin package in a sqlite database. |
sqlite_setup
Package sqlite_setup sets up a sqlite database for personal finance.
|
Package sqlite_setup sets up a sqlite database for personal finance. |