Compare commits
	
		
			5 Commits
		
	
	
		
			6fe30231d8
			...
			2843d8a2f1
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 2843d8a2f1 | |||
| 843dcd2536 | |||
| a147830e12 | |||
| b0776023b4 | |||
| 0b95cdc1d9 | 
@@ -23,7 +23,7 @@ DELETE FROM transactions
 | 
			
		||||
WHERE id = $1;
 | 
			
		||||
 | 
			
		||||
-- name: GetTransactionsForBudget :many
 | 
			
		||||
SELECT  transactions.id, transactions.date, transactions.memo, transactions.amount,
 | 
			
		||||
SELECT  transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id,
 | 
			
		||||
        accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
 | 
			
		||||
FROM transactions 
 | 
			
		||||
INNER JOIN accounts ON accounts.id = transactions.account_id
 | 
			
		||||
@@ -35,7 +35,7 @@ ORDER BY transactions.date DESC
 | 
			
		||||
LIMIT 200;
 | 
			
		||||
 | 
			
		||||
-- name: GetTransactionsForAccount :many
 | 
			
		||||
SELECT  transactions.id, transactions.date, transactions.memo, transactions.amount,
 | 
			
		||||
SELECT  transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id,
 | 
			
		||||
        accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
 | 
			
		||||
FROM transactions 
 | 
			
		||||
INNER JOIN accounts ON accounts.id = transactions.account_id
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,5 @@
 | 
			
		||||
-- +goose Up
 | 
			
		||||
ALTER TABLE transactions ADD COLUMN
 | 
			
		||||
    group_id uuid NULL;
 | 
			
		||||
ALTER TABLE transactions ADD COLUMN group_id uuid NULL;
 | 
			
		||||
 | 
			
		||||
-- +goose Down
 | 
			
		||||
ALTER TABLE transactions DROP COLUMN group_id;
 | 
			
		||||
@@ -132,7 +132,7 @@ func (q *Queries) GetTransactionsByMonthAndCategory(ctx context.Context, budgetI
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const getTransactionsForAccount = `-- name: GetTransactionsForAccount :many
 | 
			
		||||
SELECT  transactions.id, transactions.date, transactions.memo, transactions.amount,
 | 
			
		||||
SELECT  transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id,
 | 
			
		||||
        accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
 | 
			
		||||
FROM transactions 
 | 
			
		||||
INNER JOIN accounts ON accounts.id = transactions.account_id
 | 
			
		||||
@@ -149,6 +149,7 @@ type GetTransactionsForAccountRow struct {
 | 
			
		||||
	Date          time.Time
 | 
			
		||||
	Memo          string
 | 
			
		||||
	Amount        Numeric
 | 
			
		||||
	GroupID       uuid.NullUUID
 | 
			
		||||
	Account       string
 | 
			
		||||
	Payee         string
 | 
			
		||||
	CategoryGroup string
 | 
			
		||||
@@ -169,6 +170,7 @@ func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.
 | 
			
		||||
			&i.Date,
 | 
			
		||||
			&i.Memo,
 | 
			
		||||
			&i.Amount,
 | 
			
		||||
			&i.GroupID,
 | 
			
		||||
			&i.Account,
 | 
			
		||||
			&i.Payee,
 | 
			
		||||
			&i.CategoryGroup,
 | 
			
		||||
@@ -188,7 +190,7 @@ func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const getTransactionsForBudget = `-- name: GetTransactionsForBudget :many
 | 
			
		||||
SELECT  transactions.id, transactions.date, transactions.memo, transactions.amount,
 | 
			
		||||
SELECT  transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id,
 | 
			
		||||
        accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
 | 
			
		||||
FROM transactions 
 | 
			
		||||
INNER JOIN accounts ON accounts.id = transactions.account_id
 | 
			
		||||
@@ -205,6 +207,7 @@ type GetTransactionsForBudgetRow struct {
 | 
			
		||||
	Date          time.Time
 | 
			
		||||
	Memo          string
 | 
			
		||||
	Amount        Numeric
 | 
			
		||||
	GroupID       uuid.NullUUID
 | 
			
		||||
	Account       string
 | 
			
		||||
	Payee         string
 | 
			
		||||
	CategoryGroup string
 | 
			
		||||
@@ -225,6 +228,7 @@ func (q *Queries) GetTransactionsForBudget(ctx context.Context, budgetID uuid.UU
 | 
			
		||||
			&i.Date,
 | 
			
		||||
			&i.Memo,
 | 
			
		||||
			&i.Amount,
 | 
			
		||||
			&i.GroupID,
 | 
			
		||||
			&i.Account,
 | 
			
		||||
			&i.Payee,
 | 
			
		||||
			&i.CategoryGroup,
 | 
			
		||||
 
 | 
			
		||||
@@ -212,11 +212,11 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
 | 
			
		||||
 | 
			
		||||
				_, err = ynab.queries.CreateTransaction(ynab.Context, transfer.CreateTransactionParams)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return fmt.Errorf("could not save transaction %v: %w", transaction, err)
 | 
			
		||||
					return fmt.Errorf("could not save transaction %v: %w", transfer.CreateTransactionParams, err)
 | 
			
		||||
				}
 | 
			
		||||
				_, err = ynab.queries.CreateTransaction(ynab.Context, openTransfer.CreateTransactionParams)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return fmt.Errorf("could not save transaction %v: %w", transaction, err)
 | 
			
		||||
					return fmt.Errorf("could not save transaction %v: %w", openTransfer.CreateTransactionParams, err)
 | 
			
		||||
				}
 | 
			
		||||
				break
 | 
			
		||||
			}
 | 
			
		||||
