diff --git a/postgres/queries/transactions.sql b/postgres/queries/transactions.sql index 2bfbf15..65677cd 100644 --- a/postgres/queries/transactions.sql +++ b/postgres/queries/transactions.sql @@ -35,8 +35,19 @@ ORDER BY transactions.date DESC LIMIT 200; -- name: GetTransactionsForAccount :many -SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id, transactions.status, - accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category +SELECT transactions.id, transactions.date, transactions.memo, + transactions.amount, transactions.group_id, transactions.status, + accounts.name as account, + COALESCE(payees.name, '') as payee, + COALESCE(category_groups.name, '') as category_group, + COALESCE(categories.name, '') as category, + ( + SELECT CONCAT(otherAccounts.name) + FROM transactions otherTransactions + LEFT JOIN accounts otherAccounts ON otherAccounts.id = otherTransactions.account_id + WHERE otherTransactions.group_id = transactions.group_id + AND otherTransactions.id != transactions.id + ) as transfer_account FROM transactions INNER JOIN accounts ON accounts.id = transactions.account_id LEFT JOIN payees ON payees.id = transactions.payee_id diff --git a/postgres/transactions.sql.go b/postgres/transactions.sql.go index b1798ed..e6b54d7 100644 --- a/postgres/transactions.sql.go +++ b/postgres/transactions.sql.go @@ -136,8 +136,19 @@ func (q *Queries) GetTransactionsByMonthAndCategory(ctx context.Context, budgetI } const getTransactionsForAccount = `-- name: GetTransactionsForAccount :many -SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id, transactions.status, - accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category +SELECT transactions.id, transactions.date, transactions.memo, + transactions.amount, transactions.group_id, transactions.status, + accounts.name as account, + COALESCE(payees.name, '') as payee, + COALESCE(category_groups.name, '') as category_group, + COALESCE(categories.name, '') as category, + ( + SELECT CONCAT(otherAccounts.name) + FROM transactions otherTransactions + LEFT JOIN accounts otherAccounts ON otherAccounts.id = otherTransactions.account_id + WHERE otherTransactions.group_id = transactions.group_id + AND otherTransactions.id != transactions.id + ) as transfer_account FROM transactions INNER JOIN accounts ON accounts.id = transactions.account_id LEFT JOIN payees ON payees.id = transactions.payee_id @@ -149,16 +160,17 @@ LIMIT 200 ` type GetTransactionsForAccountRow struct { - ID uuid.UUID - Date time.Time - Memo string - Amount Numeric - GroupID uuid.NullUUID - Status TransactionStatus - Account string - Payee string - CategoryGroup string - Category string + ID uuid.UUID + Date time.Time + Memo string + Amount Numeric + GroupID uuid.NullUUID + Status TransactionStatus + Account string + Payee string + CategoryGroup string + Category string + TransferAccount interface{} } func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]GetTransactionsForAccountRow, error) { @@ -181,6 +193,7 @@ func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid. &i.Payee, &i.CategoryGroup, &i.Category, + &i.TransferAccount, ); err != nil { return nil, err } diff --git a/web/src/pages/Account.vue b/web/src/pages/Account.vue index de94472..ff74f8f 100644 --- a/web/src/pages/Account.vue +++ b/web/src/pages/Account.vue @@ -71,7 +71,7 @@ export default defineComponent({ :class="[index % 6 < 3 ? 'bg-gray-300' : 'bg-gray-100']">