Actually handle passed reconciliation amount
This commit is contained in:
parent
2cf6b815bf
commit
27dd6e923c
@ -4,6 +4,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.javil.eu/jacob1123/budgeteer/postgres"
|
||||
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||
@ -13,17 +14,24 @@ import (
|
||||
|
||||
type ReconcileTransactionsRequest struct {
|
||||
TransactionIDs []uuid.UUID `json:"transactionIds"`
|
||||
ReconcilationTransactionAmount numeric.Numeric `json:"reconcilationTransactionAmount"`
|
||||
ReconcilationTransactionAmount numeric.Numeric `json:"reconciliationTransactionAmount"`
|
||||
}
|
||||
|
||||
type ReconcileTransactionsResponse struct {
|
||||
Message string
|
||||
ReconcilationTransaction []postgres.GetTransactionsForAccountRow
|
||||
Message string
|
||||
ReconciliationTransaction *postgres.DisplayTransaction
|
||||
}
|
||||
|
||||
func (h *Handler) reconcileTransactions(c *gin.Context) {
|
||||
accountID := c.Param("accountid")
|
||||
accountUUID, err := uuid.Parse(accountID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
var request ReconcileTransactionsRequest
|
||||
err := c.BindJSON(&request)
|
||||
err = c.BindJSON(&request)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("parse request: %w", err))
|
||||
return
|
||||
@ -48,8 +56,32 @@ func (h *Handler) reconcileTransactions(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var reconciliationTransaction *postgres.DisplayTransaction
|
||||
if !request.ReconcilationTransactionAmount.IsZero() {
|
||||
createTransaction := postgres.CreateTransactionParams{
|
||||
Date: time.Now(),
|
||||
Memo: "Reconciliation Transaction",
|
||||
Amount: request.ReconcilationTransactionAmount,
|
||||
AccountID: accountUUID,
|
||||
Status: "Reconciled",
|
||||
}
|
||||
newTransaction, err := h.Service.CreateTransaction(c.Request.Context(), createTransaction)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("insert new transaction: %w", err))
|
||||
return
|
||||
}
|
||||
|
||||
transaction, err := h.Service.GetTransaction(c.Request.Context(), newTransaction.ID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("get created transaction: %w", err))
|
||||
return
|
||||
}
|
||||
|
||||
reconciliationTransaction = &transaction
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, ReconcileTransactionsResponse{
|
||||
Message: fmt.Sprintf("Set status for %d transactions", len(request.TransactionIDs)),
|
||||
ReconcilationTransaction: nil,
|
||||
Message: fmt.Sprintf("Set status for %d transactions", len(request.TransactionIDs)),
|
||||
ReconciliationTransaction: reconciliationTransaction,
|
||||
})
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ export const useAccountStore = defineStore("budget/account", {
|
||||
transaction.Reconciled = value;
|
||||
}
|
||||
},
|
||||
async SubmitReconcilation(reconcilationTransactionAmount : number) {
|
||||
async SubmitReconcilation(reconciliationTransactionAmount : number) {
|
||||
const account = this.CurrentAccount!;
|
||||
const reconciledTransactions = this.TransactionsList.filter(x => x.Reconciled);
|
||||
for (const transaction of reconciledTransactions) {
|
||||
@ -187,7 +187,7 @@ export const useAccountStore = defineStore("budget/account", {
|
||||
}
|
||||
const result = await POST("/account/" + this.CurrentAccountID + "/reconcile", JSON.stringify({
|
||||
transactionIDs: reconciledTransactions.map(x => x.ID),
|
||||
reconcilationTransactionAmount: reconcilationTransactionAmount,
|
||||
reconciliationTransactionAmount: reconciliationTransactionAmount,
|
||||
}));
|
||||
const response = await result.json();
|
||||
console.log("Reconcile: " + response.message);
|
||||
|
Loading…
x
Reference in New Issue
Block a user