mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 16:54:25 +08:00
support plus account balance which account currency does not equal to default currency
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import utils from './utils.js'
|
||||||
|
|
||||||
const exchangeRatesLocalStorageKey = 'lab_exchange_rates';
|
const exchangeRatesLocalStorageKey = 'lab_exchange_rates';
|
||||||
|
|
||||||
function getExchangeRates() {
|
function getExchangeRates() {
|
||||||
@@ -14,8 +16,39 @@ function clearExchangeRates() {
|
|||||||
localStorage.removeItem(exchangeRatesLocalStorageKey);
|
localStorage.removeItem(exchangeRatesLocalStorageKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getExchangeRate(fromCurrency, toCurrency) {
|
||||||
|
const exchangeRates = getExchangeRates().exchangeRates;
|
||||||
|
const exchangeRateMap = {};
|
||||||
|
|
||||||
|
for (let i = 0; i < exchangeRates.length; i++) {
|
||||||
|
const exchangeRate = exchangeRates[i];
|
||||||
|
exchangeRateMap[exchangeRate.currency] = exchangeRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fromCurrencyExchangeRate = exchangeRateMap[fromCurrency];
|
||||||
|
const toCurrencyExchangeRate = exchangeRateMap[toCurrency];
|
||||||
|
|
||||||
|
if (!fromCurrencyExchangeRate || !toCurrencyExchangeRate) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseFloat(toCurrencyExchangeRate.rate) / parseFloat(fromCurrencyExchangeRate.rate);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOtherCurrencyAmount(amount, fromCurrency, toCurrency) {
|
||||||
|
const exchangeRate = getExchangeRate(fromCurrency, toCurrency);
|
||||||
|
|
||||||
|
if (!utils.isNumber(exchangeRate)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount * exchangeRate;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getExchangeRates,
|
getExchangeRates,
|
||||||
setExchangeRates,
|
setExchangeRates,
|
||||||
clearExchangeRates,
|
clearExchangeRates,
|
||||||
|
getExchangeRate,
|
||||||
|
getOtherCurrencyAmount,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -188,17 +188,28 @@ export default {
|
|||||||
|
|
||||||
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, () => true);
|
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, () => true);
|
||||||
let netAssets = 0;
|
let netAssets = 0;
|
||||||
|
let hasUnCalculatedAmount = false;
|
||||||
|
|
||||||
for (let i = 0; i < accountsBalance.length; i++) {
|
for (let i = 0; i < accountsBalance.length; i++) {
|
||||||
if (accountsBalance[i].currency === this.defaultCurrency) {
|
if (accountsBalance[i].currency === this.defaultCurrency) {
|
||||||
netAssets += accountsBalance[i].balance;
|
netAssets += accountsBalance[i].balance;
|
||||||
} else {
|
} else {
|
||||||
// TODO: calculate exchange rate
|
const balance = this.$exchangeRates.getOtherCurrencyAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
||||||
netAssets += accountsBalance[i].balance;
|
|
||||||
|
if (!this.$utilities.isNumber(balance)) {
|
||||||
|
hasUnCalculatedAmount = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
netAssets += Math.floor(balance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return netAssets;
|
if (hasUnCalculatedAmount) {
|
||||||
|
return netAssets + '+';
|
||||||
|
} else {
|
||||||
|
return netAssets;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
totalAssets() {
|
totalAssets() {
|
||||||
if (!this.showAccountBalance) {
|
if (!this.showAccountBalance) {
|
||||||
@@ -207,17 +218,28 @@ export default {
|
|||||||
|
|
||||||
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, category => category.isAsset);
|
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, category => category.isAsset);
|
||||||
let totalAssets = 0;
|
let totalAssets = 0;
|
||||||
|
let hasUnCalculatedAmount = false;
|
||||||
|
|
||||||
for (let i = 0; i < accountsBalance.length; i++) {
|
for (let i = 0; i < accountsBalance.length; i++) {
|
||||||
if (accountsBalance[i].currency === this.defaultCurrency) {
|
if (accountsBalance[i].currency === this.defaultCurrency) {
|
||||||
totalAssets += accountsBalance[i].balance;
|
totalAssets += accountsBalance[i].balance;
|
||||||
} else {
|
} else {
|
||||||
// TODO: calculate exchange rate
|
const balance = this.$exchangeRates.getOtherCurrencyAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
||||||
totalAssets += accountsBalance[i].balance;
|
|
||||||
|
if (!this.$utilities.isNumber(balance)) {
|
||||||
|
hasUnCalculatedAmount = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalAssets += Math.floor(balance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return totalAssets;
|
if (hasUnCalculatedAmount) {
|
||||||
|
return totalAssets + '+';
|
||||||
|
} else {
|
||||||
|
return totalAssets;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
totalLiabilities() {
|
totalLiabilities() {
|
||||||
if (!this.showAccountBalance) {
|
if (!this.showAccountBalance) {
|
||||||
@@ -226,17 +248,28 @@ export default {
|
|||||||
|
|
||||||
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, category => category.isLiability);
|
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, category => category.isLiability);
|
||||||
let totalLiabilities = 0;
|
let totalLiabilities = 0;
|
||||||
|
let hasUnCalculatedAmount = false;
|
||||||
|
|
||||||
for (let i = 0; i < accountsBalance.length; i++) {
|
for (let i = 0; i < accountsBalance.length; i++) {
|
||||||
if (accountsBalance[i].currency === this.defaultCurrency) {
|
if (accountsBalance[i].currency === this.defaultCurrency) {
|
||||||
totalLiabilities += accountsBalance[i].balance;
|
totalLiabilities += accountsBalance[i].balance;
|
||||||
} else {
|
} else {
|
||||||
// TODO: calculate exchange rate
|
const balance = this.$exchangeRates.getOtherCurrencyAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
||||||
totalLiabilities += accountsBalance[i].balance;
|
|
||||||
|
if (!this.$utilities.isNumber(balance)) {
|
||||||
|
hasUnCalculatedAmount = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalLiabilities += Math.floor(balance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return totalLiabilities;
|
if (hasUnCalculatedAmount) {
|
||||||
|
return totalLiabilities + '+';
|
||||||
|
} else {
|
||||||
|
return totalLiabilities;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
@@ -333,17 +366,28 @@ export default {
|
|||||||
|
|
||||||
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, category => category.id === accountCategory.id);
|
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, category => category.id === accountCategory.id);
|
||||||
let totalBalance = 0;
|
let totalBalance = 0;
|
||||||
|
let hasUnCalculatedAmount = false;
|
||||||
|
|
||||||
for (let i = 0; i < accountsBalance.length; i++) {
|
for (let i = 0; i < accountsBalance.length; i++) {
|
||||||
if (accountsBalance[i].currency === this.defaultCurrency) {
|
if (accountsBalance[i].currency === this.defaultCurrency) {
|
||||||
totalBalance += accountsBalance[i].balance;
|
totalBalance += accountsBalance[i].balance;
|
||||||
} else {
|
} else {
|
||||||
// TODO: calculate exchange rate
|
const balance = this.$exchangeRates.getOtherCurrencyAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
||||||
totalBalance += accountsBalance[i].balance;
|
|
||||||
|
if (!this.$utilities.isNumber(balance)) {
|
||||||
|
hasUnCalculatedAmount = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalBalance += Math.floor(balance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return totalBalance;
|
if (hasUnCalculatedAmount) {
|
||||||
|
return totalBalance + '+';
|
||||||
|
} else {
|
||||||
|
return totalBalance;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setSortable() {
|
setSortable() {
|
||||||
this.showHidden = true;
|
this.showHidden = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user