Split transactions and assignments export into two endpoints
This commit is contained in:
@ -67,31 +67,33 @@ func (ynab *YNABExport) ExportTransactions(context context.Context, w io.Writer)
|
||||
csv := csv.NewWriter(w)
|
||||
csv.Comma = '\t'
|
||||
|
||||
transactions, err := ynab.queries.GetTransactionsForBudget(context, ynab.budgetID)
|
||||
transactions, err := ynab.queries.GetAllTransactionsForBudget(context, ynab.budgetID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("load transactions: %w", err)
|
||||
}
|
||||
|
||||
header := []string{
|
||||
"Account",
|
||||
"Flag",
|
||||
"Date",
|
||||
"Payee",
|
||||
"Category Group/Category",
|
||||
"Category Group",
|
||||
"Category",
|
||||
"Memo",
|
||||
"Outflow",
|
||||
"Inflow",
|
||||
"Cleared",
|
||||
}
|
||||
|
||||
err = csv.Write(header)
|
||||
if err != nil {
|
||||
return fmt.Errorf("write transaction: %w", err)
|
||||
}
|
||||
|
||||
count := 0
|
||||
for _, transaction := range transactions {
|
||||
row := []string{
|
||||
transaction.Account,
|
||||
"", // Flag
|
||||
transaction.Date.Format("02.01.2006"),
|
||||
transaction.Payee,
|
||||
transaction.CategoryGroup + " : " + transaction.Category,
|
||||
transaction.CategoryGroup,
|
||||
transaction.Category,
|
||||
transaction.Memo,
|
||||
}
|
||||
|
||||
if transaction.Amount.IsPositive() {
|
||||
row = append(row, transaction.Amount.String()+"€", "0,00€")
|
||||
} else {
|
||||
row = append(row, "0,00€", transaction.Amount.String()[1:]+"€")
|
||||
}
|
||||
|
||||
row = append(row, string(transaction.Status))
|
||||
row := GetTransactionRow(transaction)
|
||||
|
||||
err := csv.Write(row)
|
||||
if err != nil {
|
||||
@ -106,3 +108,31 @@ func (ynab *YNABExport) ExportTransactions(context context.Context, w io.Writer)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetTransactionRow(transaction GetAllTransactionsForBudgetRow) []string {
|
||||
row := []string{
|
||||
transaction.Account,
|
||||
"", // Flag
|
||||
transaction.Date.Format("02.01.2006"),
|
||||
transaction.Payee,
|
||||
}
|
||||
|
||||
if transaction.CategoryGroup != "" && transaction.Category != "" {
|
||||
row = append(row,
|
||||
transaction.CategoryGroup+" : "+transaction.Category,
|
||||
transaction.CategoryGroup,
|
||||
transaction.Category)
|
||||
} else {
|
||||
row = append(row, "", "", "")
|
||||
}
|
||||
|
||||
row = append(row, transaction.Memo)
|
||||
|
||||
if transaction.Amount.IsPositive() {
|
||||
row = append(row, transaction.Amount.String()+"€", "0,00€")
|
||||
} else {
|
||||
row = append(row, "0,00€", transaction.Amount.String()[1:]+"€")
|
||||
}
|
||||
|
||||
return append(row, string(transaction.Status))
|
||||
}
|
||||
|
Reference in New Issue
Block a user