Add ReconcilationTransactionAmount

This commit is contained in:
Jan Bader 2022-02-27 20:34:10 +00:00
parent 52503a4c92
commit 16bcf516f6
3 changed files with 26 additions and 5 deletions

View File

@ -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))})
}

View File

@ -26,7 +26,8 @@ function cancelReconcilation() {
}
function submitReconcilation() {
accounts.SubmitReconcilation();
accounts.Reconciling = false;
}
function createReconcilationTransaction() {

View File

@ -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()