- {{ $t('Total Expense') }}
- {{ $t('Total Income') }}
+
+ {{ query.chartDataType | totalAmountName(allChartDataTypes) | localized }}
+
{{ statisticsData.totalAmount | currency(defaultCurrency) }}
@@ -170,7 +173,7 @@
- {{ item.totalAmount | currency(defaultCurrency) }}
+ {{ item.totalAmount | currency(item.currency || defaultCurrency) }}
@@ -184,13 +187,13 @@
-
+
-
+
{{ dateRangeName(query) }}
-
+
@@ -283,111 +286,32 @@ export default {
},
statisticsData() {
const self = this;
- const combinedData = {};
+ let combinedData = {
+ items: [],
+ totalAmount: 0
+ };
- let allAmount = 0;
-
- for (let i = 0; i < self.$store.state.transactionStatistics.items.length; i++) {
- const item = self.$store.state.transactionStatistics.items[i];
-
- if (!item.primaryAccount || !item.account || !item.primaryCategory || !item.category) {
- continue;
- }
-
- if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByAccount.type ||
- self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory.type ||
- self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory.type) {
- if (item.category.type !== self.$constants.category.allCategoryTypes.Expense) {
- continue;
- }
- } else if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByAccount.type ||
- self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByPrimaryCategory.type ||
- self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory.type) {
- if (item.category.type !== self.$constants.category.allCategoryTypes.Income) {
- continue;
- }
- } else {
- continue;
- }
-
- if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByAccount.type ||
- self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByAccount.type) {
- if (self.$utilities.isNumber(item.amountInDefaultCurrency)) {
- let data = combinedData[item.account.id];
-
- if (data) {
- data.totalAmount += item.amountInDefaultCurrency;
- } else {
- data = {
- name: item.account.name,
- type: 'account',
- id: item.account.id,
- icon: item.account.icon || self.$constants.icons.defaultAccountIcon.icon,
- color: item.account.color || self.$constants.colors.defaultAccountColor,
- hidden: item.primaryAccount.hidden || item.account.hidden,
- totalAmount: item.amountInDefaultCurrency
- }
- }
-
- allAmount += item.amountInDefaultCurrency;
- combinedData[item.account.id] = data;
- }
- } else if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory.type ||
- self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByPrimaryCategory.type) {
- if (self.$utilities.isNumber(item.amountInDefaultCurrency)) {
- let data = combinedData[item.primaryCategory.id];
-
- if (data) {
- data.totalAmount += item.amountInDefaultCurrency;
- } else {
- data = {
- name: item.primaryCategory.name,
- type: 'category',
- id: item.primaryCategory.id,
- icon: item.primaryCategory.icon || self.$constants.icons.defaultCategoryIcon.icon,
- color: item.primaryCategory.color || self.$constants.colors.defaultCategoryColor,
- hidden: item.primaryCategory.hidden,
- totalAmount: item.amountInDefaultCurrency
- }
- }
-
- allAmount += item.amountInDefaultCurrency;
- combinedData[item.primaryCategory.id] = data;
- }
- } else if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory.type ||
- self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory.type) {
- if (self.$utilities.isNumber(item.amountInDefaultCurrency)) {
- let data = combinedData[item.category.id];
-
- if (data) {
- data.totalAmount += item.amountInDefaultCurrency;
- } else {
- data = {
- name: item.category.name,
- type: 'category',
- id: item.category.id,
- icon: item.category.icon || self.$constants.icons.defaultCategoryIcon.icon,
- color: item.category.color || self.$constants.colors.defaultCategoryColor,
- hidden: item.primaryCategory.hidden || item.category.hidden,
- totalAmount: item.amountInDefaultCurrency
- }
- }
-
- allAmount += item.amountInDefaultCurrency;
- combinedData[item.category.id] = data;
- }
- }
+ if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByAccount.type ||
+ self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory.type ||
+ self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory.type ||
+ self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByAccount.type ||
+ self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByPrimaryCategory.type ||
+ self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory.type) {
+ combinedData = this.getDataItemsByTransactions(self.$store.state.transactionStatistics);
+ } else if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.AccountTotalAssets.type ||
+ self.query.chartDataType === self.$constants.statistics.allChartDataTypes.AccountTotalLiabilities.type) {
+ combinedData = this.getDataItemsByAccounts(self.$store.getters.allPlainAccounts);
}
const allStatisticsItems = [];
- for (let id in combinedData) {
- if (!Object.prototype.hasOwnProperty.call(combinedData, id)) {
+ for (let id in combinedData.items) {
+ if (!Object.prototype.hasOwnProperty.call(combinedData.items, id)) {
continue;
}
- const data = combinedData[id];
- data.percent = data.totalAmount * 100 / allAmount;
+ const data = combinedData.items[id];
+ data.percent = data.totalAmount * 100 / combinedData.totalAmount;
allStatisticsItems.push(data);
}
@@ -397,7 +321,7 @@ export default {
});
return {
- totalAmount: allAmount,
+ totalAmount: combinedData.totalAmount,
items: allStatisticsItems
};
}
@@ -414,7 +338,7 @@ export default {
let defaultChartDataType = self.$settings.getStatisticsDefaultChartDataType();
- if (defaultChartDataType < self.$constants.statistics.allChartDataTypes.ExpenseByAccount.type || defaultChartDataType > self.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory.type) {
+ if (defaultChartDataType < self.$constants.statistics.allChartDataTypes.ExpenseByAccount.type || defaultChartDataType > self.$constants.statistics.allChartDataTypes.AccountTotalLiabilities.type) {
defaultChartDataType = self.$constants.statistics.defaultChartDataType;
}
@@ -558,6 +482,11 @@ export default {
this.reload(null);
},
dateRangeName(query) {
+ if (query.chartDataType === this.$constants.statistics.allChartDataTypes.AccountTotalAssets.type ||
+ query.chartDataType === this.$constants.statistics.allChartDataTypes.AccountTotalLiabilities.type) {
+ return this.$t(this.allDateRanges.All.name);
+ }
+
if (query.dateType === this.allDateRanges.All.type) {
return this.$t(this.allDateRanges.All.name);
}
@@ -608,6 +537,163 @@ export default {
},
settings() {
this.$f7router.navigate('/statistic/settings');
+ },
+ getDataItemsByTransactions(transactionStatistics) {
+ const allDataItems = {};
+ let allAmount = 0;
+
+ for (let i = 0; i < transactionStatistics.items.length; i++) {
+ const item = transactionStatistics.items[i];
+
+ if (!item.primaryAccount || !item.account || !item.primaryCategory || !item.category) {
+ continue;
+ }
+
+ if (this.query.chartDataType === this.$constants.statistics.allChartDataTypes.ExpenseByAccount.type ||
+ this.query.chartDataType === this.$constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory.type ||
+ this.query.chartDataType === this.$constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory.type) {
+ if (item.category.type !== this.$constants.category.allCategoryTypes.Expense) {
+ continue;
+ }
+ } else if (this.query.chartDataType === this.$constants.statistics.allChartDataTypes.IncomeByAccount.type ||
+ this.query.chartDataType === this.$constants.statistics.allChartDataTypes.IncomeByPrimaryCategory.type ||
+ this.query.chartDataType === this.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory.type) {
+ if (item.category.type !== this.$constants.category.allCategoryTypes.Income) {
+ continue;
+ }
+ } else {
+ continue;
+ }
+
+ if (this.query.chartDataType === this.$constants.statistics.allChartDataTypes.ExpenseByAccount.type ||
+ this.query.chartDataType === this.$constants.statistics.allChartDataTypes.IncomeByAccount.type) {
+ if (this.$utilities.isNumber(item.amountInDefaultCurrency)) {
+ let data = allDataItems[item.account.id];
+
+ if (data) {
+ data.totalAmount += item.amountInDefaultCurrency;
+ } else {
+ data = {
+ name: item.account.name,
+ type: 'account',
+ id: item.account.id,
+ icon: item.account.icon || this.$constants.icons.defaultAccountIcon.icon,
+ color: item.account.color || this.$constants.colors.defaultAccountColor,
+ hidden: item.primaryAccount.hidden || item.account.hidden,
+ totalAmount: item.amountInDefaultCurrency
+ }
+ }
+
+ allAmount += item.amountInDefaultCurrency;
+ allDataItems[item.account.id] = data;
+ }
+ } else if (this.query.chartDataType === this.$constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory.type ||
+ this.query.chartDataType === this.$constants.statistics.allChartDataTypes.IncomeByPrimaryCategory.type) {
+ if (this.$utilities.isNumber(item.amountInDefaultCurrency)) {
+ let data = allDataItems[item.primaryCategory.id];
+
+ if (data) {
+ data.totalAmount += item.amountInDefaultCurrency;
+ } else {
+ data = {
+ name: item.primaryCategory.name,
+ type: 'category',
+ id: item.primaryCategory.id,
+ icon: item.primaryCategory.icon || this.$constants.icons.defaultCategoryIcon.icon,
+ color: item.primaryCategory.color || this.$constants.colors.defaultCategoryColor,
+ hidden: item.primaryCategory.hidden,
+ totalAmount: item.amountInDefaultCurrency
+ }
+ }
+
+ allAmount += item.amountInDefaultCurrency;
+ allDataItems[item.primaryCategory.id] = data;
+ }
+ } else if (this.query.chartDataType === this.$constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory.type ||
+ this.query.chartDataType === this.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory.type) {
+ if (this.$utilities.isNumber(item.amountInDefaultCurrency)) {
+ let data = allDataItems[item.category.id];
+
+ if (data) {
+ data.totalAmount += item.amountInDefaultCurrency;
+ } else {
+ data = {
+ name: item.category.name,
+ type: 'category',
+ id: item.category.id,
+ icon: item.category.icon || this.$constants.icons.defaultCategoryIcon.icon,
+ color: item.category.color || this.$constants.colors.defaultCategoryColor,
+ hidden: item.primaryCategory.hidden || item.category.hidden,
+ totalAmount: item.amountInDefaultCurrency
+ }
+ }
+
+ allAmount += item.amountInDefaultCurrency;
+ allDataItems[item.category.id] = data;
+ }
+ }
+ }
+
+ return {
+ totalAmount: allAmount,
+ items: allDataItems
+ }
+ },
+ getDataItemsByAccounts(accounts) {
+ const allDataItems = {};
+ let allAmount = 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;
+ }
+ }
+
+ 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,
+ totalAmount: amount
+ };
+
+ allAmount += amount;
+ allDataItems[account.id] = data;
+ }
+
+ return {
+ totalAmount: allAmount,
+ items: allDataItems
+ }
}
},
filters: {
@@ -621,9 +707,22 @@ export default {
return allChartDataTypes[chartDataTypeField].name;
}
}
-
+
return 'Statistics';
},
+ totalAmountName(dataType, allChartDataTypes) {
+ if (dataType === allChartDataTypes.IncomeByAccount.type || dataType === allChartDataTypes.IncomeByPrimaryCategory.type || dataType === allChartDataTypes.IncomeBySecondaryCategory.type) {
+ return 'Total Income';
+ } else if (dataType === allChartDataTypes.ExpenseByAccount.type || dataType === allChartDataTypes.ExpenseByPrimaryCategory.type || dataType === allChartDataTypes.ExpenseBySecondaryCategory.type) {
+ return 'Total Expense';
+ } else if (dataType === allChartDataTypes.AccountTotalAssets.type) {
+ return 'Total Assets';
+ } else if (dataType === allChartDataTypes.AccountTotalLiabilities.type) {
+ return 'Total Liabilities';
+ }
+
+ return 'Total Amount';
+ },
itemLinkUrl(item, query, allChartDataTypes) {
const querys = [];
@@ -633,15 +732,17 @@ export default {
querys.push('type=3');
}
- if (query.chartDataType === allChartDataTypes.IncomeByAccount.type || query.chartDataType === allChartDataTypes.ExpenseByAccount.type) {
+ if (query.chartDataType === allChartDataTypes.IncomeByAccount.type || query.chartDataType === allChartDataTypes.ExpenseByAccount.type || query.chartDataType === allChartDataTypes.AccountTotalAssets.type || query.chartDataType === allChartDataTypes.AccountTotalLiabilities.type) {
querys.push('accountId=' + item.id);
} else if (query.chartDataType === allChartDataTypes.IncomeByPrimaryCategory.type || query.chartDataType === allChartDataTypes.IncomeBySecondaryCategory.type || query.chartDataType === allChartDataTypes.ExpenseByPrimaryCategory.type || query.chartDataType === allChartDataTypes.ExpenseBySecondaryCategory.type) {
querys.push('categoryId=' + item.id);
}
- querys.push('dateType=' + query.dateType);
- querys.push('minTime=' + query.startTime);
- querys.push('maxTime=' + query.endTime);
+ if (query.chartDataType !== allChartDataTypes.AccountTotalAssets.type && query.chartDataType !== allChartDataTypes.AccountTotalLiabilities.type) {
+ querys.push('dateType=' + query.dateType);
+ querys.push('minTime=' + query.startTime);
+ querys.push('maxTime=' + query.endTime);
+ }
return '/transaction/list?' + querys.join('&');
}