model

package
v0.0.0-...-975d13b Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MPL-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccountTypeUndefined uint = iota
	AccountTypeCash
	AccountTypeDeposit
	AccountTypeCreditCard
	AccountTypeInvestment
	AccountTypeHealthCare
	AccountTypeLoan
	AccountTypeAsset
	AccountTypeCrypto
)
View Source
const (
	UndefinedType uint = iota
	Debit
	Credit
	DebitTransfer
	CreditTransfer
)
View Source
const (
	FilingTypeUndefined string = ""
	FilingTypeAnnual           = "10-K"
	FilingTypeQuarterly        = "10-Q"
)
View Source
const (
	BalanceSheet           string = "Balance Sheet"
	IncomeStatement               = "Income Statement"
	CashFlowStatement             = "CashFlow Statement"
	ConsolidatedStatements        = "Consolidated Financials"
)
View Source
const (
	Cash uint = iota
	Investments
	CurrentAssets
	Goodwill
	Intangibles
	Assets
	ShortTermDebt
	UnearnedRevenue
	CurrentLiabilities
	LongTermDebt
	Liabilities
	RetainedEarnings
	Equity
	BasicShares
	DilutedShares
	Revenue
	CostOfRevenue
	GrossProfit
	OperatingExpense
	OperatingIncome
	Interest
	NetIncome
	OperatingCashFlow
	CapEx
	DividendPaid
)
View Source
const (
	UndefinedSecurityBasisType uint = iota
	BasisFIFO
	BasisAverage
)
View Source
const (
	UndefinedSecurityType uint = iota
	Stock
	MutualFund
	Bond
	BondFund
	MoneyMarket
	Currency
	ForeignStock
	ForeignStockFund
	ForeignBond
	ForeignBondFund
	// skip 2
	OtherStock = iota + 2
	OtherFunds
	Commodities
	PreciousMetal
	RealEstate
	Other
	Options
	Cryptocurrency
)
View Source
const (
	FilingStatusUndefined uint = iota
	Single
	MarriedJointly
	MarriedSeparately
	HeadOfHousehold
)
View Source
const (
	TaxTypeUndefined uint = iota
	TaxTypeIncome
	TaxTypeIncomeCapitalGain
	TaxTypeDeductionsForAGI
	TaxTypeDeductionFromAGI
	TaxTypeItemizedDeduction
	TaxTypeTax
	TaxTypeCredits
	TaxTypePayments
)
View Source
const (
	UndefinedTradeType uint = iota
	Buy
	Sell
	// below are not Trades, but CashFlow Credits
	Dividend
	Distribution
	// below are effectively Buy types, but no CashFlow Debit
	ReinvestedDividend
	ReinvestedDistribution
	// below only for moving Shares between accounts, careful some 401k
	// exported data will incorrectly encode ReinvestedDividend as SharesIn
	SharesIn
	SharesOut
	// trade.Shares is split ratio (specified negative for reverse split)
	Split
)
View Source
const (
	DefaultCashFlowLimit = 200
)

Variables

View Source
var ConsolidatedFilingItemKeys = []string{

	"Cash",
	"Investments",
	"Current Assets",
	"Goodwill",
	"Intangibles",
	"Assets",
	"Short-Term Debt",
	"Unearned Revenue",
	"Current Liabilities",
	"Long-Term Debt",
	"Liabilities",
	"Retained Earnings",
	"Equity",

	"Basic Shares",
	"Diluted Shares",
	"Revenue",
	"Cost Of Revenue",
	"Gross Profit",
	"Operating Expense",
	"Operating Income",
	"Interest",
	"Net Income",

	"Operating CashFlow",
	"CapEx",
	"Dividend Paid",
}

order of below must match above for map keys to be correct

View Source
var ConsolidatedFilingItemMap = map[string]func(edgar.Filing) (float64, error){

	ConsolidatedFilingItemKeys[Cash]:               edgar.Filing.Cash,
	ConsolidatedFilingItemKeys[Investments]:        edgar.Filing.Securities,
	ConsolidatedFilingItemKeys[CurrentAssets]:      edgar.Filing.CurrentAssets,
	ConsolidatedFilingItemKeys[Goodwill]:           edgar.Filing.Goodwill,
	ConsolidatedFilingItemKeys[Intangibles]:        edgar.Filing.Intangibles,
	ConsolidatedFilingItemKeys[Assets]:             edgar.Filing.Assets,
	ConsolidatedFilingItemKeys[ShortTermDebt]:      edgar.Filing.ShortTermDebt,
	ConsolidatedFilingItemKeys[UnearnedRevenue]:    edgar.Filing.DeferredRevenue,
	ConsolidatedFilingItemKeys[CurrentLiabilities]: edgar.Filing.CurrentLiabilities,
	ConsolidatedFilingItemKeys[LongTermDebt]:       edgar.Filing.LongTermDebt,
	ConsolidatedFilingItemKeys[Liabilities]:        edgar.Filing.Liabilities,
	ConsolidatedFilingItemKeys[RetainedEarnings]:   edgar.Filing.RetainedEarnings,
	ConsolidatedFilingItemKeys[Equity]:             edgar.Filing.TotalEquity,

	ConsolidatedFilingItemKeys[BasicShares]:      edgar.Filing.ShareCount,
	ConsolidatedFilingItemKeys[DilutedShares]:    edgar.Filing.WAShares,
	ConsolidatedFilingItemKeys[Revenue]:          edgar.Filing.Revenue,
	ConsolidatedFilingItemKeys[CostOfRevenue]:    edgar.Filing.CostOfRevenue,
	ConsolidatedFilingItemKeys[GrossProfit]:      edgar.Filing.GrossMargin,
	ConsolidatedFilingItemKeys[OperatingExpense]: edgar.Filing.OperatingExpense,
	ConsolidatedFilingItemKeys[OperatingIncome]:  edgar.Filing.OperatingIncome,
	ConsolidatedFilingItemKeys[Interest]:         edgar.Filing.Interest,
	ConsolidatedFilingItemKeys[NetIncome]:        edgar.Filing.NetIncome,

	ConsolidatedFilingItemKeys[OperatingCashFlow]: edgar.Filing.OperatingCashFlow,
	ConsolidatedFilingItemKeys[CapEx]:             edgar.Filing.CapitalExpenditure,
	ConsolidatedFilingItemKeys[DividendPaid]:      edgar.Filing.Dividend,
}
View Source
var FilingStatusLabels = [5]string{"", "S", "MFJ", "MFS", "HH"}
View Source
var FlipAutomaticTaxEntries = [9]bool{false, false, false, false, false,
	true, false, true, true}

