From 16bcf516f69928f43945935dd5e1b5494c07109f Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Sun, 27 Feb 2022 20:34:10 +0000 Subject: [PATCH] Add ReconcilationTransactionAmount --- server/reconcile.go | 12 +++++++++--- web/src/pages/Account.vue | 3 ++- web/src/stores/budget-account.ts | 16 +++++++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/server/reconcile.go b/server/reconcile.go index 4941e53..c8caf05 100644 --- a/server/reconcile.go +++ b/server/reconcile.go @@ -5,12 +5,14 @@ import ( "fmt" "net/http" + "git.javil.eu/jacob1123/budgeteer/postgres/numeric" "github.com/gin-gonic/gin" "github.com/google/uuid" ) type ReconcileTransactionsRequest struct { - TransactionIDs []uuid.UUID + TransactionIDs []uuid.UUID `json:"transactionIds"` + ReconcilationTransactionAmount numeric.Numeric `json:"reconcilationTransactionAmount"` } func (h *Handler) reconcileTransactions(c *gin.Context) { @@ -23,7 +25,7 @@ func (h *Handler) reconcileTransactions(c *gin.Context) { tx, err := h.Service.BeginTx(c.Request.Context(), &sql.TxOptions{}) if err != nil { - c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("update transaction: %w", err)) + c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("begin tx: %w", err)) return } db := h.Service.WithTx(tx) @@ -34,7 +36,11 @@ func (h *Handler) reconcileTransactions(c *gin.Context) { return } } - tx.Commit() + err = tx.Commit() + if err != nil { + c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("commit: %w", err)) + return + } c.JSON(http.StatusOK, SuccessResponse{fmt.Sprintf("Set status for %d transactions", len(request.TransactionIDs))}) } diff --git a/web/src/pages/Account.vue b/web/src/pages/Account.vue index d0fe2f3..6f24f94 100644 --- a/web/src/pages/Account.vue +++ b/web/src/pages/Account.vue @@ -26,7 +26,8 @@ function cancelReconcilation() { } function submitReconcilation() { - + accounts.SubmitReconcilation(); + accounts.Reconciling = false; } function createReconcilationTransaction() { diff --git a/web/src/stores/budget-account.ts b/web/src/stores/budget-account.ts index f6e6c75..dc0f4b8 100644 --- a/web/src/stores/budget-account.ts +++ b/web/src/stores/budget-account.ts @@ -176,7 +176,21 @@ export const useAccountStore = defineStore("budget/account", { transaction.Reconciled = value; } - + }, + async SubmitReconcilation(reconcilationTransactionAmount : number) { + const account = this.CurrentAccount!; + const reconciledTransactions = this.TransactionsList.filter(x => x.Reconciled); + for (const transaction of reconciledTransactions) { + account.ReconciledBalance += transaction.Amount; + transaction.Status = "Reconciled"; + transaction.Reconciled = false; + } + const result = await POST("/account/" + this.CurrentAccountID + "/reconcile", JSON.stringify({ + transactionIDs: reconciledTransactions.map(x => x.ID), + reconcilationTransactionAmount: reconcilationTransactionAmount, + })); + const response = await result.json(); + console.log("Reconcile: " + response.message); }, logout() { this.$reset()