mirror of
https://github.com/aclindsa/moneygo.git
synced 2025-07-02 20:28:38 -04:00
Split accounts and transactions into models
This commit is contained in:
@ -11,8 +11,8 @@ import (
|
||||
|
||||
type OFXImport struct {
|
||||
Securities []models.Security
|
||||
Accounts []Account
|
||||
Transactions []Transaction
|
||||
Accounts []models.Account
|
||||
Transactions []models.Transaction
|
||||
// Balances map[int64]string // map AccountIDs to ending balances
|
||||
}
|
||||
|
||||
@ -51,8 +51,8 @@ func (i *OFXImport) GetAddCurrency(isoname string) (*models.Security, error) {
|
||||
return &security, nil
|
||||
}
|
||||
|
||||
func (i *OFXImport) AddTransaction(tran *ofxgo.Transaction, account *Account) error {
|
||||
var t Transaction
|
||||
func (i *OFXImport) AddTransaction(tran *ofxgo.Transaction, account *models.Account) error {
|
||||
var t models.Transaction
|
||||
|
||||
t.Date = tran.DtPosted.UTC()
|
||||
|
||||
@ -70,7 +70,7 @@ func (i *OFXImport) AddTransaction(tran *ofxgo.Transaction, account *Account) er
|
||||
}
|
||||
}
|
||||
|
||||
var s1, s2 Split
|
||||
var s1, s2 models.Split
|
||||
if len(tran.ExtdName) > 0 {
|
||||
s1.Memo = tran.ExtdName.String()
|
||||
}
|
||||
@ -94,15 +94,15 @@ func (i *OFXImport) AddTransaction(tran *ofxgo.Transaction, account *Account) er
|
||||
s1.RemoteId = "ofx:" + tran.FiTID.String()
|
||||
// TODO CorrectFiTID/CorrectAction?
|
||||
|
||||
s1.ImportSplitType = ImportAccount
|
||||
s2.ImportSplitType = ExternalAccount
|
||||
s1.ImportSplitType = models.ImportAccount
|
||||
s2.ImportSplitType = models.ExternalAccount
|
||||
|
||||
security := i.Securities[account.SecurityId-1]
|
||||
s1.Amount = amt.FloatString(security.Precision)
|
||||
s2.Amount = amt.Neg(amt).FloatString(security.Precision)
|
||||
|
||||
s1.Status = Imported
|
||||
s2.Status = Imported
|
||||
s1.Status = models.Imported
|
||||
s2.Status = models.Imported
|
||||
|
||||
s1.AccountId = account.AccountId
|
||||
s2.AccountId = -1
|
||||
@ -122,12 +122,12 @@ func (i *OFXImport) importOFXBank(stmt *ofxgo.StatementResponse) error {
|
||||
return err
|
||||
}
|
||||
|
||||
account := Account{
|
||||
account := models.Account{
|
||||
AccountId: int64(len(i.Accounts) + 1),
|
||||
ExternalAccountId: stmt.BankAcctFrom.AcctID.String(),
|
||||
SecurityId: security.SecurityId,
|
||||
ParentAccountId: -1,
|
||||
Type: Bank,
|
||||
Type: models.Bank,
|
||||
}
|
||||
|
||||
if stmt.BankTranList != nil {
|
||||
@ -149,12 +149,12 @@ func (i *OFXImport) importOFXCC(stmt *ofxgo.CCStatementResponse) error {
|
||||
return err
|
||||
}
|
||||
|
||||
account := Account{
|
||||
account := models.Account{
|
||||
AccountId: int64(len(i.Accounts) + 1),
|
||||
ExternalAccountId: stmt.CCAcctFrom.AcctID.String(),
|
||||
SecurityId: security.SecurityId,
|
||||
ParentAccountId: -1,
|
||||
Type: Liability,
|
||||
Type: models.Liability,
|
||||
}
|
||||
i.Accounts = append(i.Accounts, account)
|
||||
|
||||
@ -208,14 +208,14 @@ func (i *OFXImport) importSecurities(seclist *ofxgo.SecurityList) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *OFXImport) GetInvTran(invtran *ofxgo.InvTran) Transaction {
|
||||
var t Transaction
|
||||
func (i *OFXImport) GetInvTran(invtran *ofxgo.InvTran) models.Transaction {
|
||||
var t models.Transaction
|
||||
t.Description = string(invtran.Memo)
|
||||
t.Date = invtran.DtTrade.UTC()
|
||||
return t
|
||||
}
|
||||
|
||||
func (i *OFXImport) GetInvBuyTran(buy *ofxgo.InvBuy, curdef *models.Security, account *Account) (*Transaction, error) {
|
||||
func (i *OFXImport) GetInvBuyTran(buy *ofxgo.InvBuy, curdef *models.Security, account *models.Account) (*models.Transaction, error) {
|
||||
t := i.GetInvTran(&buy.InvTran)
|
||||
|
||||
security, err := i.GetSecurityAlternateId(string(buy.SecID.UniqueID), models.Stock)
|
||||
@ -254,10 +254,10 @@ func (i *OFXImport) GetInvBuyTran(buy *ofxgo.InvBuy, curdef *models.Security, ac
|
||||
}
|
||||
|
||||
if num := commission.Num(); !num.IsInt64() || num.Int64() != 0 {
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: Commission,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.Commission,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + buy.InvTran.FiTID.String(),
|
||||
@ -266,10 +266,10 @@ func (i *OFXImport) GetInvBuyTran(buy *ofxgo.InvBuy, curdef *models.Security, ac
|
||||
})
|
||||
}
|
||||
if num := taxes.Num(); !num.IsInt64() || num.Int64() != 0 {
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: Taxes,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.Taxes,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + buy.InvTran.FiTID.String(),
|
||||
@ -278,10 +278,10 @@ func (i *OFXImport) GetInvBuyTran(buy *ofxgo.InvBuy, curdef *models.Security, ac
|
||||
})
|
||||
}
|
||||
if num := fees.Num(); !num.IsInt64() || num.Int64() != 0 {
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: Fees,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.Fees,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + buy.InvTran.FiTID.String(),
|
||||
@ -290,10 +290,10 @@ func (i *OFXImport) GetInvBuyTran(buy *ofxgo.InvBuy, curdef *models.Security, ac
|
||||
})
|
||||
}
|
||||
if num := load.Num(); !num.IsInt64() || num.Int64() != 0 {
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: Load,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.Load,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + buy.InvTran.FiTID.String(),
|
||||
@ -301,20 +301,20 @@ func (i *OFXImport) GetInvBuyTran(buy *ofxgo.InvBuy, curdef *models.Security, ac
|
||||
Amount: load.FloatString(curdef.Precision),
|
||||
})
|
||||
}
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: ImportAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.ImportAccount,
|
||||
AccountId: account.AccountId,
|
||||
SecurityId: -1,
|
||||
RemoteId: "ofx:" + buy.InvTran.FiTID.String(),
|
||||
Memo: memo,
|
||||
Amount: total.FloatString(curdef.Precision),
|
||||
})
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: TradingAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.TradingAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + buy.InvTran.FiTID.String(),
|
||||
@ -324,10 +324,10 @@ func (i *OFXImport) GetInvBuyTran(buy *ofxgo.InvBuy, curdef *models.Security, ac
|
||||
|
||||
var units big.Rat
|
||||
units.Abs(&buy.Units.Rat)
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: SubAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.SubAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: security.SecurityId,
|
||||
RemoteId: "ofx:" + buy.InvTran.FiTID.String(),
|
||||
@ -335,10 +335,10 @@ func (i *OFXImport) GetInvBuyTran(buy *ofxgo.InvBuy, curdef *models.Security, ac
|
||||
Amount: units.FloatString(security.Precision),
|
||||
})
|
||||
units.Neg(&units)
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: TradingAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.TradingAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: security.SecurityId,
|
||||
RemoteId: "ofx:" + buy.InvTran.FiTID.String(),
|
||||
@ -349,7 +349,7 @@ func (i *OFXImport) GetInvBuyTran(buy *ofxgo.InvBuy, curdef *models.Security, ac
|
||||
return &t, nil
|
||||
}
|
||||
|
||||
func (i *OFXImport) GetIncomeTran(income *ofxgo.Income, curdef *models.Security, account *Account) (*Transaction, error) {
|
||||
func (i *OFXImport) GetIncomeTran(income *ofxgo.Income, curdef *models.Security, account *models.Account) (*models.Transaction, error) {
|
||||
t := i.GetInvTran(&income.InvTran)
|
||||
|
||||
security, err := i.GetSecurityAlternateId(string(income.SecID.UniqueID), models.Stock)
|
||||
@ -370,10 +370,10 @@ func (i *OFXImport) GetIncomeTran(income *ofxgo.Income, curdef *models.Security,
|
||||
total.Mul(&total, &income.Currency.CurRate.Rat)
|
||||
}
|
||||
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: ImportAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.ImportAccount,
|
||||
AccountId: account.AccountId,
|
||||
SecurityId: -1,
|
||||
RemoteId: "ofx:" + income.InvTran.FiTID.String(),
|
||||
@ -381,10 +381,10 @@ func (i *OFXImport) GetIncomeTran(income *ofxgo.Income, curdef *models.Security,
|
||||
Amount: total.FloatString(curdef.Precision),
|
||||
})
|
||||
total.Neg(&total)
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: IncomeAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.IncomeAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + income.InvTran.FiTID.String(),
|
||||
@ -395,7 +395,7 @@ func (i *OFXImport) GetIncomeTran(income *ofxgo.Income, curdef *models.Security,
|
||||
return &t, nil
|
||||
}
|
||||
|
||||
func (i *OFXImport) GetInvExpenseTran(expense *ofxgo.InvExpense, curdef *models.Security, account *Account) (*Transaction, error) {
|
||||
func (i *OFXImport) GetInvExpenseTran(expense *ofxgo.InvExpense, curdef *models.Security, account *models.Account) (*models.Transaction, error) {
|
||||
t := i.GetInvTran(&expense.InvTran)
|
||||
|
||||
security, err := i.GetSecurityAlternateId(string(expense.SecID.UniqueID), models.Stock)
|
||||
@ -415,10 +415,10 @@ func (i *OFXImport) GetInvExpenseTran(expense *ofxgo.InvExpense, curdef *models.
|
||||
total.Mul(&total, &expense.Currency.CurRate.Rat)
|
||||
}
|
||||
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: ImportAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.ImportAccount,
|
||||
AccountId: account.AccountId,
|
||||
SecurityId: -1,
|
||||
RemoteId: "ofx:" + expense.InvTran.FiTID.String(),
|
||||
@ -426,10 +426,10 @@ func (i *OFXImport) GetInvExpenseTran(expense *ofxgo.InvExpense, curdef *models.
|
||||
Amount: total.FloatString(curdef.Precision),
|
||||
})
|
||||
total.Neg(&total)
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: ExpenseAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.ExpenseAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + expense.InvTran.FiTID.String(),
|
||||
@ -440,7 +440,7 @@ func (i *OFXImport) GetInvExpenseTran(expense *ofxgo.InvExpense, curdef *models.
|
||||
return &t, nil
|
||||
}
|
||||
|
||||
func (i *OFXImport) GetMarginInterestTran(marginint *ofxgo.MarginInterest, curdef *models.Security, account *Account) (*Transaction, error) {
|
||||
func (i *OFXImport) GetMarginInterestTran(marginint *ofxgo.MarginInterest, curdef *models.Security, account *models.Account) (*models.Transaction, error) {
|
||||
t := i.GetInvTran(&marginint.InvTran)
|
||||
|
||||
memo := string(marginint.InvTran.Memo)
|
||||
@ -454,10 +454,10 @@ func (i *OFXImport) GetMarginInterestTran(marginint *ofxgo.MarginInterest, curde
|
||||
total.Mul(&total, &marginint.Currency.CurRate.Rat)
|
||||
}
|
||||
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: ImportAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.ImportAccount,
|
||||
AccountId: account.AccountId,
|
||||
SecurityId: -1,
|
||||
RemoteId: "ofx:" + marginint.InvTran.FiTID.String(),
|
||||
@ -465,10 +465,10 @@ func (i *OFXImport) GetMarginInterestTran(marginint *ofxgo.MarginInterest, curde
|
||||
Amount: total.FloatString(curdef.Precision),
|
||||
})
|
||||
total.Neg(&total)
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: IncomeAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.IncomeAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + marginint.InvTran.FiTID.String(),
|
||||
@ -479,7 +479,7 @@ func (i *OFXImport) GetMarginInterestTran(marginint *ofxgo.MarginInterest, curde
|
||||
return &t, nil
|
||||
}
|
||||
|
||||
func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *models.Security, account *Account) (*Transaction, error) {
|
||||
func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *models.Security, account *models.Account) (*models.Transaction, error) {
|
||||
t := i.GetInvTran(&reinvest.InvTran)
|
||||
|
||||
security, err := i.GetSecurityAlternateId(string(reinvest.SecID.UniqueID), models.Stock)
|
||||
@ -518,10 +518,10 @@ func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *models.Sec
|
||||
}
|
||||
|
||||
if num := commission.Num(); !num.IsInt64() || num.Int64() != 0 {
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: Commission,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.Commission,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + reinvest.InvTran.FiTID.String(),
|
||||
@ -530,10 +530,10 @@ func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *models.Sec
|
||||
})
|
||||
}
|
||||
if num := taxes.Num(); !num.IsInt64() || num.Int64() != 0 {
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: Taxes,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.Taxes,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + reinvest.InvTran.FiTID.String(),
|
||||
@ -542,10 +542,10 @@ func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *models.Sec
|
||||
})
|
||||
}
|
||||
if num := fees.Num(); !num.IsInt64() || num.Int64() != 0 {
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: Fees,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.Fees,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + reinvest.InvTran.FiTID.String(),
|
||||
@ -554,10 +554,10 @@ func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *models.Sec
|
||||
})
|
||||
}
|
||||
if num := load.Num(); !num.IsInt64() || num.Int64() != 0 {
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: Load,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.Load,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + reinvest.InvTran.FiTID.String(),
|
||||
@ -565,10 +565,10 @@ func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *models.Sec
|
||||
Amount: load.FloatString(curdef.Precision),
|
||||
})
|
||||
}
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: ImportAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.ImportAccount,
|
||||
AccountId: account.AccountId,
|
||||
SecurityId: -1,
|
||||
RemoteId: "ofx:" + reinvest.InvTran.FiTID.String(),
|
||||
@ -576,10 +576,10 @@ func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *models.Sec
|
||||
Amount: total.FloatString(curdef.Precision),
|
||||
})
|
||||
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: IncomeAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.IncomeAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + reinvest.InvTran.FiTID.String(),
|
||||
@ -587,20 +587,20 @@ func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *models.Sec
|
||||
Amount: total.FloatString(curdef.Precision),
|
||||
})
|
||||
total.Neg(&total)
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: ImportAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.ImportAccount,
|
||||
AccountId: account.AccountId,
|
||||
SecurityId: -1,
|
||||
RemoteId: "ofx:" + reinvest.InvTran.FiTID.String(),
|
||||
Memo: memo,
|
||||
Amount: total.FloatString(curdef.Precision),
|
||||
})
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: TradingAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.TradingAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + reinvest.InvTran.FiTID.String(),
|
||||
@ -610,10 +610,10 @@ func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *models.Sec
|
||||
|
||||
var units big.Rat
|
||||
units.Abs(&reinvest.Units.Rat)
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: SubAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.SubAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: security.SecurityId,
|
||||
RemoteId: "ofx:" + reinvest.InvTran.FiTID.String(),
|
||||
@ -621,10 +621,10 @@ func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *models.Sec
|
||||
Amount: units.FloatString(security.Precision),
|
||||
})
|
||||
units.Neg(&units)
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: TradingAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.TradingAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: security.SecurityId,
|
||||
RemoteId: "ofx:" + reinvest.InvTran.FiTID.String(),
|
||||
@ -635,7 +635,7 @@ func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *models.Sec
|
||||
return &t, nil
|
||||
}
|
||||
|
||||
func (i *OFXImport) GetRetOfCapTran(retofcap *ofxgo.RetOfCap, curdef *models.Security, account *Account) (*Transaction, error) {
|
||||
func (i *OFXImport) GetRetOfCapTran(retofcap *ofxgo.RetOfCap, curdef *models.Security, account *models.Account) (*models.Transaction, error) {
|
||||
t := i.GetInvTran(&retofcap.InvTran)
|
||||
|
||||
security, err := i.GetSecurityAlternateId(string(retofcap.SecID.UniqueID), models.Stock)
|
||||
@ -655,10 +655,10 @@ func (i *OFXImport) GetRetOfCapTran(retofcap *ofxgo.RetOfCap, curdef *models.Sec
|
||||
total.Mul(&total, &retofcap.Currency.CurRate.Rat)
|
||||
}
|
||||
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: ImportAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.ImportAccount,
|
||||
AccountId: account.AccountId,
|
||||
SecurityId: -1,
|
||||
RemoteId: "ofx:" + retofcap.InvTran.FiTID.String(),
|
||||
@ -666,10 +666,10 @@ func (i *OFXImport) GetRetOfCapTran(retofcap *ofxgo.RetOfCap, curdef *models.Sec
|
||||
Amount: total.FloatString(curdef.Precision),
|
||||
})
|
||||
total.Neg(&total)
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: IncomeAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.IncomeAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + retofcap.InvTran.FiTID.String(),
|
||||
@ -680,7 +680,7 @@ func (i *OFXImport) GetRetOfCapTran(retofcap *ofxgo.RetOfCap, curdef *models.Sec
|
||||
return &t, nil
|
||||
}
|
||||
|
||||
func (i *OFXImport) GetInvSellTran(sell *ofxgo.InvSell, curdef *models.Security, account *Account) (*Transaction, error) {
|
||||
func (i *OFXImport) GetInvSellTran(sell *ofxgo.InvSell, curdef *models.Security, account *models.Account) (*models.Transaction, error) {
|
||||
t := i.GetInvTran(&sell.InvTran)
|
||||
|
||||
security, err := i.GetSecurityAlternateId(string(sell.SecID.UniqueID), models.Stock)
|
||||
@ -722,10 +722,10 @@ func (i *OFXImport) GetInvSellTran(sell *ofxgo.InvSell, curdef *models.Security,
|
||||
}
|
||||
|
||||
if num := commission.Num(); !num.IsInt64() || num.Int64() != 0 {
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: Commission,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.Commission,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + sell.InvTran.FiTID.String(),
|
||||
@ -734,10 +734,10 @@ func (i *OFXImport) GetInvSellTran(sell *ofxgo.InvSell, curdef *models.Security,
|
||||
})
|
||||
}
|
||||
if num := taxes.Num(); !num.IsInt64() || num.Int64() != 0 {
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: Taxes,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.Taxes,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + sell.InvTran.FiTID.String(),
|
||||
@ -746,10 +746,10 @@ func (i *OFXImport) GetInvSellTran(sell *ofxgo.InvSell, curdef *models.Security,
|
||||
})
|
||||
}
|
||||
if num := fees.Num(); !num.IsInt64() || num.Int64() != 0 {
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: Fees,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.Fees,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + sell.InvTran.FiTID.String(),
|
||||
@ -758,10 +758,10 @@ func (i *OFXImport) GetInvSellTran(sell *ofxgo.InvSell, curdef *models.Security,
|
||||
})
|
||||
}
|
||||
if num := load.Num(); !num.IsInt64() || num.Int64() != 0 {
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: Load,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.Load,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + sell.InvTran.FiTID.String(),
|
||||
@ -769,20 +769,20 @@ func (i *OFXImport) GetInvSellTran(sell *ofxgo.InvSell, curdef *models.Security,
|
||||
Amount: load.FloatString(curdef.Precision),
|
||||
})
|
||||
}
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: ImportAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.ImportAccount,
|
||||
AccountId: account.AccountId,
|
||||
SecurityId: -1,
|
||||
RemoteId: "ofx:" + sell.InvTran.FiTID.String(),
|
||||
Memo: memo,
|
||||
Amount: total.FloatString(curdef.Precision),
|
||||
})
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: TradingAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.TradingAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: curdef.SecurityId,
|
||||
RemoteId: "ofx:" + sell.InvTran.FiTID.String(),
|
||||
@ -792,10 +792,10 @@ func (i *OFXImport) GetInvSellTran(sell *ofxgo.InvSell, curdef *models.Security,
|
||||
|
||||
var units big.Rat
|
||||
units.Abs(&sell.Units.Rat)
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: TradingAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.TradingAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: security.SecurityId,
|
||||
RemoteId: "ofx:" + sell.InvTran.FiTID.String(),
|
||||
@ -803,10 +803,10 @@ func (i *OFXImport) GetInvSellTran(sell *ofxgo.InvSell, curdef *models.Security,
|
||||
Amount: units.FloatString(security.Precision),
|
||||
})
|
||||
units.Neg(&units)
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: SubAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.SubAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: security.SecurityId,
|
||||
RemoteId: "ofx:" + sell.InvTran.FiTID.String(),
|
||||
@ -817,7 +817,7 @@ func (i *OFXImport) GetInvSellTran(sell *ofxgo.InvSell, curdef *models.Security,
|
||||
return &t, nil
|
||||
}
|
||||
|
||||
func (i *OFXImport) GetTransferTran(transfer *ofxgo.Transfer, account *Account) (*Transaction, error) {
|
||||
func (i *OFXImport) GetTransferTran(transfer *ofxgo.Transfer, account *models.Account) (*models.Transaction, error) {
|
||||
t := i.GetInvTran(&transfer.InvTran)
|
||||
|
||||
security, err := i.GetSecurityAlternateId(string(transfer.SecID.UniqueID), models.Stock)
|
||||
@ -834,10 +834,10 @@ func (i *OFXImport) GetTransferTran(transfer *ofxgo.Transfer, account *Account)
|
||||
units.Neg(&transfer.Units.Rat)
|
||||
}
|
||||
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: SubAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.SubAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: security.SecurityId,
|
||||
RemoteId: "ofx:" + transfer.InvTran.FiTID.String(),
|
||||
@ -845,10 +845,10 @@ func (i *OFXImport) GetTransferTran(transfer *ofxgo.Transfer, account *Account)
|
||||
Amount: units.FloatString(security.Precision),
|
||||
})
|
||||
units.Neg(&units)
|
||||
t.Splits = append(t.Splits, &Split{
|
||||
t.Splits = append(t.Splits, &models.Split{
|
||||
// TODO ReversalFiTID?
|
||||
Status: Imported,
|
||||
ImportSplitType: ExternalAccount,
|
||||
Status: models.Imported,
|
||||
ImportSplitType: models.ExternalAccount,
|
||||
AccountId: -1,
|
||||
SecurityId: security.SecurityId,
|
||||
RemoteId: "ofx:" + transfer.InvTran.FiTID.String(),
|
||||
@ -859,12 +859,12 @@ func (i *OFXImport) GetTransferTran(transfer *ofxgo.Transfer, account *Account)
|
||||
return &t, nil
|
||||
}
|
||||
|
||||
func (i *OFXImport) AddInvTransaction(invtran *ofxgo.InvTransaction, account *Account, curdef *models.Security) error {
|
||||
func (i *OFXImport) AddInvTransaction(invtran *ofxgo.InvTransaction, account *models.Account, curdef *models.Security) error {
|
||||
if curdef.SecurityId < 1 || curdef.SecurityId > int64(len(i.Securities)) {
|
||||
return errors.New("Internal error: security index not found in OFX import\n")
|
||||
}
|
||||
|
||||
var t *Transaction
|
||||
var t *models.Transaction
|
||||
var err error
|
||||
if tran, ok := (*invtran).(ofxgo.BuyDebt); ok {
|
||||
t, err = i.GetInvBuyTran(&tran.InvBuy, curdef, account)
|
||||
@ -926,12 +926,12 @@ func (i *OFXImport) importOFXInv(stmt *ofxgo.InvStatementResponse) error {
|
||||
return err
|
||||
}
|
||||
|
||||
account := Account{
|
||||
account := models.Account{
|
||||
AccountId: int64(len(i.Accounts) + 1),
|
||||
ExternalAccountId: stmt.InvAcctFrom.AcctID.String(),
|
||||
SecurityId: security.SecurityId,
|
||||
ParentAccountId: -1,
|
||||
Type: Investment,
|
||||
Type: models.Investment,
|
||||
}
|
||||
i.Accounts = append(i.Accounts, account)
|
||||
|
||||
|
Reference in New Issue
Block a user