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,
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
:disabled="loading || submitting"
|
||||
:persistent-placeholder="true"
|
||||
:hide="transaction.hideAmount"
|
||||
:label="tt(sourceAmountName)"
|
||||
:label="sourceAmountTitle"
|
||||
:placeholder="tt(sourceAmountName)"
|
||||
:enable-formula="mode !== TransactionEditPageMode.View"
|
||||
v-model="transaction.sourceAmount"/>
|
||||
@@ -583,6 +583,7 @@ const {
|
||||
saveButtonTitle,
|
||||
cancelButtonTitle,
|
||||
sourceAmountName,
|
||||
sourceAmountTitle,
|
||||
sourceAccountTitle,
|
||||
transferInAmountTitle,
|
||||
sourceAccountName,
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
class="transaction-edit-amount"
|
||||
link="#" no-chevron
|
||||
:class="sourceAmountClass"
|
||||
:header="tt(sourceAmountName)"
|
||||
:header="sourceAmountTitle"
|
||||
:title="getDisplayAmount(transaction.sourceAmount, transaction.hideAmount, sourceAccountCurrency)"
|
||||
@click="showSourceAmountSheet = true"
|
||||
>
|
||||
@@ -570,7 +570,7 @@ const {
|
||||
canAddTransactionPicture,
|
||||
title,
|
||||
saveButtonTitle,
|
||||
sourceAmountName,
|
||||
sourceAmountTitle,
|
||||
sourceAccountTitle,
|
||||
transferInAmountTitle,
|
||||
sourceAccountName,
|
||||
|
||||
Reference in New Issue
Block a user