Implement closing of accounts #36
| @@ -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 | RETURNING id, budget_id, name, on_budget, is_open | ||||||
| ` | ` | ||||||
|  |  | ||||||
| type CreateAccountParams struct { | type CreateAccountParams struct { | ||||||
| @@ -31,12 +31,13 @@ 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 FROM accounts | SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget, accounts.is_open FROM accounts | ||||||
| WHERE accounts.id = $1 | WHERE accounts.id = $1 | ||||||
| ` | ` | ||||||
|  |  | ||||||
| @@ -48,13 +49,15 @@ 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 FROM accounts | SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget, accounts.is_open 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 | ||||||
| ` | ` | ||||||
|  |  | ||||||
| @@ -72,6 +75,7 @@ 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 | ||||||
| 		} | 		} | ||||||
| @@ -87,13 +91,14 @@ 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,  | SELECT accounts.id, accounts.name, accounts.on_budget, accounts.is_open, | ||||||
|         (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 | ||||||
| ` | ` | ||||||
|  |  | ||||||
| @@ -101,6 +106,7 @@ 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 | ||||||
| @@ -120,6 +126,7 @@ 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, | ||||||
| @@ -141,6 +148,7 @@ 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 | ||||||
| ` | ` | ||||||
| @@ -188,25 +196,33 @@ 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, | ||||||
| WHERE accounts.id = $3 |     is_open = $3 | ||||||
| RETURNING id, budget_id, name, on_budget | WHERE accounts.id = $4 | ||||||
|  | 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, arg.Name, arg.OnBudget, arg.ID) | 	row := q.db.QueryRowContext(ctx, updateAccount, | ||||||
|  | 		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,6 +36,7 @@ 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,27 +11,31 @@ 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,  | SELECT accounts.id, accounts.name, accounts.on_budget, accounts.is_open, | ||||||
|         (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, | ||||||
| WHERE accounts.id = $3 |     is_open = $3 | ||||||
|  | WHERE accounts.id = $4 | ||||||
| RETURNING *; | RETURNING *; | ||||||
							
								
								
									
										5
									
								
								postgres/schema/0016_closed-accounts.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								postgres/schema/0016_closed-accounts.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | |||||||
|  | -- +goose Up | ||||||
|  | ALTER TABLE accounts ADD COLUMN is_open BOOLEAN NOT NULL DEFAULT TRUE; | ||||||
|  |  | ||||||
|  | -- +goose Down | ||||||
|  | ALTER TABLE accounts DROP COLUMN is_open; | ||||||
| @@ -39,6 +39,7 @@ 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) { | ||||||
| @@ -59,6 +60,7 @@ 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'): void, |     (e: 'submit', event : {cancel:boolean}): boolean, | ||||||
|     (e: 'open'): void, |     (e: 'open'): void, | ||||||
| }>(); | }>(); | ||||||
|  |  | ||||||
| @@ -20,8 +20,12 @@ 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> | ||||||
|  |  | ||||||
| @@ -38,9 +42,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 border w-96 shadow-lg rounded-md bg-white"> |         <div class="relative top-20 mx-auto p-5 w-96 shadow-lg rounded-md bg-white dark:bg-black"> | ||||||
|             <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">{{ buttonText }}</h3> |                 <h3 class="mt-3 text-lg leading-6 font-medium text-gray-900 dark:text-gray-100">{{ 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,29 +3,50 @@ 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 : any) { | function editAccount(e : {cancel:boolean}) : boolean { | ||||||
|     accountStore.EditAccount(CurrentAccount.value?.ID ?? "", accountName.value, accountOnBudget.value); |     if(CurrentAccount.value?.ClearedBalance != 0 && !accountOpen.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>✎</template> |         <template v-slot:placeholder><span class="ml-2">✎</span></template> | ||||||
|         <div class="mt-2 px-7 py-3"> |         <div class="mt-2 px-7 py-3"> | ||||||
|             <Input |             <Input | ||||||
|                 class="border-2" |                 class="border-2 dark:border-gray-700" | ||||||
|                 type="text" |                 type="text" | ||||||
|                 v-model="accountName" |                 v-model="accountName" | ||||||
|                 placeholder="Account name" |                 placeholder="Account name" | ||||||
| @@ -33,13 +54,23 @@ function openEditAccount(e : any) { | |||||||
|             /> |             /> | ||||||
|         </div> |         </div> | ||||||
|         <div class="mt-2 px-7 py-3"> |         <div class="mt-2 px-7 py-3"> | ||||||
|             <Input |             <Checkbox | ||||||
|                 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,10 +43,12 @@ function createReconcilationTransaction() { | |||||||
|  |  | ||||||
| <template> | <template> | ||||||
|     <div class="grid grid-cols-[1fr_auto]"> |     <div class="grid grid-cols-[1fr_auto]"> | ||||||
|         <h1 class="inline"> |         <div> | ||||||
|             {{ accounts.CurrentAccount?.Name }} |             <h1 class="inline"> | ||||||
|  |                 {{ accounts.CurrentAccount?.Name }} | ||||||
|  |             </h1> | ||||||
|             <EditAccount /> |             <EditAccount /> | ||||||
|         </h1> |         </div> | ||||||
|  |  | ||||||
|         <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,11 +60,11 @@ 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-red-200 dark:bg-red-800 rounded-lg m-1 p-1 px-3"> |     <!--<li class="bg-red-200 dark:bg-red-800 rounded-lg m-1 p-1 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> | ||||||
|     </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,6 +16,7 @@ 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 | ||||||
| @@ -123,10 +124,14 @@ 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) { |         async EditAccount(accountid: string, name: string, onBudget: boolean, isOpen: boolean) { | ||||||
|             const result = await POST("/account/" + accountid, JSON.stringify({ name: name, onBudget: onBudget })); |             const result = await POST("/account/" + accountid, JSON.stringify({ name: name, onBudget: onBudget, isOpen: isOpen })); | ||||||
|             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