Compare commits
	
		
			16 Commits
		
	
	
		
			38e21786a7
			...
			fc50313907
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| fc50313907 | |||
| 4824e75049 | |||
| 00a391d08c | |||
| 744ff5207c | |||
| 1094ce670e | |||
| 1ad533a306 | |||
| 970cdf896c | |||
| f72e7b8cec | |||
| d87716977a | |||
| 0ca52d4fe4 | |||
| e0285922bd | |||
| 4eaa1ccbd1 | |||
| ccea4dfaa4 | |||
| c6cb36c260 | |||
| 646df25d5b | |||
| 0e83e31fda | 
@@ -15,7 +15,7 @@ const createAccount = `-- name: CreateAccount :one
 | 
				
			|||||||
INSERT INTO accounts
 | 
					INSERT INTO accounts
 | 
				
			||||||
(name, budget_id)
 | 
					(name, budget_id)
 | 
				
			||||||
VALUES ($1, $2)
 | 
					VALUES ($1, $2)
 | 
				
			||||||
RETURNING id, budget_id, name, on_budget, is_open
 | 
					RETURNING id, budget_id, name, on_budget
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type CreateAccountParams struct {
 | 
					type CreateAccountParams struct {
 | 
				
			||||||
@@ -31,13 +31,12 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (A
 | 
				
			|||||||
		&i.BudgetID,
 | 
							&i.BudgetID,
 | 
				
			||||||
		&i.Name,
 | 
							&i.Name,
 | 
				
			||||||
		&i.OnBudget,
 | 
							&i.OnBudget,
 | 
				
			||||||
		&i.IsOpen,
 | 
					 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	return i, err
 | 
						return i, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getAccount = `-- name: GetAccount :one
 | 
					const getAccount = `-- name: GetAccount :one
 | 
				
			||||||
SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget, accounts.is_open FROM accounts
 | 
					SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget FROM accounts
 | 
				
			||||||
WHERE accounts.id = $1
 | 
					WHERE accounts.id = $1
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -49,15 +48,13 @@ func (q *Queries) GetAccount(ctx context.Context, id uuid.UUID) (Account, error)
 | 
				
			|||||||
		&i.BudgetID,
 | 
							&i.BudgetID,
 | 
				
			||||||
		&i.Name,
 | 
							&i.Name,
 | 
				
			||||||
		&i.OnBudget,
 | 
							&i.OnBudget,
 | 
				
			||||||
		&i.IsOpen,
 | 
					 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	return i, err
 | 
						return i, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getAccounts = `-- name: GetAccounts :many
 | 
					const getAccounts = `-- name: GetAccounts :many
 | 
				
			||||||
SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget, accounts.is_open FROM accounts
 | 
					SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget FROM accounts
 | 
				
			||||||
WHERE accounts.budget_id = $1
 | 
					WHERE accounts.budget_id = $1
 | 
				
			||||||
AND accounts.is_open = TRUE
 | 
					 | 
				
			||||||
ORDER BY accounts.name
 | 
					ORDER BY accounts.name
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -75,7 +72,6 @@ func (q *Queries) GetAccounts(ctx context.Context, budgetID uuid.UUID) ([]Accoun
 | 
				
			|||||||
			&i.BudgetID,
 | 
								&i.BudgetID,
 | 
				
			||||||
			&i.Name,
 | 
								&i.Name,
 | 
				
			||||||
			&i.OnBudget,
 | 
								&i.OnBudget,
 | 
				
			||||||
			&i.IsOpen,
 | 
					 | 
				
			||||||
		); err != nil {
 | 
							); err != nil {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -91,14 +87,13 @@ func (q *Queries) GetAccounts(ctx context.Context, budgetID uuid.UUID) ([]Accoun
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getAccountsWithBalance = `-- name: GetAccountsWithBalance :many
 | 
					const getAccountsWithBalance = `-- name: GetAccountsWithBalance :many
 | 
				
			||||||
SELECT accounts.id, accounts.name, accounts.on_budget, accounts.is_open,
 | 
					SELECT accounts.id, accounts.name, accounts.on_budget, 
 | 
				
			||||||
        (SELECT MAX(transactions.date) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.status = 'Reconciled')::date as last_reconciled,
 | 
					        (SELECT MAX(transactions.date) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.status = 'Reconciled')::date as last_reconciled,
 | 
				
			||||||
        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW())::decimal(12,2) as working_balance,
 | 
					        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW())::decimal(12,2) as working_balance,
 | 
				
			||||||
        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status IN ('Cleared', 'Reconciled'))::decimal(12,2) as cleared_balance,
 | 
					        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status IN ('Cleared', 'Reconciled'))::decimal(12,2) as cleared_balance,
 | 
				
			||||||
        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status = 'Reconciled')::decimal(12,2) as reconciled_balance
 | 
					        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status = 'Reconciled')::decimal(12,2) as reconciled_balance
 | 
				
			||||||
FROM accounts
 | 
					FROM accounts
 | 
				
			||||||
WHERE accounts.budget_id = $1
 | 
					WHERE accounts.budget_id = $1
 | 
				
			||||||
AND accounts.is_open = TRUE
 | 
					 | 
				
			||||||
ORDER BY accounts.name
 | 
					ORDER BY accounts.name
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -106,7 +101,6 @@ type GetAccountsWithBalanceRow struct {
 | 
				
			|||||||
	ID                uuid.UUID
 | 
						ID                uuid.UUID
 | 
				
			||||||
	Name              string
 | 
						Name              string
 | 
				
			||||||
	OnBudget          bool
 | 
						OnBudget          bool
 | 
				
			||||||
	IsOpen            bool
 | 
					 | 
				
			||||||
	LastReconciled    time.Time
 | 
						LastReconciled    time.Time
 | 
				
			||||||
	WorkingBalance    numeric.Numeric
 | 
						WorkingBalance    numeric.Numeric
 | 
				
			||||||
	ClearedBalance    numeric.Numeric
 | 
						ClearedBalance    numeric.Numeric
 | 
				
			||||||
@@ -126,7 +120,6 @@ func (q *Queries) GetAccountsWithBalance(ctx context.Context, budgetID uuid.UUID
 | 
				
			|||||||
			&i.ID,
 | 
								&i.ID,
 | 
				
			||||||
			&i.Name,
 | 
								&i.Name,
 | 
				
			||||||
			&i.OnBudget,
 | 
								&i.OnBudget,
 | 
				
			||||||
			&i.IsOpen,
 | 
					 | 
				
			||||||
			&i.LastReconciled,
 | 
								&i.LastReconciled,
 | 
				
			||||||
			&i.WorkingBalance,
 | 
								&i.WorkingBalance,
 | 
				
			||||||
			&i.ClearedBalance,
 | 
								&i.ClearedBalance,
 | 
				
			||||||
@@ -148,7 +141,6 @@ func (q *Queries) GetAccountsWithBalance(ctx context.Context, budgetID uuid.UUID
 | 
				
			|||||||
const searchAccounts = `-- name: SearchAccounts :many
 | 
					const searchAccounts = `-- name: SearchAccounts :many
 | 
				
			||||||
SELECT accounts.id, accounts.budget_id, accounts.name, 'account' as type FROM accounts
 | 
					SELECT accounts.id, accounts.budget_id, accounts.name, 'account' as type FROM accounts
 | 
				
			||||||
WHERE accounts.budget_id = $1
 | 
					WHERE accounts.budget_id = $1
 | 
				
			||||||
AND accounts.is_open = TRUE
 | 
					 | 
				
			||||||
AND accounts.name LIKE $2
 | 
					AND accounts.name LIKE $2
 | 
				
			||||||
ORDER BY accounts.name
 | 
					ORDER BY accounts.name
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
@@ -196,33 +188,25 @@ func (q *Queries) SearchAccounts(ctx context.Context, arg SearchAccountsParams)
 | 
				
			|||||||
const updateAccount = `-- name: UpdateAccount :one
 | 
					const updateAccount = `-- name: UpdateAccount :one
 | 
				
			||||||
UPDATE accounts
 | 
					UPDATE accounts
 | 
				
			||||||
SET name = $1,
 | 
					SET name = $1,
 | 
				
			||||||
    on_budget = $2,
 | 
					    on_budget = $2
 | 
				
			||||||
    is_open = $3
 | 
					WHERE accounts.id = $3
 | 
				
			||||||
WHERE accounts.id = $4
 | 
					RETURNING id, budget_id, name, on_budget
 | 
				
			||||||
RETURNING id, budget_id, name, on_budget, is_open
 | 
					 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type UpdateAccountParams struct {
 | 
					type UpdateAccountParams struct {
 | 
				
			||||||
	Name     string
 | 
						Name     string
 | 
				
			||||||
	OnBudget bool
 | 
						OnBudget bool
 | 
				
			||||||
	IsOpen   bool
 | 
					 | 
				
			||||||
	ID       uuid.UUID
 | 
						ID       uuid.UUID
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (q *Queries) UpdateAccount(ctx context.Context, arg UpdateAccountParams) (Account, error) {
 | 
					func (q *Queries) UpdateAccount(ctx context.Context, arg UpdateAccountParams) (Account, error) {
 | 
				
			||||||
	row := q.db.QueryRowContext(ctx, updateAccount,
 | 
						row := q.db.QueryRowContext(ctx, updateAccount, arg.Name, arg.OnBudget, arg.ID)
 | 
				
			||||||
		arg.Name,
 | 
					 | 
				
			||||||
		arg.OnBudget,
 | 
					 | 
				
			||||||
		arg.IsOpen,
 | 
					 | 
				
			||||||
		arg.ID,
 | 
					 | 
				
			||||||
	)
 | 
					 | 
				
			||||||
	var i Account
 | 
						var i Account
 | 
				
			||||||
	err := row.Scan(
 | 
						err := row.Scan(
 | 
				
			||||||
		&i.ID,
 | 
							&i.ID,
 | 
				
			||||||
		&i.BudgetID,
 | 
							&i.BudgetID,
 | 
				
			||||||
		&i.Name,
 | 
							&i.Name,
 | 
				
			||||||
		&i.OnBudget,
 | 
							&i.OnBudget,
 | 
				
			||||||
		&i.IsOpen,
 | 
					 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	return i, err
 | 
						return i, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,6 @@ type Account struct {
 | 
				
			|||||||
	BudgetID uuid.UUID
 | 
						BudgetID uuid.UUID
 | 
				
			||||||
	Name     string
 | 
						Name     string
 | 
				
			||||||
	OnBudget bool
 | 
						OnBudget bool
 | 
				
			||||||
	IsOpen   bool
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Assignment struct {
 | 
					type Assignment struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,31 +11,27 @@ WHERE accounts.id = $1;
 | 
				
			|||||||
-- name: GetAccounts :many
 | 
					-- name: GetAccounts :many
 | 
				
			||||||
SELECT accounts.* FROM accounts
 | 
					SELECT accounts.* FROM accounts
 | 
				
			||||||
WHERE accounts.budget_id = $1
 | 
					WHERE accounts.budget_id = $1
 | 
				
			||||||
AND accounts.is_open = TRUE
 | 
					 | 
				
			||||||
ORDER BY accounts.name;
 | 
					ORDER BY accounts.name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- name: GetAccountsWithBalance :many
 | 
					-- name: GetAccountsWithBalance :many
 | 
				
			||||||
SELECT accounts.id, accounts.name, accounts.on_budget, accounts.is_open,
 | 
					SELECT accounts.id, accounts.name, accounts.on_budget, 
 | 
				
			||||||
        (SELECT MAX(transactions.date) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.status = 'Reconciled')::date as last_reconciled,
 | 
					        (SELECT MAX(transactions.date) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.status = 'Reconciled')::date as last_reconciled,
 | 
				
			||||||
        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW())::decimal(12,2) as working_balance,
 | 
					        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW())::decimal(12,2) as working_balance,
 | 
				
			||||||
        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status IN ('Cleared', 'Reconciled'))::decimal(12,2) as cleared_balance,
 | 
					        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status IN ('Cleared', 'Reconciled'))::decimal(12,2) as cleared_balance,
 | 
				
			||||||
        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status = 'Reconciled')::decimal(12,2) as reconciled_balance
 | 
					        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status = 'Reconciled')::decimal(12,2) as reconciled_balance
 | 
				
			||||||
FROM accounts
 | 
					FROM accounts
 | 
				
			||||||
WHERE accounts.budget_id = $1
 | 
					WHERE accounts.budget_id = $1
 | 
				
			||||||
AND accounts.is_open = TRUE
 | 
					 | 
				
			||||||
ORDER BY accounts.name;
 | 
					ORDER BY accounts.name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- name: SearchAccounts :many
 | 
					-- name: SearchAccounts :many
 | 
				
			||||||
SELECT accounts.id, accounts.budget_id, accounts.name, 'account' as type FROM accounts
 | 
					SELECT accounts.id, accounts.budget_id, accounts.name, 'account' as type FROM accounts
 | 
				
			||||||
WHERE accounts.budget_id = @budget_id
 | 
					WHERE accounts.budget_id = @budget_id
 | 
				
			||||||
AND accounts.is_open = TRUE
 | 
					 | 
				
			||||||
AND accounts.name LIKE @search
 | 
					AND accounts.name LIKE @search
 | 
				
			||||||
ORDER BY accounts.name;
 | 
					ORDER BY accounts.name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- name: UpdateAccount :one
 | 
					-- name: UpdateAccount :one
 | 
				
			||||||
UPDATE accounts
 | 
					UPDATE accounts
 | 
				
			||||||
SET name = $1,
 | 
					SET name = $1,
 | 
				
			||||||
    on_budget = $2,
 | 
					    on_budget = $2
 | 
				
			||||||
    is_open = $3
 | 
					WHERE accounts.id = $3
 | 
				
			||||||
WHERE accounts.id = $4
 | 
					 | 
				
			||||||
RETURNING *;
 | 
					RETURNING *;
 | 
				
			||||||
@@ -1,5 +0,0 @@
 | 
				
			|||||||
-- +goose Up
 | 
					 | 
				
			||||||
ALTER TABLE accounts ADD COLUMN is_open BOOLEAN NOT NULL DEFAULT TRUE;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
-- +goose Down
 | 
					 | 
				
			||||||
ALTER TABLE accounts DROP COLUMN is_open;
 | 
					 | 
				
			||||||
@@ -39,7 +39,6 @@ type TransactionsResponse struct {
 | 
				
			|||||||
type EditAccountRequest struct {
 | 
					type EditAccountRequest struct {
 | 
				
			||||||
	Name     string `json:"name"`
 | 
						Name     string `json:"name"`
 | 
				
			||||||
	OnBudget bool   `json:"onBudget"`
 | 
						OnBudget bool   `json:"onBudget"`
 | 
				
			||||||
	IsOpen   bool   `json:"isOpen"`
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (h *Handler) editAccount(c *gin.Context) {
 | 
					func (h *Handler) editAccount(c *gin.Context) {
 | 
				
			||||||
@@ -60,7 +59,6 @@ func (h *Handler) editAccount(c *gin.Context) {
 | 
				
			|||||||
	updateParams := postgres.UpdateAccountParams{
 | 
						updateParams := postgres.UpdateAccountParams{
 | 
				
			||||||
		Name:     request.Name,
 | 
							Name:     request.Name,
 | 
				
			||||||
		OnBudget: request.OnBudget,
 | 
							OnBudget: request.OnBudget,
 | 
				
			||||||
		IsOpen:   request.IsOpen,
 | 
					 | 
				
			||||||
		ID:       accountUUID,
 | 
							ID:       accountUUID,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	account, err := h.Service.UpdateAccount(c.Request.Context(), updateParams)
 | 
						account, err := h.Service.UpdateAccount(c.Request.Context(), updateParams)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,7 @@ const props = defineProps<{
 | 
				
			|||||||
}>();
 | 
					}>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const emit = defineEmits<{
 | 
					const emit = defineEmits<{
 | 
				
			||||||
    (e: 'submit', event : {cancel:boolean}): boolean,
 | 
					    (e: 'submit'): void,
 | 
				
			||||||
    (e: 'open'): void,
 | 
					    (e: 'open'): void,
 | 
				
			||||||
}>();
 | 
					}>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -20,12 +20,8 @@ function openDialog() {
 | 
				
			|||||||
    visible.value = true;
 | 
					    visible.value = true;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
function submitDialog() {
 | 
					function submitDialog() {
 | 
				
			||||||
    const e = {cancel: false};
 | 
					 | 
				
			||||||
    emit("submit", e);
 | 
					 | 
				
			||||||
    if(e.cancel)
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    visible.value = false;
 | 
					    visible.value = false;
 | 
				
			||||||
 | 
					    emit("submit");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -42,9 +38,9 @@ function submitDialog() {
 | 
				
			|||||||
        v-if="visible"
 | 
					        v-if="visible"
 | 
				
			||||||
        class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full"
 | 
					        class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full"
 | 
				
			||||||
    >
 | 
					    >
 | 
				
			||||||
        <div class="relative top-20 mx-auto p-5 w-96 shadow-lg rounded-md bg-white dark:bg-black">
 | 
					        <div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white">
 | 
				
			||||||
            <div class="mt-3 text-center">
 | 
					            <div class="mt-3 text-center">
 | 
				
			||||||
                <h3 class="mt-3 text-lg leading-6 font-medium text-gray-900 dark:text-gray-100">{{ buttonText }}</h3>
 | 
					                <h3 class="mt-3 text-lg leading-6 font-medium text-gray-900">{{ buttonText }}</h3>
 | 
				
			||||||
                <slot></slot>
 | 
					                <slot></slot>
 | 
				
			||||||
                <div class="grid grid-cols-2 gap-6">
 | 
					                <div class="grid grid-cols-2 gap-6">
 | 
				
			||||||
                    <button
 | 
					                    <button
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,50 +3,29 @@ import { computed, ref } from 'vue';
 | 
				
			|||||||
import Modal from '../components/Modal.vue';
 | 
					import Modal from '../components/Modal.vue';
 | 
				
			||||||
import { useAccountStore } from '../stores/budget-account';
 | 
					import { useAccountStore } from '../stores/budget-account';
 | 
				
			||||||
import Input from '../components/Input.vue';
 | 
					import Input from '../components/Input.vue';
 | 
				
			||||||
import Checkbox from '../components/Checkbox.vue';
 | 
					 | 
				
			||||||
import { useRouter } from 'vue-router';
 | 
					 | 
				
			||||||
import { useBudgetsStore } from '../stores/budget';
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
const router = useRouter();
 | 
					 | 
				
			||||||
const accountStore = useAccountStore();
 | 
					const accountStore = useAccountStore();
 | 
				
			||||||
const CurrentAccount = computed(() => accountStore.CurrentAccount);
 | 
					const CurrentAccount = computed(() => accountStore.CurrentAccount);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const accountName = ref("");
 | 
					const accountName = ref("");
 | 
				
			||||||
const accountOnBudget = ref(true);
 | 
					const accountOnBudget = ref(true);
 | 
				
			||||||
const accountOpen = ref(true);
 | 
					 | 
				
			||||||
const error = ref("");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
function editAccount(e : {cancel:boolean}) : boolean {
 | 
					function editAccount(e : any) {
 | 
				
			||||||
    if(CurrentAccount.value?.ClearedBalance != 0 && !accountOpen.value){
 | 
					    accountStore.EditAccount(CurrentAccount.value?.ID ?? "", accountName.value, accountOnBudget.value);
 | 
				
			||||||
        e.cancel = true;
 | 
					 | 
				
			||||||
        error.value = "Cannot close account with balance";
 | 
					 | 
				
			||||||
        return false; 
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    error.value = "";
 | 
					 | 
				
			||||||
    accountStore.EditAccount(CurrentAccount.value?.ID ?? "", accountName.value, accountOnBudget.value, accountOpen.value);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // account closed, move to Budget
 | 
					 | 
				
			||||||
    if(!accountOpen.value){
 | 
					 | 
				
			||||||
        const currentBudgetID = useBudgetsStore().CurrentBudgetID;
 | 
					 | 
				
			||||||
        router.replace('/budget/'+currentBudgetID+'/budgeting');
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return true;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function openEditAccount(e : any) {
 | 
					function openEditAccount(e : any) {
 | 
				
			||||||
    accountName.value = CurrentAccount.value?.Name ?? "";
 | 
					    accountName.value = CurrentAccount.value?.Name ?? "";
 | 
				
			||||||
    accountOnBudget.value = CurrentAccount.value?.OnBudget ?? true;
 | 
					    accountOnBudget.value = CurrentAccount.value?.OnBudget ?? true;
 | 
				
			||||||
    accountOpen.value = CurrentAccount.value?.IsOpen ?? true;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <Modal button-text="Edit Account" @open="openEditAccount" @submit="editAccount">
 | 
					    <Modal button-text="Edit Account" @open="openEditAccount" @submit="editAccount">
 | 
				
			||||||
        <template v-slot:placeholder><span class="ml-2">✎</span></template>
 | 
					        <template v-slot:placeholder>✎</template>
 | 
				
			||||||
        <div class="mt-2 px-7 py-3">
 | 
					        <div class="mt-2 px-7 py-3">
 | 
				
			||||||
            <Input
 | 
					            <Input
 | 
				
			||||||
                class="border-2 dark:border-gray-700"
 | 
					                class="border-2"
 | 
				
			||||||
                type="text"
 | 
					                type="text"
 | 
				
			||||||
                v-model="accountName"
 | 
					                v-model="accountName"
 | 
				
			||||||
                placeholder="Account name"
 | 
					                placeholder="Account name"
 | 
				
			||||||
@@ -54,23 +33,13 @@ function openEditAccount(e : any) {
 | 
				
			|||||||
            />
 | 
					            />
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <div class="mt-2 px-7 py-3">
 | 
					        <div class="mt-2 px-7 py-3">
 | 
				
			||||||
            <Checkbox
 | 
					            <Input
 | 
				
			||||||
                class="border-2"
 | 
					                class="border-2"
 | 
				
			||||||
 | 
					                type="checkbox"
 | 
				
			||||||
                v-model="accountOnBudget"
 | 
					                v-model="accountOnBudget"
 | 
				
			||||||
                required
 | 
					                required
 | 
				
			||||||
            />
 | 
					            />
 | 
				
			||||||
            <label>On Budget</label>
 | 
					            <label>On Budget</label>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <div class="mt-2 px-7 py-3">
 | 
					 | 
				
			||||||
            <Checkbox
 | 
					 | 
				
			||||||
                class="border-2"
 | 
					 | 
				
			||||||
                v-model="accountOpen"
 | 
					 | 
				
			||||||
                required
 | 
					 | 
				
			||||||
            />
 | 
					 | 
				
			||||||
            <label>Open</label>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <div v-if="error != ''" class="dark:text-red-300 text-red-700">
 | 
					 | 
				
			||||||
            {{ error }}
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
    </Modal>
 | 
					    </Modal>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
@@ -43,12 +43,10 @@ function createReconcilationTransaction() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div class="grid grid-cols-[1fr_auto]">
 | 
					    <div class="grid grid-cols-[1fr_auto]">
 | 
				
			||||||
        <div>
 | 
					 | 
				
			||||||
        <h1 class="inline">
 | 
					        <h1 class="inline">
 | 
				
			||||||
            {{ accounts.CurrentAccount?.Name }}
 | 
					            {{ accounts.CurrentAccount?.Name }}
 | 
				
			||||||
            </h1>
 | 
					 | 
				
			||||||
            <EditAccount />
 | 
					            <EditAccount />
 | 
				
			||||||
        </div>
 | 
					        </h1>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <div class="text-right flex flex-wrap flex-col md:flex-row justify-end gap-2 max-w-sm">
 | 
					        <div class="text-right flex flex-wrap flex-col md:flex-row justify-end gap-2 max-w-sm">
 | 
				
			||||||
            <span class="rounded-lg p-1 whitespace-nowrap flex-1">
 | 
					            <span class="rounded-lg p-1 whitespace-nowrap flex-1">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -60,14 +60,12 @@ function getAccountName(account : Account) {
 | 
				
			|||||||
        <Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="account.ClearedBalance" />
 | 
					        <Currency :class="ExpandMenu?'md:inline':'md:hidden'" :value="account.ClearedBalance" />
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    </li>
 | 
					    </li>
 | 
				
			||||||
    <!--
 | 
					 | 
				
			||||||
    <li class="bg-slate-100 dark:bg-slate-800 my-2 p-2 px-3">
 | 
					    <li class="bg-slate-100 dark:bg-slate-800 my-2 p-2 px-3">
 | 
				
			||||||
      <div class="flex flex-row justify-between font-bold">
 | 
					      <div class="flex flex-row justify-between font-bold">
 | 
				
			||||||
        <span>Closed Accounts</span>
 | 
					        <span>Closed Accounts</span>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
      + Add Account
 | 
					      + Add Account
 | 
				
			||||||
    </li>
 | 
					    </li>
 | 
				
			||||||
    -->
 | 
					 | 
				
			||||||
    <!--<li>
 | 
					    <!--<li>
 | 
				
			||||||
      <router-link :to="'/budget/'+CurrentBudgetID+'/accounts'">Edit accounts</router-link>
 | 
					      <router-link :to="'/budget/'+CurrentBudgetID+'/accounts'">Edit accounts</router-link>
 | 
				
			||||||
    </li>-->
 | 
					    </li>-->
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,7 +16,6 @@ export interface Account {
 | 
				
			|||||||
    ID: string
 | 
					    ID: string
 | 
				
			||||||
    Name: string
 | 
					    Name: string
 | 
				
			||||||
    OnBudget: boolean
 | 
					    OnBudget: boolean
 | 
				
			||||||
    IsOpen: boolean
 | 
					 | 
				
			||||||
    ClearedBalance: number
 | 
					    ClearedBalance: number
 | 
				
			||||||
    WorkingBalance: number
 | 
					    WorkingBalance: number
 | 
				
			||||||
    ReconciledBalance: number
 | 
					    ReconciledBalance: number
 | 
				
			||||||
@@ -124,14 +123,10 @@ export const useAccountStore = defineStore("budget/account", {
 | 
				
			|||||||
                return;
 | 
					                return;
 | 
				
			||||||
            this.addCategoriesForMonth(year, month, response.Categories);
 | 
					            this.addCategoriesForMonth(year, month, response.Categories);
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        async EditAccount(accountid: string, name: string, onBudget: boolean, isOpen: boolean) {
 | 
					        async EditAccount(accountid: string, name: string, onBudget: boolean) {
 | 
				
			||||||
            const result = await POST("/account/" + accountid, JSON.stringify({ name: name, onBudget: onBudget, isOpen: isOpen }));
 | 
					            const result = await POST("/account/" + accountid, JSON.stringify({ name: name, onBudget: onBudget }));
 | 
				
			||||||
            const response = await result.json();
 | 
					            const response = await result.json();
 | 
				
			||||||
            useBudgetsStore().MergeBudgetingData(response);
 | 
					            useBudgetsStore().MergeBudgetingData(response);
 | 
				
			||||||
 | 
					 | 
				
			||||||
            if(!isOpen) {
 | 
					 | 
				
			||||||
                this.Accounts.delete(accountid);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        addCategoriesForMonth(year: number, month: number, categories: Category[]): void {
 | 
					        addCategoriesForMonth(year: number, month: number, categories: Category[]): void {
 | 
				
			||||||
            this.$patch((state) => {
 | 
					            this.$patch((state) => {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user