Pass amount as string and add transaction correctly
This commit is contained in:
parent
bd686e0c00
commit
faef975f1a
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
type ReconcileTransactionsRequest struct {
|
type ReconcileTransactionsRequest struct {
|
||||||
TransactionIDs []uuid.UUID `json:"transactionIds"`
|
TransactionIDs []uuid.UUID `json:"transactionIds"`
|
||||||
ReconcilationTransactionAmount numeric.Numeric `json:"reconciliationTransactionAmount"`
|
ReconcilationTransactionAmount string `json:"reconciliationTransactionAmount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReconcileTransactionsResponse struct {
|
type ReconcileTransactionsResponse struct {
|
||||||
@ -37,6 +37,13 @@ func (h *Handler) reconcileTransactions(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var amount numeric.Numeric
|
||||||
|
err = amount.Set(request.ReconcilationTransactionAmount)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("parse request: %w", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
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("begin tx: %w", err))
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("begin tx: %w", err))
|
||||||
@ -52,7 +59,7 @@ func (h *Handler) reconcileTransactions(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reconciliationTransaction, err := h.CreateReconcilationTransaction(request, accountUUID, db, c)
|
reconciliationTransaction, err := h.CreateReconcilationTransaction(amount, accountUUID, db, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("insert new transaction: %w", err))
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("insert new transaction: %w", err))
|
||||||
return
|
return
|
||||||
@ -70,15 +77,15 @@ func (h *Handler) reconcileTransactions(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Handler) CreateReconcilationTransaction(request ReconcileTransactionsRequest, accountUUID uuid.UUID, db *postgres.Queries, c *gin.Context) (*postgres.DisplayTransaction, error) {
|
func (*Handler) CreateReconcilationTransaction(amount numeric.Numeric, accountUUID uuid.UUID, db *postgres.Queries, c *gin.Context) (*postgres.DisplayTransaction, error) {
|
||||||
if request.ReconcilationTransactionAmount.IsZero() {
|
if amount.IsZero() {
|
||||||
return nil, nil //nolint: nilnil
|
return nil, nil //nolint: nilnil
|
||||||
}
|
}
|
||||||
|
|
||||||
createTransaction := postgres.CreateTransactionParams{
|
createTransaction := postgres.CreateTransactionParams{
|
||||||
Date: time.Now(),
|
Date: time.Now(),
|
||||||
Memo: "Reconciliation Transaction",
|
Memo: "Reconciliation Transaction",
|
||||||
Amount: request.ReconcilationTransactionAmount,
|
Amount: amount,
|
||||||
AccountID: accountUUID,
|
AccountID: accountUUID,
|
||||||
Status: "Reconciled",
|
Status: "Reconciled",
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ function submitReconcilation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createReconcilationTransaction() {
|
function createReconcilationTransaction() {
|
||||||
const diff = accounts.ReconcilingBalance - TargetReconcilingBalance.value;
|
const diff = TargetReconcilingBalance.value - accounts.ReconcilingBalance ;
|
||||||
accounts.SubmitReconcilation(diff);
|
accounts.SubmitReconcilation(diff);
|
||||||
accounts.Reconciling = false;
|
accounts.Reconciling = false;
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ function createReconcilationTransaction() {
|
|||||||
</tr>
|
</tr>
|
||||||
<TransactionInputRow :budgetid="budgetid" :accountid="accountid" />
|
<TransactionInputRow :budgetid="budgetid" :accountid="accountid" />
|
||||||
<TransactionRow
|
<TransactionRow
|
||||||
v-for="(transaction, index) in accounts.TransactionsList"
|
v-for="(transaction, index) in accounts.TransactionsList" :key="transaction.ID"
|
||||||
:transaction="transaction"
|
:transaction="transaction"
|
||||||
:index="index"
|
:index="index"
|
||||||
/>
|
/>
|
||||||
|
@ -135,13 +135,16 @@ export const useAccountStore = defineStore("budget/account", {
|
|||||||
useSessionStore().setTitle(account.Name);
|
useSessionStore().setTitle(account.Name);
|
||||||
await this.FetchAccount(account);
|
await this.FetchAccount(account);
|
||||||
},
|
},
|
||||||
|
AddTransaction(account: Account, transaction: any) {
|
||||||
|
transaction.Date = new Date(transaction.Date);
|
||||||
|
this.Transactions.set(transaction.ID, transaction);
|
||||||
|
},
|
||||||
async FetchAccount(account: Account) {
|
async FetchAccount(account: Account) {
|
||||||
const result = await GET("/account/" + account.ID + "/transactions");
|
const result = await GET("/account/" + account.ID + "/transactions");
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
account.Transactions = [];
|
account.Transactions = [];
|
||||||
for (const transaction of response.Transactions) {
|
for (const transaction of response.Transactions) {
|
||||||
transaction.Date = new Date(transaction.Date);
|
this.AddTransaction(account, transaction);
|
||||||
this.Transactions.set(transaction.ID, transaction);
|
|
||||||
account.Transactions.push(transaction.ID);
|
account.Transactions.push(transaction.ID);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -177,7 +180,7 @@ export const useAccountStore = defineStore("budget/account", {
|
|||||||
transaction.Reconciled = value;
|
transaction.Reconciled = value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async SubmitReconcilation(reconciliationTransactionAmount : number) {
|
async SubmitReconcilation(reconciliationTransactionAmount: number) {
|
||||||
const account = this.CurrentAccount!;
|
const account = this.CurrentAccount!;
|
||||||
const reconciledTransactions = this.TransactionsList.filter(x => x.Reconciled);
|
const reconciledTransactions = this.TransactionsList.filter(x => x.Reconciled);
|
||||||
for (const transaction of reconciledTransactions) {
|
for (const transaction of reconciledTransactions) {
|
||||||
@ -187,9 +190,14 @@ export const useAccountStore = defineStore("budget/account", {
|
|||||||
}
|
}
|
||||||
const result = await POST("/account/" + this.CurrentAccountID + "/reconcile", JSON.stringify({
|
const result = await POST("/account/" + this.CurrentAccountID + "/reconcile", JSON.stringify({
|
||||||
transactionIDs: reconciledTransactions.map(x => x.ID),
|
transactionIDs: reconciledTransactions.map(x => x.ID),
|
||||||
reconciliationTransactionAmount: reconciliationTransactionAmount,
|
reconciliationTransactionAmount: reconciliationTransactionAmount.toString(),
|
||||||
}));
|
}));
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
const recTrans = response.ReconciliationTransaction;
|
||||||
|
if (recTrans) {
|
||||||
|
this.AddTransaction(account, recTrans);
|
||||||
|
account.Transactions.unshift(recTrans.ID);
|
||||||
|
}
|
||||||
console.log("Reconcile: " + response.message);
|
console.log("Reconcile: " + response.message);
|
||||||
},
|
},
|
||||||
logout() {
|
logout() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user