for ItemizedDeduction, Credits, Payments: entry.Amount will be set from Debit CashFlows, but we expected TaxEntry to have Positive Amount

View Source
var Months = [14]string{"",
	"Jan ",
	"Feb ",
	"Mar ",
	"Apr ",
	"May ",
	"Jun ",
	"Jul ",
	"Aug ",
	"Sep ",
	"Oct ",
	"Nov ",
	"Dec "}
View Source
var SecurityBasisName = [3]string{"", "FIFO", "Average"}
View Source
var SecurityTypeHasFilings = [21]bool{false, true}
View Source
var SecurityTypeIsPriceFetchable = [21]bool{false, true, true, false, true}
View Source
var TaxTypeNames = [9]string{"", "Income", "Income Capital Gain",
	"Deductions for AGI", "Deductions from AGI",
	"Itemized Deductions", "Tax", "Tax Credits",
	"Tax Payments"}
View Source
var TradeTypeCashFlowsQuery string = "trade_type_id <= 6"
View Source
var TradeTypeQueries = [9]string{"",
	"trade_type_id = 1 OR trade_type_id = 5 OR trade_type_id = 6",
	"trade_type_id = 2",
	"trade_type_id = 3 OR trade_type_id = 5",
	"trade_type_id = 4 OR trade_type_id = 6",
	"",
	"",
	"trade_type_id = 7",
	"trade_type_id = 8"}

SQL query string for all Buy, Sell types for Trades

View Source
var TradeTypeQueryDesc = [9]string{"",
	"",
	"Shares Sold",
	"Dividend",
	"Distribution",
	"",
	"",
	"",
	""}

Functions

func CashFlowTypeIsCredit

func CashFlowTypeIsCredit(CashFlowType uint) bool

func CashFlowTypeIsDebit

func CashFlowTypeIsDebit(CashFlowType uint) bool

func SecurityBasisTypeIsAverage

func SecurityBasisTypeIsAverage(basisTypeID uint) bool

func SecurityBasisTypeIsValid

func SecurityBasisTypeIsValid(SecurityBasisTypeID uint) bool

func SecurityTypeIsValid

func SecurityTypeIsValid(SecurityTypeID uint) bool

func TradeTypeIsBuy

func TradeTypeIsBuy(TradeTypeID uint) bool

func TradeTypeIsDistribution

func TradeTypeIsDistribution(TradeTypeID uint) bool

func TradeTypeIsDividend

func TradeTypeIsDividend(TradeTypeID uint) bool

func TradeTypeIsReinvest

func TradeTypeIsReinvest(TradeTypeID uint) bool

func TradeTypeIsSell

func TradeTypeIsSell(TradeTypeID uint) bool

func TradeTypeIsSharesIn

func TradeTypeIsSharesIn(TradeTypeID uint) bool

func TradeTypeIsSharesOut

func TradeTypeIsSharesOut(TradeTypeID uint) bool

func TradeTypeIsSplit

func TradeTypeIsSplit(TradeTypeID uint) bool

func TradeTypeIsValid

func TradeTypeIsValid(TradeTypeID uint) bool

func TradeTypeToCashFlowType

func TradeTypeToCashFlowType(TradeTypeID uint) uint

Types

type Account

type Account struct {
	gorm.Model
	UserID         uint            `gorm:"not null"`
	AccountTypeID  uint            `form:"account.account_type_id"`
	CurrencyTypeID uint            `form:"account.currency_type_id"`
	InstitutionID  uint            `form:"account.institution_id"`
	AverageBalance decimal.Decimal `gorm:"-:all"`
	Balance        decimal.Decimal
	CashBalance    decimal.Decimal
	Portfolio      SecurityValue `gorm:"-:all"`
	Routing        int           `form:"account.Routing"`
	OfxIndex       uint          `form:"account.OfxIndex"`
	ClientUID      string        `form:"account.ClientUID"`
	Name           string        `form:"account.Name"`
	Number         string        `form:"account.Number"`
	HasScheduled   bool
	Hidden         bool     `form:"account.Hidden"`
	Taxable        bool     `form:"account.Taxable"`
	Verified       bool     `gorm:"-:all"`
	Session        *Session `gorm:"-:all"`
	AccountType    AccountType
	CurrencyType   CurrencyType
	Institution    Institution
	User           User
	CashFlows      []CashFlow
	Securities     []Security
}

func GetAccountByName

func GetAccountByName(session *Session, name string) *Account

func List

func List(session *Session, all bool) []Account

func ListAccounts

func ListAccounts(session *Session, all bool) []Account

func (*Account) AddToBalance

func (a *Account) AddToBalance(fAmount float64)

func (*Account) ClearBooleans

func (a *Account) ClearBooleans()

for Bind() and setting from input/checkboxes */

func (*Account) Create

func (a *Account) Create(session *Session) error

func (Account) Currency

func (Account) Currency(value decimal.Decimal) string

func (*Account) Delete

func (a *Account) Delete(session *Session) error

func (*Account) Find

func (*Account) Find(ID uint) *Account

Find() for use with rails/ruby like REPL console (gomacro); controllers should not expose this as are no access controls

func (*Account) Get

func (a *Account) Get(session *Session, preload bool) *Account

Show, Edit, Delete, Update use Get a.UserID unset, need to load

func (*Account) GetRouting

func (a *Account) GetRouting() string

func (*Account) GetSecurity

func (a *Account) GetSecurity(session *Session, company *Company) (*Security, error)

This will find a Company that must match both Company.Name and Company.Symbol. If such Company doesn't exist, one is created.

func (*Account) GetSecurityBySymbol

