From a87bda09f7ce674130493703cd2126fca0a106f0 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 21 Jul 2024 17:45:42 +0800 Subject: [PATCH] modify the calculation strategy of month total amount --- src/stores/transaction.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/stores/transaction.js b/src/stores/transaction.js index c2ec958a..7dd2409b 100644 --- a/src/stores/transaction.js +++ b/src/stores/transaction.js @@ -50,8 +50,22 @@ function loadTransactionList(state, settingsStore, exchangeRatesStore, { transac const transactionMonth = getMonth(transactionTime); const transactionYearMonth = getYearAndMonth(transactionTime); + if (i === 0 && state.transactions.length > 0) { + const lastMonthList = state.transactions[state.transactions.length - 1]; + + if (lastMonthList.totalAmount.incompleteExpense || lastMonthList.totalAmount.incompleteIncome) { + // calculate the total amount of last month which has incomplete total amount before starting to process a new request + calculateMonthTotalAmount(exchangeRatesStore, lastMonthList, defaultCurrency, state.transactionsFilter.accountIds, false); + } + } + if (currentMonthList && currentMonthList.year === transactionYear && currentMonthList.month === transactionMonth) { currentMonthList.items.push(Object.freeze(item)); + + if (i === transactions.items.length - 1) { + // calculate the total amount of current month when processing the last transaction item of this request + calculateMonthTotalAmount(exchangeRatesStore, currentMonthList, defaultCurrency, state.transactionsFilter.accountIds, true); + } continue; } @@ -64,6 +78,7 @@ function loadTransactionList(state, settingsStore, exchangeRatesStore, { transac } if (!currentMonthList || currentMonthList.year !== transactionYear || currentMonthList.month !== transactionMonth) { + // calculate the total amount of current month when processing the first transaction item of the next month calculateMonthTotalAmount(exchangeRatesStore, currentMonthList, defaultCurrency, state.transactionsFilter.accountIds, false); state.transactions.push({ @@ -79,6 +94,7 @@ function loadTransactionList(state, settingsStore, exchangeRatesStore, { transac } currentMonthList.items.push(Object.freeze(item)); + // init the total amount struct of current month when processing the first transaction item of current month calculateMonthTotalAmount(exchangeRatesStore, currentMonthList, defaultCurrency, state.transactionsFilter.accountIds, true); } }