mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 17:54:30 +08:00
show exchange rate in transaction edit page when the currencies of source account and destination account are different
This commit is contained in:
@@ -126,3 +126,27 @@ export function getDisplayExchangeRateAmount(rateStr, isEnableThousandsSeparator
|
|||||||
return appendThousandsSeparator(trimmedRateStr, isEnableThousandsSeparator);
|
return appendThousandsSeparator(trimmedRateStr, isEnableThousandsSeparator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getAdaptiveDisplayAmountRate(amount1, amount2, fromExchangeRate, toExchangeRate, isEnableThousandsSeparator) {
|
||||||
|
if (!amount1 || !amount2 || amount1 === amount2) {
|
||||||
|
if (!fromExchangeRate || !fromExchangeRate.rate || !toExchangeRate || !toExchangeRate.rate) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
amount1 = fromExchangeRate.rate;
|
||||||
|
amount2 = toExchangeRate.rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
amount1 = parseFloat(amount1);
|
||||||
|
amount2 = parseFloat(amount2);
|
||||||
|
|
||||||
|
if (amount1 > amount2) {
|
||||||
|
const rateStr = (amount1 / amount2).toString();
|
||||||
|
const displayRateStr = getDisplayExchangeRateAmount(rateStr, isEnableThousandsSeparator);
|
||||||
|
return `${displayRateStr} : 1`;
|
||||||
|
} else {
|
||||||
|
const rateStr = (amount2 / amount1).toString();
|
||||||
|
const displayRateStr = getDisplayExchangeRateAmount(rateStr, isEnableThousandsSeparator);
|
||||||
|
return `1 : ${displayRateStr}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
:disabled="loading || submitting"
|
:disabled="loading || submitting"
|
||||||
:persistent-placeholder="true"
|
:persistent-placeholder="true"
|
||||||
:hide="transaction.hideAmount"
|
:hide="transaction.hideAmount"
|
||||||
:label="$t('Transfer In Amount')"
|
:label="transferInAmountTitle"
|
||||||
:placeholder="$t('Transfer In Amount')"
|
:placeholder="$t('Transfer In Amount')"
|
||||||
v-model="transaction.destinationAmount"/>
|
v-model="transaction.destinationAmount"/>
|
||||||
</v-col>
|
</v-col>
|
||||||
@@ -325,6 +325,9 @@ import {
|
|||||||
getTimezoneOffsetMinutes,
|
getTimezoneOffsetMinutes,
|
||||||
getCurrentUnixTime
|
getCurrentUnixTime
|
||||||
} from '@/lib/datetime.js';
|
} from '@/lib/datetime.js';
|
||||||
|
import {
|
||||||
|
getAdaptiveDisplayAmountRate
|
||||||
|
} from '@/lib/currency.js';
|
||||||
import {
|
import {
|
||||||
getFirstAvailableCategoryId
|
getFirstAvailableCategoryId
|
||||||
} from '@/lib/category.js';
|
} from '@/lib/category.js';
|
||||||
@@ -417,6 +420,24 @@ export default {
|
|||||||
return 'Account';
|
return 'Account';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
transferInAmountTitle() {
|
||||||
|
const sourceAccount = this.allAccountsMap[this.transaction.sourceAccountId];
|
||||||
|
const destinationAccount = this.allAccountsMap[this.transaction.destinationAccountId];
|
||||||
|
|
||||||
|
if (!sourceAccount || !destinationAccount || sourceAccount.currency === destinationAccount.currency) {
|
||||||
|
return this.$t('Transfer In Amount');
|
||||||
|
}
|
||||||
|
|
||||||
|
const fromExchangeRate = this.exchangeRatesStore.latestExchangeRateMap[sourceAccount.currency];
|
||||||
|
const toExchangeRate = this.exchangeRatesStore.latestExchangeRateMap[destinationAccount.currency];
|
||||||
|
const amountRate = getAdaptiveDisplayAmountRate(this.transaction.sourceAmount, this.transaction.destinationAmount, fromExchangeRate, toExchangeRate, this.settingsStore.appSettings.thousandsSeparator);
|
||||||
|
|
||||||
|
if (!amountRate) {
|
||||||
|
return this.$t('Transfer In Amount');
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.$t('Transfer In Amount') + ` (${amountRate})`;
|
||||||
|
},
|
||||||
defaultCurrency() {
|
defaultCurrency() {
|
||||||
return this.userStore.currentUserDefaultCurrency;
|
return this.userStore.currentUserDefaultCurrency;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -66,7 +66,7 @@
|
|||||||
class="transaction-edit-amount text-color-primary"
|
class="transaction-edit-amount text-color-primary"
|
||||||
link="#" no-chevron
|
link="#" no-chevron
|
||||||
:class="destinationAmountClass"
|
:class="destinationAmountClass"
|
||||||
:header="$t('Transfer In Amount')"
|
:header="transferInAmountTitle"
|
||||||
:title="getDisplayAmount(transaction.destinationAmount, transaction.hideAmount)"
|
:title="getDisplayAmount(transaction.destinationAmount, transaction.hideAmount)"
|
||||||
@click="showDestinationAmountSheet = true"
|
@click="showDestinationAmountSheet = true"
|
||||||
v-if="transaction.type === allTransactionTypes.Transfer"
|
v-if="transaction.type === allTransactionTypes.Transfer"
|
||||||
@@ -358,6 +358,9 @@ import {
|
|||||||
getUtcOffsetByUtcOffsetMinutes,
|
getUtcOffsetByUtcOffsetMinutes,
|
||||||
getActualUnixTimeForStore
|
getActualUnixTimeForStore
|
||||||
} from '@/lib/datetime.js';
|
} from '@/lib/datetime.js';
|
||||||
|
import {
|
||||||
|
getAdaptiveDisplayAmountRate
|
||||||
|
} from '@/lib/currency.js';
|
||||||
import {
|
import {
|
||||||
getTransactionPrimaryCategoryName,
|
getTransactionPrimaryCategoryName,
|
||||||
getTransactionSecondaryCategoryName,
|
getTransactionSecondaryCategoryName,
|
||||||
@@ -435,6 +438,24 @@ export default {
|
|||||||
return 'Account';
|
return 'Account';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
transferInAmountTitle() {
|
||||||
|
const sourceAccount = this.allAccountsMap[this.transaction.sourceAccountId];
|
||||||
|
const destinationAccount = this.allAccountsMap[this.transaction.destinationAccountId];
|
||||||
|
|
||||||
|
if (!sourceAccount || !destinationAccount || sourceAccount.currency === destinationAccount.currency) {
|
||||||
|
return this.$t('Transfer In Amount');
|
||||||
|
}
|
||||||
|
|
||||||
|
const fromExchangeRate = this.exchangeRatesStore.latestExchangeRateMap[sourceAccount.currency];
|
||||||
|
const toExchangeRate = this.exchangeRatesStore.latestExchangeRateMap[destinationAccount.currency];
|
||||||
|
const amountRate = getAdaptiveDisplayAmountRate(this.transaction.sourceAmount, this.transaction.destinationAmount, fromExchangeRate, toExchangeRate, this.settingsStore.appSettings.thousandsSeparator);
|
||||||
|
|
||||||
|
if (!amountRate) {
|
||||||
|
return this.$t('Transfer In Amount');
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.$t('Transfer In Amount') + ` (${amountRate})`;
|
||||||
|
},
|
||||||
defaultCurrency() {
|
defaultCurrency() {
|
||||||
return this.userStore.currentUserDefaultCurrency;
|
return this.userStore.currentUserDefaultCurrency;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user