fin

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2020 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package fin declares basic types used in personal finance.

Package fin declares basic types used in personal finance.

Index

Constants

View Source
const (
	Reviewed         ReviewStatus = 1
	NotReviewed                   = 0
	ReviewInProgress              = -1
)

Variables

View Source
var (
	// Expense is the top level expense category.
	Expense = Cat{Type: ExpenseCat}
	// Income is the top level income category.
	Income = Cat{Type: IncomeCat}
)

Functions

func BuildCatPopularity

func BuildCatPopularity(
	maxEntriesToRead int,
	catPopularity *CatPopularity) goconsume.ConsumeFinalizer

BuildCatPopularity returns a consumer that consumes Entry values to build a CatPopularity instance. The returned consumer consumes at most maxEntriesToRead values with categories other than the top level expense category and skips values that have only the top level expense category. Caller must call Finalize on returned consumer for the built CatPopularity instance to be stored at catPopularity.

func FormatUSD

func FormatUSD(x int64) string

FormatUSD returns amount as dollars and cents. 347 -> "3.47"

func ParseUSD

func ParseUSD(s string) (v int64, e error)

ParseUSD is the inverse of FormatUSD. "3.47" -> 347

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.

func (*Account) String

func (a *Account) String() string

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

type AccountSet map[int64]bool

AccountSet represents a set of account ids.

func (AccountSet) Include

func (a AccountSet) Include(catPayment *CatPayment)

type Cat

type Cat struct {
	// Id is unique over same type, but not different types.
	Id   int64
	Type CatType
}

A Cat specifies a raw category.

func CatFromString

func CatFromString(s string) (cat Cat, err error)

CatFromString converts a string e.g 0:4 to a Cat instance

func NewCat

func NewCat(s string) Cat

NewCat creates a Cat value from a string e.g 0:4. If string cannot be parsed, returns the zero value.

func (Cat) IsTop

func (c Cat) IsTop() bool

IsTop returns true if this value represents a top-level category.

func (Cat) String

func (c Cat) String() string

func (Cat) ToString

func (c Cat) ToString() string

ToString converts this value to a String.

type CatFilter

type CatFilter func(c Cat) bool

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

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

type CatPopularity interface {

	// Popularity returns the popularity of the category as a value greater than
	// or equal to zero. The higher the return value the more popular the
	// category.
	Popularity(cat Cat) int
}

CatPopularity tells the popularity of each 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 CatSet

type CatSet map[Cat]bool

CatSet represents a set of Cat instances

func (CatSet) AddSet

func (c CatSet) AddSet(rhs CatSet) CatSet

AddSet adds the Cat instances in rhs to this instance. AddSet returns this instance for chaining.

type CatTotals

type CatTotals map[Cat]int64

CatTotals represents category totals

func (CatTotals) Include

func (c CatTotals) Include(catPayment *CatPayment)

type CatType

type CatType int

A CatType specifies expense, income, or account category

const (
	ExpenseCat CatType = iota
	IncomeCat
	AccountCat
)

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.

func (*Entry) String

func (e *Entry) String() string

type EntryBalance

type EntryBalance struct {
	Entry
	Balance int64
}

EntryBalance is an Entry with an ending balance

type EntryUpdater

type EntryUpdater func(entry *Entry) bool

EntryUpdater updates an Entry in place and returns true if successful.

type Marshaller

type Marshaller func(cr []CatRec, id int64, r bool, ptr interface{})

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.

func (RecurringPeriod) AddTo

func (r RecurringPeriod) AddTo(date time.Time) time.Time

AddTo returns date + (this instance). If the Count field of this instance is < 1, AddTo treats it as 1. AddTo panics if the Unit field of this instance is not an actual unit.

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 ReviewStatus

type ReviewStatus int

ReviewStatus is the review status of an Entry.

type Unmarshaller

type Unmarshaller func(ptr interface{}, cr *[]CatRec, id *int64, r *bool) error

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.

type User

type User struct {
	Id   int64
	Name string
	passwords.Password
	Permission Permission
	LastLogin  time.Time
}

User represents a user.

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 streams contains useful consumers of basic types
Package streams contains useful consumers of basic types
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL