mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 01:04:25 +08:00
code refactor
This commit is contained in:
@@ -629,7 +629,6 @@ const allCurrencies = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const allCurrencyDisplayModes = {
|
const allCurrencyDisplayModes = {
|
||||||
None: 0,
|
None: 0,
|
||||||
Symbol: 1,
|
Symbol: 1,
|
||||||
@@ -637,12 +636,14 @@ const allCurrencyDisplayModes = {
|
|||||||
Name: 3
|
Name: 3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const defaultCurrency = allCurrencies.USD.code;
|
||||||
const defaultCurrencyDisplayMode = allCurrencyDisplayModes.Symbol;
|
const defaultCurrencyDisplayMode = allCurrencyDisplayModes.Symbol;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
parentAccountCurrencyPlaceholder: parentAccountCurrencyPlaceholder,
|
parentAccountCurrencyPlaceholder: parentAccountCurrencyPlaceholder,
|
||||||
defaultCurrencySymbol: defaultCurrencySymbol,
|
defaultCurrencySymbol: defaultCurrencySymbol,
|
||||||
all: allCurrencies,
|
all: allCurrencies,
|
||||||
|
defaultCurrency: defaultCurrency,
|
||||||
allCurrencyDisplayModes: allCurrencyDisplayModes,
|
allCurrencyDisplayModes: allCurrencyDisplayModes,
|
||||||
defaultCurrencyDisplayMode: defaultCurrencyDisplayMode
|
defaultCurrencyDisplayMode: defaultCurrencyDisplayMode
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -80,7 +80,10 @@ const allDateRanges = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const defaultFirstDayOfWeek = allWeekDays.Sunday.type;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
allWeekDays: allWeekDays,
|
allWeekDays: allWeekDays,
|
||||||
allDateRanges: allDateRanges,
|
allDateRanges: allDateRanges,
|
||||||
|
defaultFirstDayOfWeek: defaultFirstDayOfWeek
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -209,6 +209,17 @@ Vue.prototype.$locale = {
|
|||||||
moment.locale(locale);
|
moment.locale(locale);
|
||||||
services.setLocale(locale);
|
services.setLocale(locale);
|
||||||
document.querySelector('html').setAttribute('lang', locale);
|
document.querySelector('html').setAttribute('lang', locale);
|
||||||
|
|
||||||
|
const defaultCurrency = i18n.t('default.currency');
|
||||||
|
const defaultFirstDayOfWeekName = i18n.t('default.firstDayOfWeek');
|
||||||
|
let defaultFirstDayOfWeek = datetime.defaultFirstDayOfWeek;
|
||||||
|
|
||||||
|
if (datetime.allWeekDays[defaultFirstDayOfWeekName]) {
|
||||||
|
defaultFirstDayOfWeek = datetime.allWeekDays[defaultFirstDayOfWeekName].type;
|
||||||
|
}
|
||||||
|
|
||||||
|
store.dispatch('updateLocalizedDefaultSettings', { defaultCurrency, defaultFirstDayOfWeek });
|
||||||
|
|
||||||
return locale;
|
return locale;
|
||||||
},
|
},
|
||||||
getTimezone: function () {
|
getTimezone: function () {
|
||||||
|
|||||||
+21
-1
@@ -1,4 +1,5 @@
|
|||||||
import datetimeConstants from '../consts/datetime.js';
|
import datetimeConstants from '../consts/datetime.js';
|
||||||
|
import currencyConstants from '../consts/currency.js';
|
||||||
import statisticsConstants from '../consts/statistics.js';
|
import statisticsConstants from '../consts/statistics.js';
|
||||||
import userState from '../lib/userstate.js';
|
import userState from '../lib/userstate.js';
|
||||||
import settings from '../lib/settings.js';
|
import settings from '../lib/settings.js';
|
||||||
@@ -7,6 +8,8 @@ import utils from '../lib/utils.js';
|
|||||||
import {
|
import {
|
||||||
RESET_STATE,
|
RESET_STATE,
|
||||||
|
|
||||||
|
UPDATE_DEFAULT_SETTING,
|
||||||
|
|
||||||
STORE_USER_INFO,
|
STORE_USER_INFO,
|
||||||
CLEAR_USER_INFO,
|
CLEAR_USER_INFO,
|
||||||
|
|
||||||
@@ -53,6 +56,10 @@ import {
|
|||||||
UPDATE_TRANSACTION_STATISTICS_INVALID_STATE,
|
UPDATE_TRANSACTION_STATISTICS_INVALID_STATE,
|
||||||
} from './mutations.js';
|
} from './mutations.js';
|
||||||
|
|
||||||
|
import {
|
||||||
|
updateLocalizedDefaultSettings
|
||||||
|
} from './setting.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
authorize,
|
authorize,
|
||||||
authorize2FA,
|
authorize2FA,
|
||||||
@@ -100,7 +107,8 @@ import {
|
|||||||
loadTransactionStatistics,
|
loadTransactionStatistics,
|
||||||
initTransactionStatisticsFilter,
|
initTransactionStatisticsFilter,
|
||||||
updateTransactionStatisticsFilter,
|
updateTransactionStatisticsFilter,
|
||||||
statisticsItemsByTransactionStatisticsData
|
statisticsItemsByTransactionStatisticsData,
|
||||||
|
statisticsItemsByAccountsData,
|
||||||
} from './statistics.js';
|
} from './statistics.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -154,6 +162,10 @@ import {
|
|||||||
const stores = {
|
const stores = {
|
||||||
strict: !settings.isProduction(),
|
strict: !settings.isProduction(),
|
||||||
state: {
|
state: {
|
||||||
|
defaultSetting: {
|
||||||
|
currency: currencyConstants.defaultCurrency,
|
||||||
|
firstDayOfWeek: datetimeConstants.defaultFirstDayOfWeek
|
||||||
|
},
|
||||||
currentUserInfo: userState.getUserInfo(),
|
currentUserInfo: userState.getUserInfo(),
|
||||||
latestExchangeRates: getExchangeRatesFromLocalStorage(),
|
latestExchangeRates: getExchangeRatesFromLocalStorage(),
|
||||||
allAccounts: [],
|
allAccounts: [],
|
||||||
@@ -204,6 +216,7 @@ const stores = {
|
|||||||
|
|
||||||
// statistics
|
// statistics
|
||||||
statisticsItemsByTransactionStatisticsData,
|
statisticsItemsByTransactionStatisticsData,
|
||||||
|
statisticsItemsByAccountsData,
|
||||||
|
|
||||||
// account
|
// account
|
||||||
allPlainAccounts,
|
allPlainAccounts,
|
||||||
@@ -258,6 +271,10 @@ const stores = {
|
|||||||
|
|
||||||
clearExchangeRatesFromLocalStorage();
|
clearExchangeRatesFromLocalStorage();
|
||||||
},
|
},
|
||||||
|
[UPDATE_DEFAULT_SETTING] (state, { defaultCurrency, defaultFirstDayOfWeek }) {
|
||||||
|
state.defaultSetting.currency = defaultCurrency;
|
||||||
|
state.defaultSetting.firstDayOfWeek = defaultFirstDayOfWeek;
|
||||||
|
},
|
||||||
[STORE_USER_INFO] (state, userInfo) {
|
[STORE_USER_INFO] (state, userInfo) {
|
||||||
state.currentUserInfo = userInfo;
|
state.currentUserInfo = userInfo;
|
||||||
userState.updateUserInfo(userInfo);
|
userState.updateUserInfo(userInfo);
|
||||||
@@ -900,6 +917,9 @@ const stores = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
// setting
|
||||||
|
updateLocalizedDefaultSettings,
|
||||||
|
|
||||||
// user
|
// user
|
||||||
authorize,
|
authorize,
|
||||||
authorize2FA,
|
authorize2FA,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
export const RESET_STATE = 'RESET_STATE';
|
export const RESET_STATE = 'RESET_STATE';
|
||||||
|
|
||||||
|
export const UPDATE_DEFAULT_SETTING = 'UPDATE_DEFAULT_SETTING';
|
||||||
|
|
||||||
export const STORE_USER_INFO = 'STORE_USER_INFO';
|
export const STORE_USER_INFO = 'STORE_USER_INFO';
|
||||||
export const CLEAR_USER_INFO = 'CLEAR_USER_INFO';
|
export const CLEAR_USER_INFO = 'CLEAR_USER_INFO';
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import {
|
||||||
|
UPDATE_DEFAULT_SETTING
|
||||||
|
} from './mutations.js';
|
||||||
|
|
||||||
|
export function updateLocalizedDefaultSettings(context, { defaultCurrency, defaultFirstDayOfWeek }) {
|
||||||
|
context.commit(UPDATE_DEFAULT_SETTING, {
|
||||||
|
defaultCurrency,
|
||||||
|
defaultFirstDayOfWeek,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ import services from '../lib/services.js';
|
|||||||
import logger from '../lib/logger.js';
|
import logger from '../lib/logger.js';
|
||||||
import utils from '../lib/utils.js';
|
import utils from '../lib/utils.js';
|
||||||
|
|
||||||
|
import { getExchangedAmount } from './exchangeRates.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
LOAD_TRANSACTION_STATISTICS,
|
LOAD_TRANSACTION_STATISTICS,
|
||||||
INIT_TRANSACTION_STATISTICS_FILTER,
|
INIT_TRANSACTION_STATISTICS_FILTER,
|
||||||
@@ -191,3 +193,76 @@ export function statisticsItemsByTransactionStatisticsData(state) {
|
|||||||
items: allDataItems
|
items: allDataItems
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function statisticsItemsByAccountsData(state, getters) {
|
||||||
|
if (!getters.allPlainAccounts) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const allDataItems = {};
|
||||||
|
let totalAmount = 0;
|
||||||
|
let totalNonNegativeAmount = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < getters.allPlainAccounts.length; i++) {
|
||||||
|
const account = getters.allPlainAccounts[i];
|
||||||
|
|
||||||
|
if (state.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.AccountTotalAssets.type) {
|
||||||
|
if (!account.isAsset) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (state.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.AccountTotalLiabilities.type) {
|
||||||
|
if (!account.isLiability) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.transactionStatisticsFilter.filterAccountIds && state.transactionStatisticsFilter.filterAccountIds[account.id]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let primaryAccount = state.allAccountsMap[account.parentId];
|
||||||
|
|
||||||
|
if (!primaryAccount) {
|
||||||
|
primaryAccount = account;
|
||||||
|
}
|
||||||
|
|
||||||
|
let amount = account.balance;
|
||||||
|
|
||||||
|
if (account.currency !== getters.currentUserDefaultCurrency) {
|
||||||
|
amount = Math.floor(getExchangedAmount(state)(amount, account.currency, getters.currentUserDefaultCurrency));
|
||||||
|
|
||||||
|
if (!utils.isNumber(amount)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (account.isLiability) {
|
||||||
|
amount = -amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
name: account.name,
|
||||||
|
type: 'account',
|
||||||
|
id: account.id,
|
||||||
|
icon: account.icon || iconConstants.defaultAccountIcon.icon,
|
||||||
|
color: account.color || colorConstants.defaultAccountColor,
|
||||||
|
hidden: primaryAccount.hidden || account.hidden,
|
||||||
|
displayOrders: [primaryAccount.category, primaryAccount.displayOrder, account.displayOrder],
|
||||||
|
totalAmount: amount
|
||||||
|
};
|
||||||
|
|
||||||
|
totalAmount += amount;
|
||||||
|
|
||||||
|
if (amount > 0) {
|
||||||
|
totalNonNegativeAmount += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
allDataItems[account.id] = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
totalAmount: totalAmount,
|
||||||
|
totalNonNegativeAmount: totalNonNegativeAmount,
|
||||||
|
items: allDataItems
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+2
-2
@@ -343,10 +343,10 @@ export function currentUserNickname(state) {
|
|||||||
|
|
||||||
export function currentUserDefaultCurrency(state) {
|
export function currentUserDefaultCurrency(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserInfo || {};
|
||||||
return userInfo.defaultCurrency || null;
|
return userInfo.defaultCurrency || state.defaultSetting.currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function currentUserFirstDayOfWeek(state) {
|
export function currentUserFirstDayOfWeek(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserInfo || {};
|
||||||
return utils.isNumber(userInfo.firstDayOfWeek) ? userInfo.firstDayOfWeek : null;
|
return utils.isNumber(userInfo.firstDayOfWeek) ? userInfo.firstDayOfWeek : state.defaultSetting.firstDayOfWeek;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,14 +263,6 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
defaultCurrency() {
|
defaultCurrency() {
|
||||||
if (this.query.accountId && this.query.accountId !== '0') {
|
|
||||||
const account = this.allAccounts[this.query.accountId];
|
|
||||||
|
|
||||||
if (account && account.currency && account.currency !== this.$constants.currency.parentAccountCurrencyPlaceholder) {
|
|
||||||
return account.currency;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.$store.getters.currentUserDefaultCurrency || this.$t('default.currency');
|
return this.$store.getters.currentUserDefaultCurrency || this.$t('default.currency');
|
||||||
},
|
},
|
||||||
firstDayOfWeek() {
|
firstDayOfWeek() {
|
||||||
@@ -309,7 +301,7 @@ export default {
|
|||||||
combinedData = this.$store.getters.statisticsItemsByTransactionStatisticsData;
|
combinedData = this.$store.getters.statisticsItemsByTransactionStatisticsData;
|
||||||
} else if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.AccountTotalAssets.type ||
|
} else if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.AccountTotalAssets.type ||
|
||||||
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.AccountTotalLiabilities.type) {
|
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.AccountTotalLiabilities.type) {
|
||||||
combinedData = this.getDataItemsByAccounts(self.$store.getters.allPlainAccounts);
|
combinedData = this.$store.getters.statisticsItemsByAccountsData;
|
||||||
}
|
}
|
||||||
|
|
||||||
const allStatisticsItems = [];
|
const allStatisticsItems = [];
|
||||||
@@ -598,74 +590,6 @@ export default {
|
|||||||
settings() {
|
settings() {
|
||||||
this.$f7router.navigate('/statistic/settings');
|
this.$f7router.navigate('/statistic/settings');
|
||||||
},
|
},
|
||||||
getDataItemsByAccounts(accounts) {
|
|
||||||
const allDataItems = {};
|
|
||||||
let totalAmount = 0;
|
|
||||||
let totalNonNegativeAmount = 0;
|
|
||||||
|
|
||||||
for (let i = 0; i < accounts.length; i++) {
|
|
||||||
const account = accounts[i];
|
|
||||||
|
|
||||||
if (this.query.chartDataType === this.$constants.statistics.allChartDataTypes.AccountTotalAssets.type) {
|
|
||||||
if (!account.isAsset) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else if (this.query.chartDataType === this.$constants.statistics.allChartDataTypes.AccountTotalLiabilities.type) {
|
|
||||||
if (!account.isLiability) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.query.filterAccountIds && this.query.filterAccountIds[account.id]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let primaryAccount = this.$store.state.allAccountsMap[account.parentId];
|
|
||||||
|
|
||||||
if (!primaryAccount) {
|
|
||||||
primaryAccount = account;
|
|
||||||
}
|
|
||||||
|
|
||||||
let amount = account.balance;
|
|
||||||
|
|
||||||
if (account.currency !== this.defaultCurrency) {
|
|
||||||
amount = Math.floor(this.$store.getters.getExchangedAmount(amount, account.currency, this.defaultCurrency));
|
|
||||||
|
|
||||||
if (!this.$utilities.isNumber(amount)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (account.isLiability) {
|
|
||||||
amount = -amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = {
|
|
||||||
name: account.name,
|
|
||||||
type: 'account',
|
|
||||||
id: account.id,
|
|
||||||
icon: account.icon || self.$constants.icons.defaultAccountIcon.icon,
|
|
||||||
color: account.color || self.$constants.colors.defaultAccountColor,
|
|
||||||
hidden: primaryAccount.hidden || account.hidden,
|
|
||||||
displayOrders: [primaryAccount.category, primaryAccount.displayOrder, account.displayOrder],
|
|
||||||
totalAmount: amount
|
|
||||||
};
|
|
||||||
|
|
||||||
totalAmount += amount;
|
|
||||||
|
|
||||||
if (amount > 0) {
|
|
||||||
totalNonNegativeAmount += amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
allDataItems[account.id] = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
totalAmount: totalAmount,
|
|
||||||
totalNonNegativeAmount: totalNonNegativeAmount,
|
|
||||||
items: allDataItems
|
|
||||||
}
|
|
||||||
},
|
|
||||||
scrollPopoverToSelectedItem(event) {
|
scrollPopoverToSelectedItem(event) {
|
||||||
if (!event || !event.$el || !event.$el.length) {
|
if (!event || !event.$el || !event.$el.length) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user