func (a *Account) GetSecurityBySymbol(session *Session, symbol string) (*Security, error)

This version will find a Company that matches Company.Symbol regardless of Company.Name. If no such Company, one is created with Company.Name = "".

func (Account) HasAverageDailyBalance

func (a Account) HasAverageDailyBalance() bool

func (*Account) HaveAccessPermission

func (a *Account) HaveAccessPermission(session *Session) bool

func (*Account) Init

func (a *Account) Init() *Account

func (*Account) IsInvestment

func (a *Account) IsInvestment() bool

func (*Account) ListImports

func (account *Account) ListImports(session *Session, limit int) []Import

func (*Account) ListScheduled

func (account *Account) ListScheduled(session *Session, canRecordOnly bool) []CashFlow

func (*Account) ListSecurities

func (a *Account) ListSecurities(session *Session, openPositions bool) []Security

Account access already verified by caller

func (Account) PortfolioTotalReturn

func (a Account) PortfolioTotalReturn() decimal.Decimal

func (*Account) Print

func (a *Account) Print()

func (*Account) PrintAll

func (a *Account) PrintAll()

func (*Account) SetAverageDailyBalance

func (a *Account) SetAverageDailyBalance(session *Session)

func (*Account) SupportsDownload

func (a *Account) SupportsDownload(requireID bool) bool

func (*Account) TotalPortfolio

func (a *Account) TotalPortfolio(securities []Security)

func (*Account) Update

func (a *Account) Update() error

Account access already verified with Get

type AccountType

type AccountType struct {
	Model
	Name string `form:"account_type.Name"`
}

func (AccountType) GetAltText

func (a AccountType) GetAltText() string

func (AccountType) GetIconPath

func (a AccountType) GetIconPath() string

func (*AccountType) List

func (*AccountType) List(db *gorm.DB) []AccountType

type CashFlow

type CashFlow struct {
	gorm.Model
	CashFlowTypeID uint `form:"cash_flow_type_id" gorm:"-:all"`
	AccountID      uint `gorm:"not null"`

	TaxYear int `form:"tax_year"`
	Date    time.Time

	Amount decimal.Decimal `gorm:"not null"`

	Balance    decimal.Decimal `gorm:"-:all"`
	PayeeID    uint            `gorm:"not null"`    // also serves as Pair.AccountID (Transfers)
	CategoryID uint            `form:"category_id"` // also serves as Pair.ID (Transfers)

	PairID           uint `gorm:"-:all"`
	ImportID         uint
	RepeatIntervalID uint
	SplitFrom        uint
	Split            bool
	Transfer         bool
	CategoryName     string `gorm:"-:all"`
	Memo             string `form:"memo"`
	PayeeName        string `form:"payee_name" gorm:"-:all"`
	Transnum         string `form:"transnum"`
	Type             string `gorm:"default:NULL"`
	Account          Account
	Category         Category
	Payee            Payee
	RepeatInterval   RepeatInterval
	// contains filtered or unexported fields
}

func NewSplitCashFlow

func NewSplitCashFlow(session *Session, SplitFrom uint) (*CashFlow, int)

Used with CreateSplitCashFlow. Controller calls to get common CashFlow fields first, and before Bind (which can/will override other fields).

func (*CashFlow) CanSplit

func (c *CashFlow) CanSplit() bool

func (*CashFlow) Count

func (c *CashFlow) Count(account *Account) int64

func (*CashFlow) Create

func (c *CashFlow) Create(session *Session) error

func (CashFlow) Currency

func (CashFlow) Currency(value decimal.Decimal) string

func (*CashFlow) Delete

func (c *CashFlow) Delete(session *Session) error

func (*CashFlow) Find

func (*CashFlow) Find(ID uint) *CashFlow

Find() for use with rails/ruby like REPL console (gomacro); controllers should not expose this as are no access controls

func (*CashFlow) Get

func (c *CashFlow) Get(session *Session, edit bool) *CashFlow

Edit, Delete, Update, NewSplit use Get c.Account needs to be preloaded

func (CashFlow) GetTransnum

func (c CashFlow) GetTransnum() string

func (*CashFlow) HasSplits

func (c *CashFlow) HasSplits() bool

func (*CashFlow) HaveAccessPermission

func (c *CashFlow) HaveAccessPermission(session *Session) bool

c.Account must be preloaded

func (*CashFlow) IsCredit

func (c *CashFlow) IsCredit() bool

func (*CashFlow) IsDebit

func (c *CashFlow) IsDebit() bool

func (*CashFlow) IsScheduled

func (c *CashFlow) IsScheduled() bool

func (*CashFlow) IsScheduledEnterable

func (c *CashFlow) IsScheduledEnterable(allowFutureNoRepeat bool) bool

func (*CashFlow) IsScheduledParent

func (c *CashFlow) IsScheduledParent() bool

func (CashFlow) IsSellTrade

func (c CashFlow) IsSellTrade() bool

func (*CashFlow) IsTrade

func (c *CashFlow) IsTrade() bool

func (*CashFlow) List

func (*CashFlow) List(db *gorm.DB, account *Account) []CashFlow

func (*CashFlow) ListByDate

func (*CashFlow) ListByDate(db *gorm.DB, account *Account, date *time.Time) []CashFlow

func (*CashFlow) ListMerge

func (*CashFlow) ListMerge(db *gorm.DB, account *Account, other []CashFlow) []CashFlow

func (*CashFlow) ListMergeByDate

func (*CashFlow) ListMergeByDate(db *gorm.DB, account *Account, other []CashFlow,
	date *time.Time) []CashFlow

Account access already verified by caller

func (*CashFlow) ListSplit

func (c *CashFlow) ListSplit(db *gorm.DB) ([]CashFlow, string)

Account access already verified by caller

func (*CashFlow) ParentID

func (c *CashFlow) ParentID() uint

if SplitCashFlow, get parent CashFlow.ID

func (*CashFlow) Preload

func (c *CashFlow) Preload(db *gorm.DB)

func (*CashFlow) PreloadRepeat

func (c *CashFlow) PreloadRepeat(db *gorm.DB)

func (*CashFlow) Print

func (c *CashFlow) Print()

