Add transfers to list and skip
This commit is contained in:
parent
d71eb17092
commit
2f3e4bc748
@ -125,6 +125,8 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
|
|||||||
return fmt.Errorf("could not read from tsv: %w", err)
|
return fmt.Errorf("could not read from tsv: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var openTransfers []CreateTransactionParams
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
for _, record := range csvData[1:] {
|
for _, record := range csvData[1:] {
|
||||||
accountName := record[0]
|
accountName := record[0]
|
||||||
@ -141,12 +143,6 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
|
|||||||
return fmt.Errorf("could not parse date %s: %w", dateString, err)
|
return fmt.Errorf("could not parse date %s: %w", dateString, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
payeeName := record[3]
|
|
||||||
payeeID, err := ynab.GetPayee(payeeName)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("could not get payee %s: %w", payeeName, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
categoryGroup, categoryName := record[5], record[6] //also in 4 joined by :
|
categoryGroup, categoryName := record[5], record[6] //also in 4 joined by :
|
||||||
category, err := ynab.GetCategory(categoryGroup, categoryName)
|
category, err := ynab.GetCategory(categoryGroup, categoryName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -162,21 +158,39 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
|
|||||||
return fmt.Errorf("could not parse amount from (%s/%s): %w", inflow, outflow, err)
|
return fmt.Errorf("could not parse amount from (%s/%s): %w", inflow, outflow, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//status := record[10]
|
|
||||||
|
|
||||||
transaction := CreateTransactionParams{
|
transaction := CreateTransactionParams{
|
||||||
Date: date,
|
Date: date,
|
||||||
Memo: memo,
|
Memo: memo,
|
||||||
AccountID: account.ID,
|
AccountID: account.ID,
|
||||||
PayeeID: payeeID,
|
|
||||||
CategoryID: category,
|
CategoryID: category,
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
}
|
}
|
||||||
_, err = ynab.queries.CreateTransaction(ynab.Context, transaction)
|
|
||||||
if err != nil {
|
payeeName := record[3]
|
||||||
return fmt.Errorf("could not save transaction %v: %w", transaction, err)
|
if strings.HasPrefix(payeeName, "Transfer : ") {
|
||||||
|
// Transaction is a transfer to
|
||||||
|
transferToAccountName := payeeName[11:]
|
||||||
|
transferToAccount, err := ynab.GetAccount(transferToAccountName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Could not get transfer account %s: %w", transferToAccountName, err)
|
||||||
|
}
|
||||||
|
openTransfers = append(openTransfers, transaction)
|
||||||
|
fmt.Printf("Found transfer from %s to %s over %f\n", account.Name, transferToAccount.Name, amount.GetFloat64())
|
||||||
|
} else {
|
||||||
|
payeeID, err := ynab.GetPayee(payeeName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not get payee %s: %w", payeeName, err)
|
||||||
|
}
|
||||||
|
transaction.PayeeID = payeeID
|
||||||
|
|
||||||
|
_, err = ynab.queries.CreateTransaction(ynab.Context, transaction)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not save transaction %v: %w", transaction, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//status := record[10]
|
||||||
|
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user