add billing cycle date range filter

This commit is contained in:
MaysWind
2024-12-16 23:44:20 +08:00
parent 8fdbb39ee4
commit 647cd3c33f
12 changed files with 226 additions and 23 deletions
@@ -152,6 +152,7 @@ import { useAccountsStore } from '@/stores/account.js';
import { useTransactionsStore } from '@/stores/transaction.js';
import { useStatisticsStore } from '@/stores/statistics.js';
import datetimeConstants from '@/consts/datetime.js';
import accountConstants from '@/consts/account.js';
import { copyObjectTo } from '@/lib/common.js';
import {
@@ -322,9 +323,15 @@ export default {
self.statisticsStore.updateTransactionStatisticsInvalidState(true);
}
} else if (this.type === 'transactionListCurrent') {
changed = self.transactionsStore.updateTransactionListFilter({
const filter = {
accountIds: isAllSelected ? '' : finalAccountIds
});
};
if (datetimeConstants.allBillingCycleDateRangesMap[self.transactionsStore.transactionsFilter.dateType] && !self.accountsStore.getAccountStatementDate(filter.accountIds)) {
filter.dateType = datetimeConstants.allDateRanges.Custom.type;
}
changed = self.transactionsStore.updateTransactionListFilter(filter);
if (changed) {
self.transactionsStore.updateTransactionListInvalidState(true);
+27 -7
View File
@@ -146,7 +146,7 @@
<span class="text-sm ml-3">{{ dateRange.displayName }}</span>
</div>
</v-list-item-title>
<div class="ml-3 smaller" v-if="dateRange.type === allDateRanges.Custom.type && query.dateType === allDateRanges.Custom.type && query.minTime && query.maxTime">
<div class="ml-3 smaller" v-if="((dateRange.isBillingCycle || dateRange.type === allDateRanges.Custom.type) && query.dateType === dateRange.type) && query.minTime && query.maxTime">
<span>{{ queryMinTime }}</span>
<span>&nbsp;-&nbsp;</span>
<br/>
@@ -615,7 +615,9 @@ import {
getBrowserTimezoneOffsetMinutes,
getActualUnixTimeForStore,
getShiftedDateRangeAndDateType,
getShiftedDateRangeAndDateTypeForBillingCycle,
getDateTypeByDateRange,
getDateRangeByBillingCycleDateType,
getDateRangeByDateType,
getRecentDateRangeType,
isDateRangeMatchOneMonth
@@ -743,7 +745,7 @@ export default {
return this.userStore.currentUserFirstDayOfWeek;
},
allDateRangesArray() {
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.Normal, true);
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.Normal, true, !!this.accountsStore.getAccountStatementDate(this.query.accountIds));
},
allDateRanges() {
return datetimeConstants.allDateRanges;
@@ -1115,7 +1117,7 @@ export default {
let dateRange = getDateRangeByDateType(query.dateType ? parseInt(query.dateType) : undefined, this.firstDayOfWeek);
if (!dateRange &&
query.dateType === datetimeConstants.allDateRanges.Custom.type.toString() &&
(datetimeConstants.allBillingCycleDateRangesMap[query.dateType] || query.dateType === datetimeConstants.allDateRanges.Custom.type.toString()) &&
parseInt(query.maxTime) > 0 && parseInt(query.minTime) > 0) {
dateRange = {
dateType: parseInt(query.dateType),
@@ -1209,7 +1211,15 @@ export default {
return;
}
const newDateRange = getShiftedDateRangeAndDateType(startTime, endTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
let newDateRange = null;
if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType]) {
newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(this.query.dateType, scale, this.firstDayOfWeek, this.accountsStore.getAccountStatementDate(this.query.accountIds));
}
if (!newDateRange) {
newDateRange = getShiftedDateRangeAndDateType(startTime, endTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
}
const changed = this.transactionsStore.updateTransactionListFilter({
dateType: newDateRange.dateType,
@@ -1226,7 +1236,11 @@ export default {
},
changeDateFilter(dateRange) {
if (isNumber(dateRange)) {
dateRange = getDateRangeByDateType(dateRange, this.firstDayOfWeek);
if (datetimeConstants.allBillingCycleDateRangesMap[dateRange]) {
dateRange = getDateRangeByBillingCycleDateType(dateRange, this.firstDayOfWeek, this.accountsStore.getAccountStatementDate(this.query.accountIds));
} else {
dateRange = getDateRangeByDateType(dateRange, this.firstDayOfWeek);
}
}
if (dateRange.dateType === datetimeConstants.allDateRanges.Custom.type &&
@@ -1418,9 +1432,15 @@ export default {
return;
}
const changed = this.transactionsStore.updateTransactionListFilter({
const filter = {
accountIds: accountIds
});
};
if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType] && !this.accountsStore.getAccountStatementDate(accountIds)) {
filter.dateType = datetimeConstants.allDateRanges.Custom.type;
}
const changed = this.transactionsStore.updateTransactionListFilter(filter);
if (changed) {
this.loading = true;
@@ -136,6 +136,7 @@ import { useAccountsStore } from '@/stores/account.js';
import { useTransactionsStore } from '@/stores/transaction.js';
import { useStatisticsStore } from '@/stores/statistics.js';
import datetimeConstants from '@/consts/datetime.js';
import accountConstants from '@/consts/account.js';
import { copyObjectTo } from '@/lib/common.js';
import {
@@ -294,9 +295,15 @@ export default {
filterAccountIds: filteredAccountIds
});
} else if (this.type === 'transactionListCurrent') {
const changed = self.transactionsStore.updateTransactionListFilter({
const filter = {
accountIds: isAllSelected ? '' : finalAccountIds
});
};
if (datetimeConstants.allBillingCycleDateRangesMap[self.transactionsStore.transactionsFilter.dateType] && !self.accountsStore.getAccountStatementDate(filter.accountIds)) {
filter.dateType = datetimeConstants.allDateRanges.Custom.type;
}
const changed = self.transactionsStore.updateTransactionListFilter(filter);
if (changed) {
self.transactionsStore.updateTransactionListInvalidState(true);
+30 -8
View File
@@ -270,7 +270,7 @@
<f7-icon class="list-item-checked-icon" f7="checkmark_alt" v-if="query.dateType === dateRange.type"></f7-icon>
</template>
<template #footer>
<div v-if="dateRange.type === allDateRanges.Custom.type && query.dateType === allDateRanges.Custom.type && query.minTime && query.maxTime">
<div v-if="((dateRange.isBillingCycle || dateRange.type === allDateRanges.Custom.type) && query.dateType === dateRange.type) && query.minTime && query.maxTime">
<span>{{ queryMinTime }}</span>
<span>&nbsp;-&nbsp;</span>
<br/>
@@ -540,8 +540,10 @@ import {
getActualUnixTimeForStore,
getYearMonthFirstUnixTime,
getShiftedDateRangeAndDateType,
getShiftedDateRangeAndDateTypeForBillingCycle,
getDateTypeByDateRange,
getDateRangeByDateType
getDateRangeByDateType,
getDateRangeByBillingCycleDateType
} from '@/lib/datetime.js';
import { categoryTypeToTransactionType, transactionTypeToCategoryType } from '@/lib/category.js';
import { getUnifiedSelectedAccountsCurrencyOrDefaultCurrency } from '@/lib/account.js';
@@ -735,7 +737,7 @@ export default {
return datetimeConstants.allDateRanges;
},
allDateRangesArray() {
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.Normal, true);
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.Normal, true, !!this.accountsStore.getAccountStatementDate(this.query.accountIds));
},
showTotalAmountInTransactionListPage() {
return this.settingsStore.appSettings.showTotalAmountInTransactionListPage;
@@ -751,7 +753,7 @@ export default {
let dateRange = getDateRangeByDateType(query.dateType ? parseInt(query.dateType) : undefined, self.firstDayOfWeek);
if (!dateRange &&
query.dateType === self.allDateRanges.Custom.type.toString() &&
(datetimeConstants.allBillingCycleDateRangesMap[query.dateType] || query.dateType === datetimeConstants.allDateRanges.Custom.type.toString()) &&
parseInt(query.maxTime) > 0 && parseInt(query.minTime) > 0) {
dateRange = {
dateType: parseInt(query.dateType),
@@ -878,7 +880,13 @@ export default {
return;
}
const dateRange = getDateRangeByDateType(dateType, this.firstDayOfWeek);
let dateRange = null;
if (datetimeConstants.allBillingCycleDateRangesMap[dateType]) {
dateRange = getDateRangeByBillingCycleDateType(dateType, this.firstDayOfWeek, this.accountsStore.getAccountStatementDate(this.query.accountIds));
} else {
dateRange = getDateRangeByDateType(dateType, this.firstDayOfWeek);
}
if (!dateRange) {
return;
@@ -973,9 +981,15 @@ export default {
return;
}
const changed = this.transactionsStore.updateTransactionListFilter({
const filter = {
accountIds: accountIds
});
};
if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType] && !this.accountsStore.getAccountStatementDate(accountIds)) {
filter.dateType = datetimeConstants.allDateRanges.Custom.type;
}
const changed = this.transactionsStore.updateTransactionListFilter(filter);
this.showAccountPopover = false;
@@ -1107,7 +1121,15 @@ export default {
return;
}
const newDateRange = getShiftedDateRangeAndDateType(minTime, maxTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
let newDateRange = null;
if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType]) {
newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(this.query.dateType, scale, this.firstDayOfWeek, this.accountsStore.getAccountStatementDate(this.query.accountIds));
}
if (!newDateRange) {
newDateRange = getShiftedDateRangeAndDateType(minTime, maxTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
}
const changed = this.transactionsStore.updateTransactionListFilter({
dateType: newDateRange.dateType,