mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 00:34:28 +08:00
code refactor
This commit is contained in:
@@ -8,12 +8,30 @@ const allChartTypes = {
|
|||||||
const defaultChartType = allChartTypes.Pie;
|
const defaultChartType = allChartTypes.Pie;
|
||||||
|
|
||||||
const allChartDataTypes = {
|
const allChartDataTypes = {
|
||||||
ExpenseByAccount: 0,
|
ExpenseByAccount: {
|
||||||
ExpenseByPrimaryCategory: 1,
|
type: 0,
|
||||||
ExpenseBySecondaryCategory: 2,
|
name: 'Expense By Account'
|
||||||
IncomeByAccount: 3,
|
},
|
||||||
IncomeByPrimaryCategory: 4,
|
ExpenseByPrimaryCategory: {
|
||||||
IncomeBySecondaryCategory: 5
|
type: 1,
|
||||||
|
name: 'Expense By Primary Category'
|
||||||
|
},
|
||||||
|
ExpenseBySecondaryCategory: {
|
||||||
|
type: 2,
|
||||||
|
name: 'Expense By Secondary Category'
|
||||||
|
},
|
||||||
|
IncomeByAccount: {
|
||||||
|
type: 3,
|
||||||
|
name: 'Income By Account'
|
||||||
|
},
|
||||||
|
IncomeByPrimaryCategory: {
|
||||||
|
type: 4,
|
||||||
|
name: 'Income By Primary Category'
|
||||||
|
},
|
||||||
|
IncomeBySecondaryCategory: {
|
||||||
|
type: 5,
|
||||||
|
name: 'Income By Secondary Category'
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultChartDataType = allChartDataTypes.ExpenseByPrimaryCategory;
|
const defaultChartDataType = allChartDataTypes.ExpenseByPrimaryCategory;
|
||||||
|
|||||||
@@ -43,32 +43,7 @@
|
|||||||
export default {
|
export default {
|
||||||
computed: {
|
computed: {
|
||||||
allChartDataTypes() {
|
allChartDataTypes() {
|
||||||
return [
|
return this.$constants.statistics.allChartDataTypes;
|
||||||
{
|
|
||||||
type: this.$constants.statistics.allChartDataTypes.ExpenseByAccount,
|
|
||||||
name: 'Expense By Account'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: this.$constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory,
|
|
||||||
name: 'Expense By Primary Category'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: this.$constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory,
|
|
||||||
name: 'Expense By Secondary Category'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: this.$constants.statistics.allChartDataTypes.IncomeByAccount,
|
|
||||||
name: 'Income By Account'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: this.$constants.statistics.allChartDataTypes.IncomeByPrimaryCategory,
|
|
||||||
name: 'Income By Primary Category'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: this.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory,
|
|
||||||
name: 'Income By Secondary Category'
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
},
|
||||||
allDateRanges() {
|
allDateRanges() {
|
||||||
const allDateRanges = [];
|
const allDateRanges = [];
|
||||||
|
|||||||
@@ -53,8 +53,8 @@
|
|||||||
v-else-if="!loading"
|
v-else-if="!loading"
|
||||||
@click="clickPieChartItem"
|
@click="clickPieChartItem"
|
||||||
>
|
>
|
||||||
<text class="statistics-pie-chart-total-amount-title" v-if="statisticsData.items && statisticsData.items.length && (query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseByAccount || query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory || query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory)">{{ $t('Total Expense') }}</text>
|
<text class="statistics-pie-chart-total-amount-title" v-if="statisticsData.items && statisticsData.items.length && (query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseByAccount.type || query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory.type || query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory.type)">{{ $t('Total Expense') }}</text>
|
||||||
<text class="statistics-pie-chart-total-amount-title" v-if="statisticsData.items && statisticsData.items.length && (query.chartDataType === $constants.statistics.allChartDataTypes.IncomeByAccount || query.chartDataType === $constants.statistics.allChartDataTypes.IncomeByPrimaryCategory || query.chartDataType === $constants.statistics.allChartDataTypes.IncomeBySecondaryCategory)">{{ $t('Total Income') }}</text>
|
<text class="statistics-pie-chart-total-amount-title" v-if="statisticsData.items && statisticsData.items.length && (query.chartDataType === $constants.statistics.allChartDataTypes.IncomeByAccount.type || query.chartDataType === $constants.statistics.allChartDataTypes.IncomeByPrimaryCategory.type || query.chartDataType === $constants.statistics.allChartDataTypes.IncomeBySecondaryCategory.type)">{{ $t('Total Income') }}</text>
|
||||||
<text class="statistics-pie-chart-total-amount-value" v-if="statisticsData.items && statisticsData.items.length">
|
<text class="statistics-pie-chart-total-amount-value" v-if="statisticsData.items && statisticsData.items.length">
|
||||||
{{ statisticsData.totalAmount | currency(defaultCurrency) }}
|
{{ statisticsData.totalAmount | currency(defaultCurrency) }}
|
||||||
</text>
|
</text>
|
||||||
@@ -140,10 +140,10 @@
|
|||||||
</f7-list>
|
</f7-list>
|
||||||
<f7-list v-else-if="!loading && statisticsData && statisticsData.items && statisticsData.items.length">
|
<f7-list v-else-if="!loading && statisticsData && statisticsData.items && statisticsData.items.length">
|
||||||
<f7-list-item class="statistics-list-item-overview">
|
<f7-list-item class="statistics-list-item-overview">
|
||||||
<div slot="header" v-if="query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseByAccount || query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory || query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory">{{ $t('Total Expense') }}</div>
|
<div slot="header" v-if="query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseByAccount.type || query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory.type || query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory.type">{{ $t('Total Expense') }}</div>
|
||||||
<div slot="header" v-if="query.chartDataType === $constants.statistics.allChartDataTypes.IncomeByAccount || query.chartDataType === $constants.statistics.allChartDataTypes.IncomeByPrimaryCategory || query.chartDataType === $constants.statistics.allChartDataTypes.IncomeBySecondaryCategory">{{ $t('Total Income') }}</div>
|
<div slot="header" v-if="query.chartDataType === $constants.statistics.allChartDataTypes.IncomeByAccount.type || query.chartDataType === $constants.statistics.allChartDataTypes.IncomeByPrimaryCategory.type || query.chartDataType === $constants.statistics.allChartDataTypes.IncomeBySecondaryCategory.type">{{ $t('Total Income') }}</div>
|
||||||
<div slot="title"
|
<div slot="title"
|
||||||
:class="{ 'statistics-list-item-overview-amount': true, 'text-color-teal': query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseByAccount || query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory || query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory, 'text-color-red': query.chartDataType === $constants.statistics.allChartDataTypes.IncomeByAccount || query.chartDataType === $constants.statistics.allChartDataTypes.IncomeByPrimaryCategory || query.chartDataType === $constants.statistics.allChartDataTypes.IncomeBySecondaryCategory }">
|
:class="{ 'statistics-list-item-overview-amount': true, 'text-color-teal': query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseByAccount.type || query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory.type || query.chartDataType === $constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory.type, 'text-color-red': query.chartDataType === $constants.statistics.allChartDataTypes.IncomeByAccount.type || query.chartDataType === $constants.statistics.allChartDataTypes.IncomeByPrimaryCategory.type || query.chartDataType === $constants.statistics.allChartDataTypes.IncomeBySecondaryCategory.type }">
|
||||||
{{ statisticsData.totalAmount | currency(defaultCurrency) }}
|
{{ statisticsData.totalAmount | currency(defaultCurrency) }}
|
||||||
</div>
|
</div>
|
||||||
</f7-list-item>
|
</f7-list-item>
|
||||||
@@ -276,32 +276,7 @@ export default {
|
|||||||
return this.$store.state.transactionStatisticsFilter;
|
return this.$store.state.transactionStatisticsFilter;
|
||||||
},
|
},
|
||||||
allChartDataTypes() {
|
allChartDataTypes() {
|
||||||
return [
|
return this.$constants.statistics.allChartDataTypes;
|
||||||
{
|
|
||||||
type: this.$constants.statistics.allChartDataTypes.ExpenseByAccount,
|
|
||||||
name: 'Expense By Account'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: this.$constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory,
|
|
||||||
name: 'Expense By Primary Category'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: this.$constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory,
|
|
||||||
name: 'Expense By Secondary Category'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: this.$constants.statistics.allChartDataTypes.IncomeByAccount,
|
|
||||||
name: 'Income By Account'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: this.$constants.statistics.allChartDataTypes.IncomeByPrimaryCategory,
|
|
||||||
name: 'Income By Primary Category'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: this.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory,
|
|
||||||
name: 'Income By Secondary Category'
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
},
|
||||||
allDateRanges() {
|
allDateRanges() {
|
||||||
return this.$constants.datetime.allDateRanges;
|
return this.$constants.datetime.allDateRanges;
|
||||||
@@ -319,15 +294,15 @@ export default {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByAccount ||
|
if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByAccount.type ||
|
||||||
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory ||
|
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory.type ||
|
||||||
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory) {
|
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory.type) {
|
||||||
if (item.category.type !== self.$constants.category.allCategoryTypes.Expense) {
|
if (item.category.type !== self.$constants.category.allCategoryTypes.Expense) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByAccount ||
|
} else if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByAccount.type ||
|
||||||
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByPrimaryCategory ||
|
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByPrimaryCategory.type ||
|
||||||
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory) {
|
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory.type) {
|
||||||
if (item.category.type !== self.$constants.category.allCategoryTypes.Income) {
|
if (item.category.type !== self.$constants.category.allCategoryTypes.Income) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -335,8 +310,8 @@ export default {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByAccount ||
|
if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByAccount.type ||
|
||||||
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByAccount) {
|
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByAccount.type) {
|
||||||
if (self.$utilities.isNumber(item.amountInDefaultCurrency)) {
|
if (self.$utilities.isNumber(item.amountInDefaultCurrency)) {
|
||||||
let data = combinedData[item.account.id];
|
let data = combinedData[item.account.id];
|
||||||
|
|
||||||
@@ -357,8 +332,8 @@ export default {
|
|||||||
allAmount += item.amountInDefaultCurrency;
|
allAmount += item.amountInDefaultCurrency;
|
||||||
combinedData[item.account.id] = data;
|
combinedData[item.account.id] = data;
|
||||||
}
|
}
|
||||||
} else if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory ||
|
} else if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory.type ||
|
||||||
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByPrimaryCategory) {
|
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeByPrimaryCategory.type) {
|
||||||
if (self.$utilities.isNumber(item.amountInDefaultCurrency)) {
|
if (self.$utilities.isNumber(item.amountInDefaultCurrency)) {
|
||||||
let data = combinedData[item.primaryCategory.id];
|
let data = combinedData[item.primaryCategory.id];
|
||||||
|
|
||||||
@@ -379,8 +354,8 @@ export default {
|
|||||||
allAmount += item.amountInDefaultCurrency;
|
allAmount += item.amountInDefaultCurrency;
|
||||||
combinedData[item.primaryCategory.id] = data;
|
combinedData[item.primaryCategory.id] = data;
|
||||||
}
|
}
|
||||||
} else if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory ||
|
} else if (self.query.chartDataType === self.$constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory.type ||
|
||||||
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory) {
|
self.query.chartDataType === self.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory.type) {
|
||||||
if (self.$utilities.isNumber(item.amountInDefaultCurrency)) {
|
if (self.$utilities.isNumber(item.amountInDefaultCurrency)) {
|
||||||
let data = combinedData[item.category.id];
|
let data = combinedData[item.category.id];
|
||||||
|
|
||||||
@@ -439,7 +414,7 @@ export default {
|
|||||||
|
|
||||||
let defaultChartDataType = self.$settings.getStatisticsDefaultChartDataType();
|
let defaultChartDataType = self.$settings.getStatisticsDefaultChartDataType();
|
||||||
|
|
||||||
if (defaultChartDataType < self.$constants.statistics.allChartDataTypes.ExpenseByAccount || defaultChartDataType > self.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory) {
|
if (defaultChartDataType < self.$constants.statistics.allChartDataTypes.ExpenseByAccount.type || defaultChartDataType > self.$constants.statistics.allChartDataTypes.IncomeBySecondaryCategory.type) {
|
||||||
defaultChartDataType = self.$constants.statistics.defaultChartDataType;
|
defaultChartDataType = self.$constants.statistics.defaultChartDataType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -637,26 +612,30 @@ export default {
|
|||||||
},
|
},
|
||||||
filters: {
|
filters: {
|
||||||
chartDataTypeName(dataType, allChartDataTypes) {
|
chartDataTypeName(dataType, allChartDataTypes) {
|
||||||
for (let i = 0; i < allChartDataTypes.length; i++) {
|
for (let chartDataTypeField in allChartDataTypes) {
|
||||||
if (allChartDataTypes[i].type === dataType) {
|
if (!Object.prototype.hasOwnProperty.call(allChartDataTypes, chartDataTypeField)) {
|
||||||
return allChartDataTypes[i].name;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allChartDataTypes[chartDataTypeField].type === dataType) {
|
||||||
|
return allChartDataTypes[chartDataTypeField].name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'Statistics';
|
return 'Statistics';
|
||||||
},
|
},
|
||||||
itemLinkUrl(item, query, allChartDataTypes) {
|
itemLinkUrl(item, query, allChartDataTypes) {
|
||||||
const querys = [];
|
const querys = [];
|
||||||
|
|
||||||
if (query.chartDataType === allChartDataTypes.IncomeByAccount || query.chartDataType === allChartDataTypes.IncomeByPrimaryCategory || query.chartDataType === allChartDataTypes.IncomeBySecondaryCategory) {
|
if (query.chartDataType === allChartDataTypes.IncomeByAccount.type || query.chartDataType === allChartDataTypes.IncomeByPrimaryCategory.type || query.chartDataType === allChartDataTypes.IncomeBySecondaryCategory.type) {
|
||||||
querys.push('type=2');
|
querys.push('type=2');
|
||||||
} else if (query.chartDataType === allChartDataTypes.ExpenseByAccount || query.chartDataType === allChartDataTypes.ExpenseByPrimaryCategory || query.chartDataType === allChartDataTypes.ExpenseBySecondaryCategory) {
|
} else if (query.chartDataType === allChartDataTypes.ExpenseByAccount.type || query.chartDataType === allChartDataTypes.ExpenseByPrimaryCategory.type || query.chartDataType === allChartDataTypes.ExpenseBySecondaryCategory.type) {
|
||||||
querys.push('type=3');
|
querys.push('type=3');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.chartDataType === allChartDataTypes.IncomeByAccount || query.chartDataType === allChartDataTypes.ExpenseByAccount) {
|
if (query.chartDataType === allChartDataTypes.IncomeByAccount.type || query.chartDataType === allChartDataTypes.ExpenseByAccount.type) {
|
||||||
querys.push('accountId=' + item.id);
|
querys.push('accountId=' + item.id);
|
||||||
} else if (query.chartDataType === allChartDataTypes.IncomeByPrimaryCategory || query.chartDataType === allChartDataTypes.IncomeBySecondaryCategory || query.chartDataType === allChartDataTypes.ExpenseByPrimaryCategory || query.chartDataType === allChartDataTypes.ExpenseBySecondaryCategory) {
|
} 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('categoryId=' + item.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user