func (*CashFlow) PrintAll

func (c *CashFlow) PrintAll()

func (*CashFlow) Put

func (c *CashFlow) Put(session *Session, request map[string]interface{}) error

func (*CashFlow) RepeatParentID

func (c *CashFlow) RepeatParentID() uint

get ScheduledCashFlow.ID that is assocated with object

func (c CashFlow) ShowTradeLinks() bool

func (*CashFlow) SplitCount

func (c *CashFlow) SplitCount() uint

func (*CashFlow) Update

func (c *CashFlow) Update() error

CashFlow access already verified with Get

type CashFlowType

type CashFlowType struct {
	Model
	Name string `form:"cash_flow_type.Name"`
}

func (*CashFlowType) List

func (*CashFlowType) List(db *gorm.DB) []CashFlowType

type Category

type Category struct {
	Model
	UserID         uint
	CategoryTypeID uint   `form:"category.category_type_id"`
	Name           string `form:"category.Name"`
	OmitFromPie    bool
	CategoryType   CategoryType
	User           User
}

func CategoryGetByName

func CategoryGetByName(name string) *Category

func (*Category) IsInterest

func (c *Category) IsInterest() bool

func (*Category) IsInterestIncome

func (c *Category) IsInterestIncome() bool

func (*Category) IsMortgageInterest

func (c *Category) IsMortgageInterest() bool

func (*Category) IsValid

func (c *Category) IsValid() bool

func (*Category) List

func (*Category) List(db *gorm.DB) []Category

func (*Category) LoanPI

func (c *Category) LoanPI() bool

type CategoryType

type CategoryType struct {
	Model
	Name string `form:"category_type.Name"`
}

func (*CategoryType) List

func (*CategoryType) List(db *gorm.DB) []CategoryType

type Company

type Company struct {
	Model
	Name   string `form:"company.Name"`
	Symbol string `form:"company.Symbol"`

	// UserID only used from Security.Update
	UserID uint `gorm:"-:all"`
	// contains filtered or unexported fields
}

func (*Company) Create

func (c *Company) Create(isUpdate bool) *Company

Query if Company already exists and return. If non-existent, create one. But if this is an Update, first try to update the calling object Company first if only attached to one Security. XXX Possibly should disallow multiple Companies for same Symbol. Or in future have defined set of fixed Companies if ever consider to add support for financial statements.

func (*Company) Find

func (*Company) Find(ID uint) *Company

Find() for use with rails/ruby like REPL console (gomacro); controllers should not expose this as are no access controls

func (*Company) FindBySymbol

func (*Company) FindBySymbol(symbol string) *Company

func (*Company) Get

func (c *Company) Get() *Company

Query if Company already exists and return.

func (*Company) GetBySymbol

func (c *Company) GetBySymbol() []Company

Query if Companies already exists and return them. XXX Possibly should disallow multiple Companies for same Symbol.

func (*Company) GetFiling

func (c *Company) GetFiling(fType string, date time.Time) edgar.Filing

Note to caller:

convert floats to string with: strconv.FormatFloat(f.item(), 'f', -1, 64)

func (*Company) GetFilingDate

func (c *Company) GetFilingDate(f FilingData) string

func (*Company) GetFilingDates

func (c *Company) GetFilingDates(fType string) []time.Time

func (*Company) GetFilingItem

func (c *Company) GetFilingItem(f FilingData, item string) float64

func (*Company) GetFilingItemNames

func (c *Company) GetFilingItemNames(viewName string) []string

func (*Company) GetFilingItemString

func (c *Company) GetFilingItemString(f FilingData, item string) string

func (Company) GetName

func (c Company) GetName() string

func (*Company) HasFilings

func (c *Company) HasFilings() bool

func (Company) NumFilings

func (c Company) NumFilings(fType string) int

func (*Company) Print

func (c *Company) Print()

func (*Company) Update

func (c *Company) Update() bool

Return true if Company.ID was updated.

type CurrencyType

type CurrencyType struct {
	Model
	Name string `form:"currency_type.Name"`
}

func (*CurrencyType) List

func (*CurrencyType) List(db *gorm.DB) []CurrencyType

type FilingData

type FilingData edgar.Filing

type HttpFile

type HttpFile struct {
	FileName string
	FileData multipart.File
}

type Import

type Import struct {
	Model
	AccountID     uint   `gorm:"not null"`
	CashFlowCount uint   `gorm:"-:all"`
	TradeCount    uint   `gorm:"-:all"`
	Username      string `gorm:"-:all" form:"import.Username"`
	Password      string `gorm:"-:all" form:"import.Password"`
	CreatedOn     time.Time
	Account       Account
}

func (*Import) CountImported

func (im *Import) CountImported(session *Session)

func (*Import) FetchOFX

func (im *Import) FetchOFX(session *Session) error

func (*Import) Get

func (im *Import) Get(session *Session) *Import

func (*Import) HaveAccessPermission

func (i *Import) HaveAccessPermission(session *Session) bool

i.Account must be preloaded

func (*Import) ImportFile

func (im *Import) ImportFile(session *Session, importFile HttpFile) error

func (*Import) ImportFromOFX

func (im *Import) ImportFromOFX(session *Session, resp *ofxgo.Response, after *time.Time) error

func (*Import) ImportFromQFX

func (im *Import) ImportFromQFX(session *Session, importFile HttpFile) error

func (*Import) ImportFromQIF

func (im *Import) ImportFromQIF(session *Session, importFile HttpFile) error

func (*Import) ListImported

func (im *Import) ListImported(session *Session) []CashFlow

type Institution

type Institution struct {
	Model
	AppVer uint
	FiId   uint
	AppId  string
	FiOrg  string
	FiUrl  string
	Name   string
}

func (*Institution) List

func (*Institution) List() []Institution

type Model

type Model struct {
	ID uint `gorm:"primaryKey"`
}

type Payee

type Payee struct {
	Model
	UserID       uint   `gorm:"not null"`
	CategoryID   uint   `form:"payee.category_id"`
	Name         string `form:"payee.Name"`
	Address      string `form:"payee.Address"`
	SkipOnImport bool   `form:"payee.SkipOnImport"`
	Verified     bool   `gorm:"-:all"`
	User         User
	Category     Category
}

