mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-15 23:47:33 +08:00
show amount in default currency in transaction edit page / dialog when account currency is not default currency
This commit is contained in:
@@ -26,6 +26,10 @@ import {
|
||||
isArray
|
||||
} from '@/lib/common.ts';
|
||||
|
||||
import {
|
||||
getExchangedAmountByRate
|
||||
} from '@/lib/numeral.ts';
|
||||
|
||||
import {
|
||||
getUtcOffsetByUtcOffsetMinutes,
|
||||
getTimezoneOffsetMinutes,
|
||||
@@ -165,6 +169,33 @@ export function useTransactionEditPageBase(type: TransactionEditPageType, initMo
|
||||
}
|
||||
});
|
||||
|
||||
const sourceAmountTitle = computed<string>(() => {
|
||||
const sourceAccount = allAccountsMap.value[transaction.value.sourceAccountId];
|
||||
const amountName = tt(sourceAmountName.value);
|
||||
|
||||
if (!sourceAccount || sourceAccount.currency === defaultCurrency.value || !transaction.value.sourceAmount || transaction.value.hideAmount) {
|
||||
return amountName;
|
||||
}
|
||||
|
||||
const fromExchangeRate = exchangeRatesStore.latestExchangeRateMap[sourceAccount.currency];
|
||||
const toExchangeRate = exchangeRatesStore.latestExchangeRateMap[defaultCurrency.value];
|
||||
|
||||
if (!fromExchangeRate || !fromExchangeRate.rate || !toExchangeRate || !toExchangeRate.rate) {
|
||||
return amountName;
|
||||
}
|
||||
|
||||
let amountInDefaultCurrency = getExchangedAmountByRate(transaction.value.sourceAmount, fromExchangeRate.rate, toExchangeRate.rate);
|
||||
|
||||
if (!amountInDefaultCurrency) {
|
||||
return amountName;
|
||||
}
|
||||
|
||||
amountInDefaultCurrency = Math.floor(amountInDefaultCurrency);
|
||||
|
||||
const displayAmountInDefaultCurrency = getDisplayAmount(amountInDefaultCurrency, transaction.value.hideAmount, defaultCurrency.value);
|
||||
return amountName + ` (${displayAmountInDefaultCurrency})`;
|
||||
});
|
||||
|
||||
const sourceAccountTitle = computed<string>(() => {
|
||||
if (transaction.value.type === TransactionType.Expense || transaction.value.type === TransactionType.Income) {
|
||||
return 'Account';
|
||||
@@ -404,6 +435,7 @@ export function useTransactionEditPageBase(type: TransactionEditPageType, initMo
|
||||
saveButtonTitle,
|
||||
cancelButtonTitle,
|
||||
sourceAmountName,
|
||||
sourceAmountTitle,
|
||||
sourceAccountTitle,
|
||||
transferInAmountTitle,
|
||||
sourceAccountName,
|
||||
|
||||
Reference in New Issue
Block a user