Add ReconcilationTransactionAmount
This commit is contained in:
parent
52503a4c92
commit
16bcf516f6
@ -5,12 +5,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ReconcileTransactionsRequest struct {
|
type ReconcileTransactionsRequest struct {
|
||||||
TransactionIDs []uuid.UUID
|
TransactionIDs []uuid.UUID `json:"transactionIds"`
|
||||||
|
ReconcilationTransactionAmount numeric.Numeric `json:"reconcilationTransactionAmount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) reconcileTransactions(c *gin.Context) {
|
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{})
|
tx, err := h.Service.BeginTx(c.Request.Context(), &sql.TxOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("update transaction: %w", err))
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("begin tx: %w", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
db := h.Service.WithTx(tx)
|
db := h.Service.WithTx(tx)
|
||||||
@ -34,7 +36,11 @@ func (h *Handler) reconcileTransactions(c *gin.Context) {
|
|||||||
return
|
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))})
|
c.JSON(http.StatusOK, SuccessResponse{fmt.Sprintf("Set status for %d transactions", len(request.TransactionIDs))})
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,8 @@ function cancelReconcilation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function submitReconcilation() {
|
function submitReconcilation() {
|
||||||
|
accounts.SubmitReconcilation();
|
||||||
|
accounts.Reconciling = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createReconcilationTransaction() {
|
function createReconcilationTransaction() {
|
||||||
|
@ -176,7 +176,21 @@ export const useAccountStore = defineStore("budget/account", {
|
|||||||
|
|
||||||
transaction.Reconciled = value;
|
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() {
|
logout() {
|
||||||
this.$reset()
|
this.$reset()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user