func (Payee) CategoryName

func (p Payee) CategoryName() string

func (*Payee) ClearBooleans

func (p *Payee) ClearBooleans()

for Bind() and setting from input/checkboxes */

func (*Payee) Create

func (p *Payee) Create(session *Session) error

func (*Payee) Delete

func (p *Payee) Delete(session *Session) error

func (*Payee) Find

func (*Payee) Find(ID uint) *Payee

Find() for use with rails/ruby like REPL console (gomacro); controllers should not expose this as are no access controls

func (*Payee) Get

func (p *Payee) Get(session *Session) *Payee

Edit, Delete, Update use Get

func (*Payee) GetDuplicates

func (p *Payee) GetDuplicates() []Payee

func (*Payee) HaveAccessPermission

func (p *Payee) HaveAccessPermission(session *Session) bool

func (*Payee) InUse

func (p *Payee) InUse() bool

func (*Payee) List

func (*Payee) List(session *Session, account *Account) []Payee

func (*Payee) ListCashFlows

func (p *Payee) ListCashFlows(account *Account) []CashFlow

func (*Payee) Merge

func (p *Payee) Merge(toMerge *Payee, account *Account) error

func (*Payee) Print

func (p *Payee) Print()

func (*Payee) SetCategory

func (p *Payee) SetCategory(account *Account, categoryID uint, toAll bool) error

func (*Payee) Update

func (p *Payee) Update() error

Payee access already verified with Get

func (Payee) UseByAccount

func (p Payee) UseByAccount(a *Account) uint

func (Payee) UseCount

func (p Payee) UseCount() uint

type RepeatInterval

type RepeatInterval struct {
	Model
	CashFlowID           uint
	Rate                 decimal.Decimal
	RepeatIntervalTypeID uint  `form:"repeat_interval_type_id"`
	RepeatsLeft          uint  `form:"repeats" gorm:"default:NULL"`
	RepeatsLeftPtr       *uint `gorm:"-:all"`
	StartDay             int
	RepeatIntervalType   RepeatIntervalType
}

func (*RepeatInterval) Create

func (r *RepeatInterval) Create(db *gorm.DB, c *CashFlow) error

func (*RepeatInterval) Find

func (*RepeatInterval) Find(ID uint) *RepeatInterval

Find() for use with rails/ruby like REPL console (gomacro); controllers should not expose this as are no access controls

func (RepeatInterval) GetRate

func (r RepeatInterval) GetRate() string

func (RepeatInterval) GetRepeatsLeft

func (r RepeatInterval) GetRepeatsLeft() string

func (RepeatInterval) HasRepeatsLeft

func (r RepeatInterval) HasRepeatsLeft() bool

func (*RepeatInterval) Preload

func (r *RepeatInterval) Preload(db *gorm.DB)

func (*RepeatInterval) Print

func (r *RepeatInterval) Print()

func (*RepeatInterval) SetRepeatsLeft

func (r *RepeatInterval) SetRepeatsLeft(repeats string)

func (*RepeatInterval) Update

func (r *RepeatInterval) Update() error

type RepeatIntervalType

type RepeatIntervalType struct {
	Model
	Name string `form:"repeat_interval_type.Name"`
	Days uint
}

func (*RepeatIntervalType) List

type Security

type Security struct {
	Model
	CompanyID           uint `gorm:"not null"`
	SecurityBasisTypeID uint `form:"security_basis_type_id"`

	SecurityTypeID  uint            `form:"security_type_id"`
	AccountID       uint            `gorm:"not null"`
	ImportName      string          `form:"security.ImportName"`
	BasisFromTrades decimal.Decimal `gorm:"-:all"`
	SecurityValue

	Account      Account
	Company      Company
	SecurityType SecurityType
	// contains filtered or unexported fields
}

func (Security) BasisPrice

func (s Security) BasisPrice() decimal.Decimal

func (*Security) ChangeAccount

func (s *Security) ChangeAccount(session *Session, name string) *Account

func (*Security) ChartsEnabled

func (s *Security) ChartsEnabled() bool

func (*Security) Create

func (s *Security) Create(session *Session) error

func (Security) Currency

func (Security) Currency(value decimal.Decimal) string

func (*Security) Delete

func (s *Security) Delete(session *Session) error

func (*Security) Find

func (*Security) Find(ID uint) *Security

Find() for use with rails/ruby like REPL console (gomacro); controllers should not expose this as are no access controls

func (*Security) Get

func (s *Security) Get(session *Session) *Security

controllers(Get, Edit, Delete, Update) use Get

func (*Security) GetChartData

func (s *Security) GetChartData(days int) string

func (*Security) GetChartDataByte

func (s *Security) GetChartDataByte(days int) []byte

func (*Security) GetChartOptions

func (s *Security) GetChartOptions() string

func (*Security) GetChartOptionsByte

func (s *Security) GetChartOptionsByte() []byte

func (*Security) HasFilings

func (s *Security) HasFilings() bool

func (*Security) HaveAccessPermission

func (s *Security) HaveAccessPermission(session *Session) bool

s.Account must be preloaded

func (*Security) LatestTradeBy

func (s *Security) LatestTradeBy(db *gorm.DB, tradeType uint) *Trade

Find only most recent Trade for Security

func (*Security) List

func (s *Security) List(session *Session, openPositions bool) []Security

get Securities for session.User

func (*Security) ListTrades

func (s *Security) ListTrades() []Trade

func (*Security) ListTradesBy

func (s *Security) ListTradesBy(tradeType uint, openOnly bool) []Trade

Find Trades for Security Security access already verified by caller

func (Security) Price

func (s Security) Price() decimal.Decimal

func (*Security) Print

func (s *Security) Print()

func (*Security) PrintAll

func (s *Security) PrintAll()

func (Security) TotalReturn

func (s Security) TotalReturn() decimal.Decimal

func (*Security) UnrealizedGain

func (s *Security) UnrealizedGain() decimal.Decimal

func (Security) UnrealizedReturn

