mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 06:57:35 +08:00
show opening / closing balance in reconciliation statement dialog
This commit is contained in:
@@ -340,7 +340,7 @@ func (a *TransactionsApi) TransactionReconciliationStatementHandler(c *core.WebC
|
||||
minTransactionTime = utils.GetMinTransactionTimeFromUnixTime(reconciliationStatementRequest.StartTime)
|
||||
}
|
||||
|
||||
transactionsWithAccountBalance, err := a.transactions.GetAllTransactionsWithAccountBalanceByMaxTime(c, uid, pageCountForAccountStatement, maxTransactionTime, minTransactionTime, reconciliationStatementRequest.AccountId)
|
||||
transactionsWithAccountBalance, openingBalance, closingBalance, err := a.transactions.GetAllTransactionsWithAccountBalanceByMaxTime(c, uid, pageCountForAccountStatement, maxTransactionTime, minTransactionTime, reconciliationStatementRequest.AccountId)
|
||||
|
||||
if err != nil {
|
||||
log.Errorf(c, "[transactions.TransactionReconciliationStatementHandler] failed to get transactions from \"%d\" to \"%d\" for user \"uid:%d\", because %s", reconciliationStatementRequest.StartTime, reconciliationStatementRequest.EndTime, uid, err.Error())
|
||||
@@ -383,7 +383,9 @@ func (a *TransactionsApi) TransactionReconciliationStatementHandler(c *core.WebC
|
||||
}
|
||||
|
||||
reconciliationStatementResp := &models.TransactionReconciliationStatementResponse{
|
||||
Transactions: responseItems,
|
||||
Transactions: responseItems,
|
||||
OpeningBalance: openingBalance,
|
||||
ClosingBalance: closingBalance,
|
||||
}
|
||||
|
||||
return reconciliationStatementResp, nil
|
||||
|
||||
@@ -343,7 +343,9 @@ type TransactionReconciliationStatementResponseItem struct {
|
||||
|
||||
// TransactionReconciliationStatementResponse represents the response of all transaction reconciliation statement response
|
||||
type TransactionReconciliationStatementResponse struct {
|
||||
Transactions []*TransactionReconciliationStatementResponseItem `json:"transactions"`
|
||||
Transactions []*TransactionReconciliationStatementResponseItem `json:"transactions"`
|
||||
OpeningBalance int64 `json:"openingBalance"`
|
||||
ClosingBalance int64 `json:"closingBalance"`
|
||||
}
|
||||
|
||||
// TransactionStatisticResponse represents transaction statistic response
|
||||
|
||||
@@ -108,7 +108,7 @@ func (s *TransactionService) GetAllSpecifiedTransactions(c core.Context, uid int
|
||||
}
|
||||
|
||||
// GetAllTransactionsWithAccountBalanceByMaxTime returns account statement within time range
|
||||
func (s *TransactionService) GetAllTransactionsWithAccountBalanceByMaxTime(c core.Context, uid int64, pageCount int32, maxTransactionTime int64, minTransactionTime int64, accountId int64) ([]*models.TransactionWithAccountBalance, error) {
|
||||
func (s *TransactionService) GetAllTransactionsWithAccountBalanceByMaxTime(c core.Context, uid int64, pageCount int32, maxTransactionTime int64, minTransactionTime int64, accountId int64) ([]*models.TransactionWithAccountBalance, int64, int64, error) {
|
||||
if maxTransactionTime <= 0 {
|
||||
maxTransactionTime = utils.GetMaxTransactionTimeFromUnixTime(time.Now().Unix())
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func (s *TransactionService) GetAllTransactionsWithAccountBalanceByMaxTime(c cor
|
||||
transactions, err := s.GetTransactionsByMaxTime(c, uid, maxTransactionTime, 0, 0, nil, []int64{accountId}, nil, false, models.TRANSACTION_TAG_FILTER_HAS_ANY, "", "", 1, pageCount, false, true)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
|
||||
allTransactions = append(allTransactions, transactions...)
|
||||
@@ -135,9 +135,10 @@ func (s *TransactionService) GetAllTransactionsWithAccountBalanceByMaxTime(c cor
|
||||
allTransactionsAndAccountBalance := make([]*models.TransactionWithAccountBalance, 0, len(allTransactions))
|
||||
|
||||
if len(allTransactions) < 1 {
|
||||
return allTransactionsAndAccountBalance, nil
|
||||
return allTransactionsAndAccountBalance, 0, 0, nil
|
||||
}
|
||||
|
||||
openingBalance := int64(0)
|
||||
accumulatedBalance := int64(0)
|
||||
|
||||
for i := len(allTransactions) - 1; i >= 0; i-- {
|
||||
@@ -155,10 +156,11 @@ func (s *TransactionService) GetAllTransactionsWithAccountBalanceByMaxTime(c cor
|
||||
accumulatedBalance = accumulatedBalance + transaction.Amount
|
||||
} else {
|
||||
log.Errorf(c, "[transactions.GetAllTransactionsWithAccountBalanceByMaxTime] trasaction type (%d) is invalid (id:%d)", transaction.TransactionId, transaction.Type)
|
||||
return nil, errs.ErrTransactionTypeInvalid
|
||||
return nil, 0, 0, errs.ErrTransactionTypeInvalid
|
||||
}
|
||||
|
||||
if transaction.TransactionTime < minTransactionTime {
|
||||
openingBalance = accumulatedBalance
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -170,7 +172,7 @@ func (s *TransactionService) GetAllTransactionsWithAccountBalanceByMaxTime(c cor
|
||||
allTransactionsAndAccountBalance = append(allTransactionsAndAccountBalance, transactionsAndAccountBalance)
|
||||
}
|
||||
|
||||
return allTransactionsAndAccountBalance, nil
|
||||
return allTransactionsAndAccountBalance, openingBalance, accumulatedBalance, nil
|
||||
}
|
||||
|
||||
// GetTransactionsByMaxTime returns transactions before given time
|
||||
|
||||
@@ -1830,6 +1830,9 @@
|
||||
"Total Outflows": "Total Outflows",
|
||||
"Total Inflows": "Total Inflows",
|
||||
"Total Balance": "Gesamtsaldo",
|
||||
"Total Transactions": "Total Transactions",
|
||||
"Opening Balance": "Opening Balance",
|
||||
"Closing Balance": "Closing Balance",
|
||||
"Expense By Account": "Ausgaben nach Konto",
|
||||
"Expense By Primary Category": "Ausgaben nach Primärkategorie",
|
||||
"Expense By Secondary Category": "Ausgaben nach Sekundärkategorie",
|
||||
|
||||
@@ -1830,6 +1830,9 @@
|
||||
"Total Outflows": "Total Outflows",
|
||||
"Total Inflows": "Total Inflows",
|
||||
"Total Balance": "Total Balance",
|
||||
"Total Transactions": "Total Transactions",
|
||||
"Opening Balance": "Opening Balance",
|
||||
"Closing Balance": "Closing Balance",
|
||||
"Expense By Account": "Expense By Account",
|
||||
"Expense By Primary Category": "Expense By Primary Category",
|
||||
"Expense By Secondary Category": "Expense By Secondary Category",
|
||||
|
||||
@@ -1830,6 +1830,9 @@
|
||||
"Total Outflows": "Total Outflows",
|
||||
"Total Inflows": "Total Inflows",
|
||||
"Total Balance": "Saldo total",
|
||||
"Total Transactions": "Total Transactions",
|
||||
"Opening Balance": "Opening Balance",
|
||||
"Closing Balance": "Closing Balance",
|
||||
"Expense By Account": "Gasto por cuenta",
|
||||
"Expense By Primary Category": "Gasto por categoría primaria",
|
||||
"Expense By Secondary Category": "Gasto por categoría secundaria",
|
||||
|
||||
@@ -1830,6 +1830,9 @@
|
||||
"Total Outflows": "Total Outflows",
|
||||
"Total Inflows": "Total Inflows",
|
||||
"Total Balance": "Saldo totale",
|
||||
"Total Transactions": "Total Transactions",
|
||||
"Opening Balance": "Opening Balance",
|
||||
"Closing Balance": "Closing Balance",
|
||||
"Expense By Account": "Spesa per conto",
|
||||
"Expense By Primary Category": "Spesa per categoria principale",
|
||||
"Expense By Secondary Category": "Spesa per categoria secondaria",
|
||||
|
||||
@@ -1830,6 +1830,9 @@
|
||||
"Total Outflows": "Total Outflows",
|
||||
"Total Inflows": "Total Inflows",
|
||||
"Total Balance": "残高合計",
|
||||
"Total Transactions": "Total Transactions",
|
||||
"Opening Balance": "Opening Balance",
|
||||
"Closing Balance": "Closing Balance",
|
||||
"Expense By Account": "口座別の支出",
|
||||
"Expense By Primary Category": "一次カテゴリ別の支出",
|
||||
"Expense By Secondary Category": "二次カテゴリ別の支出",
|
||||
|
||||
@@ -1830,6 +1830,9 @@
|
||||
"Total Outflows": "Total Outflows",
|
||||
"Total Inflows": "Total Inflows",
|
||||
"Total Balance": "Saldo Total",
|
||||
"Total Transactions": "Total Transactions",
|
||||
"Opening Balance": "Opening Balance",
|
||||
"Closing Balance": "Closing Balance",
|
||||
"Expense By Account": "Despesa por Conta",
|
||||
"Expense By Primary Category": "Despesa por Categoria Primária",
|
||||
"Expense By Secondary Category": "Despesa por Categoria Secundária",
|
||||
|
||||
@@ -1830,6 +1830,9 @@
|
||||
"Total Outflows": "Total Outflows",
|
||||
"Total Inflows": "Total Inflows",
|
||||
"Total Balance": "Общий баланс",
|
||||
"Total Transactions": "Total Transactions",
|
||||
"Opening Balance": "Opening Balance",
|
||||
"Closing Balance": "Closing Balance",
|
||||
"Expense By Account": "Расходы по счетам",
|
||||
"Expense By Primary Category": "Расходы по основной категории",
|
||||
"Expense By Secondary Category": "Расходы по вторичной категории",
|
||||
|
||||
@@ -1830,6 +1830,9 @@
|
||||
"Total Outflows": "Total Outflows",
|
||||
"Total Inflows": "Total Inflows",
|
||||
"Total Balance": "Загальний баланс",
|
||||
"Total Transactions": "Total Transactions",
|
||||
"Opening Balance": "Opening Balance",
|
||||
"Closing Balance": "Closing Balance",
|
||||
"Expense By Account": "Витрати за рахунками",
|
||||
"Expense By Primary Category": "Витрати за основними категоріями",
|
||||
"Expense By Secondary Category": "Витрати за другорядними категоріями",
|
||||
|
||||
@@ -1830,6 +1830,9 @@
|
||||
"Total Outflows": "Total Outflows",
|
||||
"Total Inflows": "Total Inflows",
|
||||
"Total Balance": "Tổng số dư",
|
||||
"Total Transactions": "Total Transactions",
|
||||
"Opening Balance": "Opening Balance",
|
||||
"Closing Balance": "Closing Balance",
|
||||
"Expense By Account": "Chi phí theo tài khoản",
|
||||
"Expense By Primary Category": "Chi phí theo danh mục chính",
|
||||
"Expense By Secondary Category": "Chi phí theo danh mục phụ",
|
||||
|
||||
@@ -1830,6 +1830,9 @@
|
||||
"Total Outflows": "总流出",
|
||||
"Total Inflows": "总流入",
|
||||
"Total Balance": "总结余",
|
||||
"Total Transactions": "总交易数",
|
||||
"Opening Balance": "期初余额",
|
||||
"Closing Balance": "期末余额",
|
||||
"Expense By Account": "账户支出",
|
||||
"Expense By Primary Category": "一级分类支出",
|
||||
"Expense By Secondary Category": "二级分类支出",
|
||||
|
||||
@@ -1830,6 +1830,9 @@
|
||||
"Total Outflows": "總流出",
|
||||
"Total Inflows": "總流入",
|
||||
"Total Balance": "總結餘",
|
||||
"Total Transactions": "總交易數",
|
||||
"Opening Balance": "期初餘額",
|
||||
"Closing Balance": "期末餘額",
|
||||
"Expense By Account": "帳戶支出",
|
||||
"Expense By Primary Category": "一級分類支出",
|
||||
"Expense By Secondary Category": "二級分類支出",
|
||||
|
||||
@@ -667,6 +667,8 @@ export interface TransactionReconciliationStatementResponseItem extends Transact
|
||||
|
||||
export interface TransactionReconciliationStatementResponse {
|
||||
readonly transactions: TransactionReconciliationStatementResponseItem[];
|
||||
readonly openingBalance: number;
|
||||
readonly closingBalance: number;
|
||||
}
|
||||
|
||||
export interface TransactionPageWrapper {
|
||||
|
||||
@@ -34,6 +34,8 @@ export function useReconciliationStatementPageBase() {
|
||||
const startTime = ref<number>(0);
|
||||
const endTime = ref<number>(0);
|
||||
const reconciliationStatements = ref<TransactionReconciliationStatementResponseItem[]>([]);
|
||||
const openingBalance = ref<number>(0);
|
||||
const closingBalance = ref<number>(0);
|
||||
|
||||
const currentTimezoneOffsetMinutes = computed<number>(() => getTimezoneOffsetMinutes(settingsStore.appSettings.timeZone));
|
||||
const defaultCurrency = computed<string>(() => userStore.currentUserDefaultCurrency);
|
||||
@@ -41,15 +43,17 @@ export function useReconciliationStatementPageBase() {
|
||||
const allAccountsMap = computed<Record<string, Account>>(() => accountsStore.allAccountsMap);
|
||||
const allCategoriesMap = computed<Record<string, TransactionCategory>>(() => transactionCategoriesStore.allTransactionCategoriesMap);
|
||||
|
||||
const displayStartDateTime = computed<string>(() => {
|
||||
return formatUnixTimeToLongDateTime(startTime.value);
|
||||
const accountCurrency = computed<string>(() => {
|
||||
let currency = defaultCurrency.value;
|
||||
|
||||
if (allAccountsMap.value[accountId.value]) {
|
||||
currency = allAccountsMap.value[accountId.value].currency;
|
||||
}
|
||||
|
||||
return currency;
|
||||
});
|
||||
|
||||
const displayEndDateTime = computed<string>(() => {
|
||||
return formatUnixTimeToLongDateTime(endTime.value);
|
||||
});
|
||||
|
||||
const displayTotalOutflows = computed<string>(() => {
|
||||
const totalOutflows = computed<number>(() => {
|
||||
let totalOutflows = 0;
|
||||
|
||||
for (let i = 0; i < reconciliationStatements.value.length; i++) {
|
||||
@@ -62,16 +66,10 @@ export function useReconciliationStatementPageBase() {
|
||||
}
|
||||
}
|
||||
|
||||
let currency = defaultCurrency.value;
|
||||
|
||||
if (allAccountsMap.value[accountId.value]) {
|
||||
currency = allAccountsMap.value[accountId.value].currency;
|
||||
}
|
||||
|
||||
return formatAmountWithCurrency(totalOutflows, currency);
|
||||
return totalOutflows;
|
||||
});
|
||||
|
||||
const displayTotalInflows = computed<string>(() => {
|
||||
const totalInflows = computed<number>(() => {
|
||||
let totalInflows = 0;
|
||||
|
||||
for (let i = 0; i < reconciliationStatements.value.length; i++) {
|
||||
@@ -84,13 +82,55 @@ export function useReconciliationStatementPageBase() {
|
||||
}
|
||||
}
|
||||
|
||||
let currency = defaultCurrency.value;
|
||||
return totalInflows;
|
||||
});
|
||||
|
||||
const displayStartDateTime = computed<string>(() => {
|
||||
return formatUnixTimeToLongDateTime(startTime.value);
|
||||
});
|
||||
|
||||
const displayEndDateTime = computed<string>(() => {
|
||||
return formatUnixTimeToLongDateTime(endTime.value);
|
||||
});
|
||||
|
||||
const displayTotalOutflows = computed<string>(() => {
|
||||
return formatAmountWithCurrency(totalOutflows.value, accountCurrency.value);
|
||||
});
|
||||
|
||||
const displayTotalInflows = computed<string>(() => {
|
||||
return formatAmountWithCurrency(totalInflows.value, accountCurrency.value);
|
||||
});
|
||||
|
||||
const displayTotalBalance = computed<string>(() => {
|
||||
return formatAmountWithCurrency(totalInflows.value - totalOutflows.value, accountCurrency.value);
|
||||
});
|
||||
|
||||
const displayOpeningBalance = computed<string>(() => {
|
||||
let isLiabilityAccount = false;
|
||||
|
||||
if (allAccountsMap.value[accountId.value]) {
|
||||
currency = allAccountsMap.value[accountId.value].currency;
|
||||
isLiabilityAccount = allAccountsMap.value[accountId.value].isLiability;
|
||||
}
|
||||
|
||||
return formatAmountWithCurrency(totalInflows, currency);
|
||||
if (isLiabilityAccount) {
|
||||
return formatAmountWithCurrency(-openingBalance.value, accountCurrency.value);
|
||||
} else {
|
||||
return formatAmountWithCurrency(openingBalance.value, accountCurrency.value);
|
||||
}
|
||||
});
|
||||
|
||||
const displayClosingBalance = computed<string>(() => {
|
||||
let isLiabilityAccount = false;
|
||||
|
||||
if (allAccountsMap.value[accountId.value]) {
|
||||
isLiabilityAccount = allAccountsMap.value[accountId.value].isLiability;
|
||||
}
|
||||
|
||||
if (isLiabilityAccount) {
|
||||
return formatAmountWithCurrency(-closingBalance.value, accountCurrency.value);
|
||||
} else {
|
||||
return formatAmountWithCurrency(closingBalance.value, accountCurrency.value);
|
||||
}
|
||||
});
|
||||
|
||||
function getDisplayDateTime(transaction: TransactionReconciliationStatementResponseItem): string {
|
||||
@@ -149,6 +189,8 @@ export function useReconciliationStatementPageBase() {
|
||||
startTime,
|
||||
endTime,
|
||||
reconciliationStatements,
|
||||
openingBalance,
|
||||
closingBalance,
|
||||
// computed states
|
||||
currentTimezoneOffsetMinutes,
|
||||
defaultCurrency,
|
||||
@@ -158,6 +200,9 @@ export function useReconciliationStatementPageBase() {
|
||||
displayEndDateTime,
|
||||
displayTotalOutflows,
|
||||
displayTotalInflows,
|
||||
displayTotalBalance,
|
||||
displayOpeningBalance,
|
||||
displayClosingBalance,
|
||||
// functions
|
||||
getDisplayDateTime,
|
||||
getDisplayTimezone,
|
||||
|
||||
@@ -9,14 +9,61 @@
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #subtitle>
|
||||
<div class="text-body-1 text-center text-wrap mt-2">
|
||||
<div class="text-body-1 text-center text-wrap mt-2" v-if="!startTime && !endTime">
|
||||
<span>{{ tt('All') }}</span>
|
||||
</div>
|
||||
<div class="text-body-1 text-center text-wrap mt-2" v-if="startTime || endTime">
|
||||
<span>{{ displayStartDateTime }}</span>
|
||||
<span> - </span>
|
||||
<span>{{ displayEndDateTime }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="d-flex align-center" :class="{'mb-4': !loading}">
|
||||
<div class="d-flex align-center text-body-1">
|
||||
<span class="ml-2">{{ tt('Opening Balance') }}</span>
|
||||
<span class="text-primary" v-if="loading">
|
||||
<v-skeleton-loader type="text" style="width: 80px" :loading="true"></v-skeleton-loader>
|
||||
</span>
|
||||
<span class="text-primary ml-2" v-else-if="!loading">
|
||||
{{ displayOpeningBalance }}
|
||||
</span>
|
||||
<span class="ml-3">{{ tt('Closing Balance') }}</span>
|
||||
<span class="text-primary" v-if="loading">
|
||||
<v-skeleton-loader type="text" style="width: 80px" :loading="true"></v-skeleton-loader>
|
||||
</span>
|
||||
<span class="text-primary ml-2" v-else-if="!loading">
|
||||
{{ displayClosingBalance }}
|
||||
</span>
|
||||
</div>
|
||||
<v-spacer/>
|
||||
<div class="d-flex align-center text-body-1">
|
||||
<span class="ml-2">{{ tt('Total Inflows') }}</span>
|
||||
<span class="text-income" v-if="loading">
|
||||
<v-skeleton-loader type="text" style="width: 80px" :loading="true"></v-skeleton-loader>
|
||||
</span>
|
||||
<span class="text-income ml-2" v-else-if="!loading">
|
||||
{{ displayTotalInflows }}
|
||||
</span>
|
||||
<span class="ml-3">{{ tt('Total Outflows') }}</span>
|
||||
<span class="text-expense" v-if="loading">
|
||||
<v-skeleton-loader type="text" style="width: 80px" :loading="true"></v-skeleton-loader>
|
||||
</span>
|
||||
<span class="text-expense ml-2" v-else-if="!loading">
|
||||
{{ displayTotalOutflows }}
|
||||
</span>
|
||||
<span class="ml-3">{{ tt('Total Balance') }}</span>
|
||||
<span class="text-primary" v-if="loading">
|
||||
<v-skeleton-loader type="text" style="width: 80px" :loading="true"></v-skeleton-loader>
|
||||
</span>
|
||||
<span class="text-primary ml-2" v-else-if="!loading">
|
||||
{{ displayTotalBalance }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<v-data-table
|
||||
fixed-header
|
||||
fixed-footer
|
||||
@@ -72,20 +119,13 @@
|
||||
<span>{{ getDisplayAccountBalance(item) }}</span>
|
||||
</template>
|
||||
<template #bottom>
|
||||
<div class="title-and-toolbar d-flex align-center text-no-wrap mt-2">
|
||||
<span class="ml-2">{{ tt('Total Inflows') }}</span>
|
||||
<span class="text-income" v-if="loading">
|
||||
<div class="title-and-toolbar d-flex align-center text-no-wrap mt-2" v-if="loading || reconciliationStatements.length">
|
||||
<span class="ml-2">{{ tt('Total Transactions') }}</span>
|
||||
<span v-if="loading">
|
||||
<v-skeleton-loader type="text" style="width: 80px" :loading="true"></v-skeleton-loader>
|
||||
</span>
|
||||
<span class="text-income ml-2" v-else-if="!loading">
|
||||
{{ displayTotalInflows }}
|
||||
</span>
|
||||
<span class="ml-3">{{ tt('Total Outflows') }}</span>
|
||||
<span class="text-expense" v-if="loading">
|
||||
<v-skeleton-loader type="text" style="width: 80px" :loading="true"></v-skeleton-loader>
|
||||
</span>
|
||||
<span class="text-expense ml-2" v-else-if="!loading">
|
||||
{{ displayTotalOutflows }}
|
||||
<span class="ml-2" v-else-if="!loading">
|
||||
{{ reconciliationStatements.length }}
|
||||
</span>
|
||||
<v-spacer/>
|
||||
<span v-if="reconciliationStatements && reconciliationStatements.length > 10">
|
||||
@@ -153,6 +193,8 @@ const {
|
||||
startTime,
|
||||
endTime,
|
||||
reconciliationStatements,
|
||||
openingBalance,
|
||||
closingBalance,
|
||||
currentTimezoneOffsetMinutes,
|
||||
allAccountsMap,
|
||||
allCategoriesMap,
|
||||
@@ -160,6 +202,9 @@ const {
|
||||
displayEndDateTime,
|
||||
displayTotalOutflows,
|
||||
displayTotalInflows,
|
||||
displayTotalBalance,
|
||||
displayOpeningBalance,
|
||||
displayClosingBalance,
|
||||
getDisplayDateTime,
|
||||
getDisplayTimezone,
|
||||
getDisplaySourceAmount,
|
||||
@@ -255,6 +300,8 @@ function open(options: { accountId: string, startTime: number, endTime: number }
|
||||
});
|
||||
}).then(result => {
|
||||
reconciliationStatements.value = result.transactions;
|
||||
openingBalance.value = result.openingBalance;
|
||||
closingBalance.value = result.closingBalance;
|
||||
loading.value = false;
|
||||
}).catch(error => {
|
||||
loading.value = false;
|
||||
|
||||
Reference in New Issue
Block a user