@@ -243,7 +243,12 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, openTransfer := range openTransfers {
 | 
			
		||||
		fmt.Printf("Found transfer from %s to %s on %s over %f\n", openTransfer.FromAccount, openTransfer.ToAccount, openTransfer.Date, openTransfer.Amount.GetFloat64())
 | 
			
		||||
		fmt.Printf("Saving unmatched transfer from %s to %s on %s over %f as regular transaction\n", openTransfer.FromAccount, openTransfer.ToAccount, openTransfer.Date, openTransfer.Amount.GetFloat64())
 | 
			
		||||
		_, err = ynab.queries.CreateTransaction(ynab.Context, openTransfer.CreateTransactionParams)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return fmt.Errorf("could not save transaction %v: %w", openTransfer.CreateTransactionParams, err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
	fmt.Printf("Imported %d transactions\n", count)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -26,6 +26,9 @@
 | 
			
		||||
                {{.CategoryGroup}} : {{.Category}}
 | 
			
		||||
            {{end}}
 | 
			
		||||
        </td>
 | 
			
		||||
        <td>
 | 
			
		||||
            {{if .GroupID.Valid}}☀{{end}}
 | 
			
		||||
        </td>
 | 
			
		||||
        <td>
 | 
			
		||||
            <a href="/budget/{{$.Budget.ID}}/transaction/{{.ID}}">{{.Memo}}</a>
 | 
			
		||||
        </td>
 | 
			
		||||
 
 | 
			
		||||
@@ -7,8 +7,8 @@
 | 
			
		||||
{{define "main"}}
 | 
			
		||||
    <h1>Danger Zone</h1>
 | 
			
		||||
    <div class="budget-item">
 | 
			
		||||
        <a href="/budget/{{.Budget.ID}}/settings/clear">Clear database</a>
 | 
			
		||||
        <p>This removes all data and starts from scratch. Not undoable!</p>
 | 
			
		||||
        <a href="/budget/{{.Budget.ID}}/settings/clear">Clear budget</a>
 | 
			
		||||
        <p>This removes transactions and assignments to start from scratch. Accounts and categories are kept. Not undoable!</p>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="budget-item">
 | 
			
		||||
        <a href="/budget/{{.Budget.ID}}/settings/clean-negative">Fix all historic negative category-balances</a>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user