func (s Security) UnrealizedReturn() decimal.Decimal

func (*Security) Update

func (s *Security) Update() error

Security access already verified with Get

type SecurityBasisType

type SecurityBasisType struct {
	Model
	Name string `form:"security_basis_type.Name"`
}

func (*SecurityBasisType) List

type SecurityChart

type SecurityChart struct {
	Labels   []string                `json:"labels"`
	Datasets []*SecurityChartDataSet `json:"datasets"`
}

type SecurityChartAxisOptions

type SecurityChartAxisOptions struct {
	Ticks SecurityChartTickOptions `json:"ticks"`
}

type SecurityChartDataSet

type SecurityChartDataSet struct {
	Label           string            `json:"label"`
	BackgroundColor string            `json:"backgroundColor"`
	BorderColor     string            `json:"borderColor"`
	Fill            string            `json:"fill"`
	Data            []decimal.Decimal `json:"data"`
}

type SecurityChartOptions

type SecurityChartOptions struct {
	Scales SecurityChartScaleOptions `json:"scales"`
}

type SecurityChartScaleOptions

type SecurityChartScaleOptions struct {
}

type SecurityChartTickOptions

type SecurityChartTickOptions struct {
}

type SecurityQuote

type SecurityQuote struct {
	Price decimal.Decimal
	// contains filtered or unexported fields
}

type SecurityQuoteCache

type SecurityQuoteCache struct {
	Quotes map[string]SecurityQuote
}

func GetQuoteCache

func GetQuoteCache() *SecurityQuoteCache

func (*SecurityQuoteCache) Get

func (sqc *SecurityQuoteCache) Get(symbol string) SecurityQuote

func (*SecurityQuoteCache) GetDateOf

func (sqc *SecurityQuoteCache) GetDateOf(symbol string) time.Time

type SecurityType

type SecurityType struct {
	Model
	Name string `form:"security_type.Name"`
}

func (*SecurityType) List

func (*SecurityType) List(db *gorm.DB) []SecurityType

type SecurityValue

type SecurityValue struct {
	Basis            decimal.Decimal
	Shares           decimal.Decimal
	Value            decimal.Decimal
	AccumulatedBasis decimal.Decimal
	RetainedEarnings decimal.Decimal
}

type Session

type Session struct {
	User    User
	Cache   UserCache
	DB      *gorm.DB
	DebugDB *gorm.DB
}

func (*Session) CloseSession

func (session *Session) CloseSession()

func (*Session) GetUser

func (session *Session) GetUser() *User

type TaxCategory

type TaxCategory struct {
	Model
	TaxItemID   uint `form:"tax_category.tax_item_id"`
	CategoryID  uint `form:"tax_category.category_id"`
	TradeTypeID uint `form:"tax_category.trade_type_id"`
	TaxItem     TaxItem
}

func (*TaxCategory) List

func (tc *TaxCategory) List(db *gorm.DB, taxType uint) []TaxCategory

type TaxConstant

type TaxConstant struct {
	Model
	TaxTableMax int32
	CapgainRate decimal.Decimal
	TaxL1Rate   decimal.Decimal
	TaxL2Rate   decimal.Decimal
	TaxL3Rate   decimal.Decimal
	TaxL4Rate   decimal.Decimal
	TaxL5Rate   decimal.Decimal
	TaxL6Rate   decimal.Decimal
	TaxL7Rate   decimal.Decimal
}

func (*TaxConstant) Get

func (c *TaxConstant) Get(db *gorm.DB) *TaxConstant

type TaxEntry

type TaxEntry struct {
	Model
	Year          time.Time
	DateYear      int  `form:"year" gorm:"-:all"`
	TaxItemID     uint `form:"tax_item_id"`
	TaxRegionID   uint `form:"tax_region_id"`
	TaxTypeID     uint `form:"tax_type_id"`
	TaxCategoryID uint `gorm:"-:all"`
	UserID        uint
	Amount        decimal.Decimal `gorm:"not null"`
	Memo          string          `form:"memo"`
	TaxItem       TaxItem
	TaxRegion     TaxRegion
	TaxType       TaxType
	User          User
}

db.Table("taxes")

func (*TaxEntry) Create

func (te *TaxEntry) Create(session *Session) error

func (TaxEntry) Currency

func (TaxEntry) Currency(value decimal.Decimal) string

func (*TaxEntry) Delete

func (te *TaxEntry) Delete(session *Session) error

func (*TaxEntry) Get

func (te *TaxEntry) Get(session *Session) *TaxEntry

func (*TaxEntry) HaveAccessPermission

func (te *TaxEntry) HaveAccessPermission(session *Session) bool

func (*TaxEntry) List

func (*TaxEntry) List(session *Session, year int) []TaxEntry

func (*TaxEntry) Update

func (te *TaxEntry) Update() error

TaxEntry access already verified with Get

type TaxFilingStatus

type TaxFilingStatus struct {
	Model
	Name  string
	Label string
}

func (*TaxFilingStatus) List

func (*TaxFilingStatus) List(db *gorm.DB) []TaxFilingStatus

type TaxItem

type TaxItem struct {
	Model
	TaxTypeID uint `form:"tax_item.tax_type_id"`
	//TaxCategoryID uint `form:"tax_item.tax_category_id"
	Name    string `form:"tax_item.Name"`
	Type    string
	TaxType TaxType
}

func (*TaxItem) Get

func (item *TaxItem) Get(db *gorm.DB) *TaxItem

func (*TaxItem) GetByName

func (item *TaxItem) GetByName(db *gorm.DB, name string) *TaxItem

func (*TaxItem) List

func (*TaxItem) List(db *gorm.DB) []TaxItem

func (*TaxItem) ListTaxCashFlows

func (it *TaxItem) ListTaxCashFlows(session *Session, year int) ([]CashFlow, decimal.Decimal)

func (*TaxItem) Sum

func (item *TaxItem) Sum(db *gorm.DB, r *TaxReturn, name string) decimal.Decimal

type TaxRegion

type TaxRegion struct {
	Model
	Name string `form:"tax_region.Name"`
}

func (*TaxRegion) List

