Also export transfers
This commit is contained in:
parent
8ac3c22826
commit
78389e4beb
@ -23,8 +23,19 @@ DELETE FROM transactions
|
|||||||
WHERE id = $1;
|
WHERE id = $1;
|
||||||
|
|
||||||
-- name: GetAllTransactionsForBudget :many
|
-- name: GetAllTransactionsForBudget :many
|
||||||
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id, transactions.status,
|
SELECT transactions.id, transactions.date, transactions.memo,
|
||||||
accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
|
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
|
||||||
|
)::text as transfer_account
|
||||||
FROM transactions
|
FROM transactions
|
||||||
INNER JOIN accounts ON accounts.id = transactions.account_id
|
INNER JOIN accounts ON accounts.id = transactions.account_id
|
||||||
LEFT JOIN payees ON payees.id = transactions.payee_id
|
LEFT JOIN payees ON payees.id = transactions.payee_id
|
||||||
@ -46,7 +57,7 @@ SELECT transactions.id, transactions.date, transactions.memo,
|
|||||||
LEFT JOIN accounts otherAccounts ON otherAccounts.id = otherTransactions.account_id
|
LEFT JOIN accounts otherAccounts ON otherAccounts.id = otherTransactions.account_id
|
||||||
WHERE otherTransactions.group_id = transactions.group_id
|
WHERE otherTransactions.group_id = transactions.group_id
|
||||||
AND otherTransactions.id != transactions.id
|
AND otherTransactions.id != transactions.id
|
||||||
) as transfer_account
|
)::text as transfer_account
|
||||||
FROM transactions
|
FROM transactions
|
||||||
INNER JOIN accounts ON accounts.id = transactions.account_id
|
INNER JOIN accounts ON accounts.id = transactions.account_id
|
||||||
LEFT JOIN payees ON payees.id = transactions.payee_id
|
LEFT JOIN payees ON payees.id = transactions.payee_id
|
||||||
|
@ -81,8 +81,19 @@ func (q *Queries) DeleteTransaction(ctx context.Context, id uuid.UUID) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getAllTransactionsForBudget = `-- name: GetAllTransactionsForBudget :many
|
const getAllTransactionsForBudget = `-- name: GetAllTransactionsForBudget :many
|
||||||
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id, transactions.status,
|
SELECT transactions.id, transactions.date, transactions.memo,
|
||||||
accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
|
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
|
||||||
|
)::text as transfer_account
|
||||||
FROM transactions
|
FROM transactions
|
||||||
INNER JOIN accounts ON accounts.id = transactions.account_id
|
INNER JOIN accounts ON accounts.id = transactions.account_id
|
||||||
LEFT JOIN payees ON payees.id = transactions.payee_id
|
LEFT JOIN payees ON payees.id = transactions.payee_id
|
||||||
@ -103,6 +114,7 @@ type GetAllTransactionsForBudgetRow struct {
|
|||||||
Payee string
|
Payee string
|
||||||
CategoryGroup string
|
CategoryGroup string
|
||||||
Category string
|
Category string
|
||||||
|
TransferAccount string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetAllTransactionsForBudget(ctx context.Context, budgetID uuid.UUID) ([]GetAllTransactionsForBudgetRow, error) {
|
func (q *Queries) GetAllTransactionsForBudget(ctx context.Context, budgetID uuid.UUID) ([]GetAllTransactionsForBudgetRow, error) {
|
||||||
@ -125,6 +137,7 @@ func (q *Queries) GetAllTransactionsForBudget(ctx context.Context, budgetID uuid
|
|||||||
&i.Payee,
|
&i.Payee,
|
||||||
&i.CategoryGroup,
|
&i.CategoryGroup,
|
||||||
&i.Category,
|
&i.Category,
|
||||||
|
&i.TransferAccount,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -208,7 +221,7 @@ SELECT transactions.id, transactions.date, transactions.memo,
|
|||||||
LEFT JOIN accounts otherAccounts ON otherAccounts.id = otherTransactions.account_id
|
LEFT JOIN accounts otherAccounts ON otherAccounts.id = otherTransactions.account_id
|
||||||
WHERE otherTransactions.group_id = transactions.group_id
|
WHERE otherTransactions.group_id = transactions.group_id
|
||||||
AND otherTransactions.id != transactions.id
|
AND otherTransactions.id != transactions.id
|
||||||
) as transfer_account
|
)::text as transfer_account
|
||||||
FROM transactions
|
FROM transactions
|
||||||
INNER JOIN accounts ON accounts.id = transactions.account_id
|
INNER JOIN accounts ON accounts.id = transactions.account_id
|
||||||
LEFT JOIN payees ON payees.id = transactions.payee_id
|
LEFT JOIN payees ON payees.id = transactions.payee_id
|
||||||
@ -230,7 +243,7 @@ type GetTransactionsForAccountRow struct {
|
|||||||
Payee string
|
Payee string
|
||||||
CategoryGroup string
|
CategoryGroup string
|
||||||
Category string
|
Category string
|
||||||
TransferAccount interface{}
|
TransferAccount string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]GetTransactionsForAccountRow, error) {
|
func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]GetTransactionsForAccountRow, error) {
|
||||||
|
@ -115,7 +115,12 @@ func GetTransactionRow(transaction GetAllTransactionsForBudgetRow) []string {
|
|||||||
transaction.Account,
|
transaction.Account,
|
||||||
"", // Flag
|
"", // Flag
|
||||||
transaction.Date.Format("02.01.2006"),
|
transaction.Date.Format("02.01.2006"),
|
||||||
transaction.Payee,
|
}
|
||||||
|
|
||||||
|
if transaction.TransferAccount != "" {
|
||||||
|
row = append(row, "Transfer : "+transaction.TransferAccount)
|
||||||
|
} else {
|
||||||
|
row = append(row, transaction.Payee)
|
||||||
}
|
}
|
||||||
|
|
||||||
if transaction.CategoryGroup != "" && transaction.Category != "" {
|
if transaction.CategoryGroup != "" && transaction.Category != "" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user