func (*TaxRegion) List(db *gorm.DB) []TaxRegion

type TaxReturn

type TaxReturn struct {
	Model
	FilingStatus      uint `form:"tax_filing_status"`
	TaxRegionID       uint `form:"tax_region_id"`
	UserID            uint
	Year              int   `form:"year"`
	Exemptions        int32 `form:"exemptions"`
	Income            decimal.Decimal
	AgiIncome         decimal.Decimal
	TaxableIncome     decimal.Decimal
	ForAGI            decimal.Decimal
	FromAGI           decimal.Decimal
	StandardDeduction decimal.Decimal
	ItemizedDeduction decimal.Decimal
	Exemption         decimal.Decimal
	Credits           decimal.Decimal
	Payments          decimal.Decimal
	BaseTax           decimal.Decimal
	OtherTax          decimal.Decimal
	OwedTax           decimal.Decimal
	UnpaidTax         decimal.Decimal
	LongCapgainIncome decimal.Decimal
	Session           *Session `gorm:"-:all"`
	TaxRegion         TaxRegion
	User              User
}

db.Table("tax_users")

func (*TaxReturn) Create

func (t *TaxReturn) Create(session *Session) error

func (TaxReturn) Currency

func (TaxReturn) Currency(value decimal.Decimal) string

func (*TaxReturn) Delete

func (r *TaxReturn) Delete(session *Session) error

func (TaxReturn) FilingStatusLabel

func (t TaxReturn) FilingStatusLabel() string

cannot get GORM to read this table using Preload, this is faster to just compute and avoid DB lookup

func (*TaxReturn) Get

func (r *TaxReturn) Get(session *Session) *TaxReturn

func (*TaxReturn) HaveAccessPermission

func (r *TaxReturn) HaveAccessPermission(session *Session) bool

func (*TaxReturn) List

func (*TaxReturn) List(session *Session, year int) []TaxReturn

func (*TaxReturn) Recalculate

func (r *TaxReturn) Recalculate(session *Session) error

type TaxType

type TaxType struct {
	Model
	Name string `form:"tax_type.Name"`
}

func (*TaxType) Get

func (tt *TaxType) Get(db *gorm.DB) *TaxType

func (*TaxType) List

func (*TaxType) List(db *gorm.DB) []TaxType

func (*TaxType) ListTaxCashFlows

func (tt *TaxType) ListTaxCashFlows(session *Session, year int) ([]CashFlow, decimal.Decimal)

func (*TaxType) Sum

func (*TaxType) Sum(db *gorm.DB, r *TaxReturn, taxType uint) decimal.Decimal

Some TaxTypes may need Neg() of the CashFlows (handled in makeTaxEntry) Possibly we should add Round(2) to be cautious

type TaxYear

type TaxYear struct {
	Model
	Year                 int
	ExemptionAmount      int32
	SaltMaximum          int32
	StandardDeductionS   int32
	StandardDeductionMFJ int32
	StandardDeductionMFS int32
	StandardDeductionHH  int32
	TaxIncomeL1S         int32
	TaxIncomeL1MFJ       int32
	TaxIncomeL1MFS       int32
	TaxIncomeL1HH        int32
	TaxIncomeL2S         int32
	TaxIncomeL2MFJ       int32
	TaxIncomeL2MFS       int32
	TaxIncomeL2HH        int32
	TaxIncomeL3S         int32
	TaxIncomeL3MFJ       int32
	TaxIncomeL3MFS       int32
	TaxIncomeL3HH        int32
	TaxIncomeL4S         int32
	TaxIncomeL4MFJ       int32
	TaxIncomeL4MFS       int32
	TaxIncomeL4HH        int32
	TaxIncomeL5S         int32
	TaxIncomeL5MFJ       int32
	TaxIncomeL5MFS       int32
	TaxIncomeL5HH        int32
	TaxIncomeL6S         int32
	TaxIncomeL6MFJ       int32
	TaxIncomeL6MFS       int32
	TaxIncomeL6HH        int32
	TaxL1Rate            decimal.Decimal
	TaxL2Rate            decimal.Decimal
	TaxL3Rate            decimal.Decimal
	TaxL4Rate            decimal.Decimal
	TaxL5Rate            decimal.Decimal
	TaxL6Rate            decimal.Decimal
	TaxL7Rate            decimal.Decimal
}

func (*TaxYear) Get

func (y *TaxYear) Get(db *gorm.DB, year int) *TaxYear

type Trade

type Trade struct {
	gorm.Model
	TradeTypeID uint `form:"trade_type_id"`

	AccountID uint `gorm:"not null"`

	SecurityID uint `gorm:"not null"`
	ImportID   uint
	Symbol     string `form:"Symbol" gorm:"-:all"`
	Date       time.Time

	TaxYear int             `form:"tax_year"`
	Amount  decimal.Decimal `gorm:"not null"`

	Price     decimal.Decimal
	Shares    decimal.Decimal
	SharesSum decimal.Decimal `gorm:"-:all"`
	// AdjustedShares is remaining unsold shares, split adjusted
	AdjustedShares decimal.Decimal
	// Basis is accumulated (used) basis from Sells (starts at 0)
	// for Buys: remaining Basis is: Amount - Basis
	// (for AVGB, we still increment Buy specific (FIFO basis) in
	//  the buy.Basis; for actual used (average) basis, this is in
	//  the associated TradeGain.)
	// for Sells: the Gain (Loss) then is: Amount - Basis
	Basis   decimal.Decimal
	BasisPS decimal.Decimal `gorm:"-:all"`
	Gain    decimal.Decimal `gorm:"-:all"`

	GainPS decimal.Decimal `gorm:"-:all"`

	Closed     bool
	TradeType  TradeType
	Account    Account
	Security   Security
	TradeGains []TradeGain `gorm:"foreignKey:SellID"`
	// contains filtered or unexported fields
}

func (*Trade) Count

func (t *Trade) Count(account *Account) int64

func (*Trade) Create

func (t *Trade) Create(session *Session) error

func (Trade) Currency

func (Trade) Currency(value decimal.Decimal) string

func (*Trade) Delete

func (t *Trade) Delete(session *Session) error

func (*Trade) Find

func (*Trade) Find(ID uint) *Trade

Find() for use with rails/ruby like REPL console (gomacro); controllers should not expose this as are no access controls

func (*Trade) Get

func (t *Trade) Get(session *Session) *Trade

Edit, Delete, Update use Get

func (Trade) GetBasis

func (t Trade) GetBasis() string

func (*Trade) HaveAccessPermission

func (t *Trade) HaveAccessPermission(session *Session) bool

t.Account must be preloaded

func (*Trade) IsAverageCost

func (t *Trade) IsAverageCost() bool

func (*Trade) IsBuy

func (t *Trade) IsBuy() bool

func (*Trade) IsCredit

func (t *Trade) IsCredit() bool

func (*Trade) IsReinvest

func (t *Trade) IsReinvest() bool

func (*Trade) IsSell

func (t *Trade) IsSell() bool

func (*Trade) IsSharesIn

func (t *Trade) IsSharesIn() bool

func (*Trade) IsSharesOut

func (t *Trade) IsSharesOut() bool

func (*Trade) IsSplit

func (t *Trade) IsSplit() bool

func (*Trade) List

func (*Trade) List(db *gorm.DB, account *Account) []Trade

Account Trades, Account access already verified by caller For Security Trades, use security.ListTrades

func (*Trade) ListByType

func (t *Trade) ListByType(session *Session, tradeType uint, daysHeld uint) ([]Trade, [2]decimal.Decimal)

Filtered Account or User Trades for just single Year (t.Date.Year)

func (*Trade) ListByTypeTotal

func (t *Trade) ListByTypeTotal(session *Session, tradeType uint, daysHeld uint) [2]decimal.Decimal

func (*Trade) ListCashFlowByType

func (t *Trade) ListCashFlowByType(session *Session, tradeType uint) ([]CashFlow, decimal.Decimal)

Usage is interested in Trade Gains (Taxable), so here in returned CashFlows, we switch cf.Amount with the trade.Gain.

func (*Trade) ListCashFlows

func (t *Trade) ListCashFlows(db *gorm.DB, account *Account) []CashFlow

func (*Trade) ListGains

func (t *Trade) ListGains() ([]TradeGain, []decimal.Decimal)

func (*Trade) ListImportedCashFlows

func (t *Trade) ListImportedCashFlows(im *Import) []CashFlow

func (*Trade) Print

func (t *Trade) Print()

func (*Trade) PrintAll

func (t *Trade) PrintAll()

func (*Trade) Save

func (t *Trade) Save() error

func (*Trade) SharesRemaining

func (t *Trade) SharesRemaining() decimal.Decimal

func (*Trade) Update

func (t *Trade) Update() error

Trade access already verified with Get

func (*Trade) UpdateAdjustedShares

func (t *Trade) UpdateAdjustedShares(fShares float64)

func (Trade) ViewIsSell

func (t Trade) ViewIsSell() bool

func (*Trade) WasReinvest

func (t *Trade) WasReinvest() bool

type TradeGain

type TradeGain struct {
	Model
	SellID         uint
	BuyID          uint
	DaysHeld       int32
	Shares         decimal.Decimal
	AdjustedShares decimal.Decimal // deprecated
	Basis          decimal.Decimal
	BasisFIFO      decimal.Decimal
	BasisPS        decimal.Decimal `gorm:"-:all"`
	Amount         decimal.Decimal `gorm:"-:all"`
	Gain           decimal.Decimal `gorm:"-:all"`
	GainPS         decimal.Decimal `gorm:"-:all"`
	BuyDate        time.Time       `gorm:"-:all"`
}

func (*TradeGain) Delete

func (tg *TradeGain) Delete(session *Session) error

func (*TradeGain) Find

func (*TradeGain) Find(ID uint) *TradeGain

Find() for use with rails/ruby like REPL console (gomacro); controllers should not expose this as are no access controls

func (*TradeGain) FindForSale

func (*TradeGain) FindForSale(ID uint) []TradeGain

func (*TradeGain) Print

func (tg *TradeGain) Print()

func (*TradeGain) PrintAll

func (tg *TradeGain) PrintAll()

func (*TradeGain) Save

func (tg *TradeGain) Save() error

type TradeType

type TradeType struct {
	Model
	Name string `form:"trade_type.Name"`
}

func (*TradeType) List

func (*TradeType) List(db *gorm.DB) []TradeType

func (*TradeType) ListBuys

func (*TradeType) ListBuys(db *gorm.DB) []TradeType

type User

type User struct {
	gorm.Model
	Login          string `form:"user.Login"`
	Email          string `form:"user.Email"`
	PasswordDigest string
	CashflowLimit  int
	Session        *Session `gorm:"-:all"`
	UserSettings   UserSettings
	Accounts       []Account
	Payees         []Payee
}

func (*User) Authenticate

func (u *User) Authenticate(password string) bool

func (*User) Cache

func (u *User) Cache() *UserCache

func (*User) Create

func (u *User) Create(password [2]string) error

func (*User) Delete

func (u *User) Delete(session *Session) error

func (*User) Get

func (u *User) Get(session *Session) *User

Edit, Delete, Update use Get

func (*User) GetByLogin

func (u *User) GetByLogin(login string) *User

func (*User) HaveAccessPermission

func (u *User) HaveAccessPermission(session *Session) *User

func (*User) ListTaxCategory

func (u *User) ListTaxCategory(db *gorm.DB, year int, taxCat *TaxCategory) ([]CashFlow, decimal.Decimal)

func (*User) ListTaxCategoryTotal

func (u *User) ListTaxCategoryTotal(db *gorm.DB, year int, taxCat *TaxCategory) decimal.Decimal

func (*User) NewSession

func (u *User) NewSession() *Session

type UserCache

type UserCache struct {
	AccountBalances map[uint]decimal.Decimal
	AccountNames    map[uint]string
	CategoryNames   map[uint]string
	// contains filtered or unexported fields
}

type UserSettings

type UserSettings struct {
	Model
	UserID        uint
	CashFlowLimit int `gorm:"-:all"`
}

Jump to

Keyboard shortcuts

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