From a26397131d629e214a493c75e64b88e08ad6704d Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sat, 21 Dec 2024 23:15:14 +0800 Subject: [PATCH] check whether the billing cycle is chosen when set custom date range or backward/forward the date range --- src/lib/datetime.js | 38 ++++++++++++++++++--- src/views/desktop/transactions/ListPage.vue | 13 ++++--- src/views/mobile/transactions/ListPage.vue | 11 ++++-- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/lib/datetime.js b/src/lib/datetime.js index 1f43fb0d..a417531d 100644 --- a/src/lib/datetime.js +++ b/src/lib/datetime.js @@ -488,11 +488,22 @@ export function getShiftedDateRangeAndDateType(minTime, maxTime, scale, firstDay }; } -export function getShiftedDateRangeAndDateTypeForBillingCycle(dateType, scale, firstDayOfWeek, statementDate) { - if (dateType === dateTimeConstants.allDateRanges.PreviousBillingCycle.type && scale === 1) { - return getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.CurrentBillingCycle.type, firstDayOfWeek, statementDate); - } else if (dateType === dateTimeConstants.allDateRanges.CurrentBillingCycle.type && scale === -1) { - return getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.PreviousBillingCycle.type, firstDayOfWeek, statementDate); +export function getShiftedDateRangeAndDateTypeForBillingCycle(minTime, maxTime, scale, firstDayOfWeek, scene, statementDate) { + if (!dateTimeConstants.allDateRanges.PreviousBillingCycle.availableScenes[scene] || !dateTimeConstants.allDateRanges.CurrentBillingCycle.availableScenes[scene]) { + return; + } + + const previousBillingCycleRange = getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.PreviousBillingCycle.type, firstDayOfWeek, statementDate); + const currentBillingCycleRange = getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.CurrentBillingCycle.type, firstDayOfWeek, statementDate); + + if (previousBillingCycleRange && getUnixTimeBeforeUnixTime(previousBillingCycleRange.maxTime, 1, 'months') === maxTime && getUnixTimeBeforeUnixTime(previousBillingCycleRange.minTime, 1, 'months') === minTime && scale === 1) { + return previousBillingCycleRange; + } else if (previousBillingCycleRange && previousBillingCycleRange.maxTime === maxTime && previousBillingCycleRange.minTime === minTime && scale === 1) { + return currentBillingCycleRange; + } else if (currentBillingCycleRange && currentBillingCycleRange.maxTime === maxTime && currentBillingCycleRange.minTime === minTime && scale === -1) { + return previousBillingCycleRange; + } else if (currentBillingCycleRange && getUnixTimeAfterUnixTime(currentBillingCycleRange.maxTime, 1, 'months') === maxTime && getUnixTimeAfterUnixTime(currentBillingCycleRange.minTime, 1, 'months') === minTime && scale === -1) { + return currentBillingCycleRange; } return null; @@ -523,6 +534,23 @@ export function getDateTypeByDateRange(minTime, maxTime, firstDayOfWeek, scene) return newDateType; } +export function getDateTypeByBillingCycleDateRange(minTime, maxTime, firstDayOfWeek, scene, statementDate) { + if (!dateTimeConstants.allDateRanges.PreviousBillingCycle.availableScenes[scene] || !dateTimeConstants.allDateRanges.CurrentBillingCycle.availableScenes[scene]) { + return; + } + + const previousBillingCycleRange = getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.PreviousBillingCycle.type, firstDayOfWeek, statementDate); + const currentBillingCycleRange = getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.CurrentBillingCycle.type, firstDayOfWeek, statementDate); + + if (previousBillingCycleRange && previousBillingCycleRange.maxTime === maxTime && previousBillingCycleRange.minTime === minTime) { + return previousBillingCycleRange.dateType; + } else if (currentBillingCycleRange && currentBillingCycleRange.maxTime === maxTime && currentBillingCycleRange.minTime === minTime) { + return currentBillingCycleRange.dateType; + } + + return null; +} + export function getDateRangeByDateType(dateType, firstDayOfWeek) { let maxTime = 0; let minTime = 0; diff --git a/src/views/desktop/transactions/ListPage.vue b/src/views/desktop/transactions/ListPage.vue index 579d3d43..2b767b74 100644 --- a/src/views/desktop/transactions/ListPage.vue +++ b/src/views/desktop/transactions/ListPage.vue @@ -617,8 +617,9 @@ import { getShiftedDateRangeAndDateType, getShiftedDateRangeAndDateTypeForBillingCycle, getDateTypeByDateRange, - getDateRangeByBillingCycleDateType, + getDateTypeByBillingCycleDateRange, getDateRangeByDateType, + getDateRangeByBillingCycleDateType, getRecentDateRangeType, isDateRangeMatchOneMonth } from '@/lib/datetime.js'; @@ -1213,8 +1214,8 @@ export default { let newDateRange = null; - if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType]) { - newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(this.query.dateType, scale, this.firstDayOfWeek, this.accountsStore.getAccountStatementDate(this.query.accountIds)); + if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType] || this.query.dateType === this.allDateRanges.Custom.type) { + newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(startTime, endTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds)); } if (!newDateRange) { @@ -1279,7 +1280,11 @@ export default { return; } - const dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal); + let dateType = getDateTypeByBillingCycleDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds)); + + if (!dateType) { + dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal); + } if (this.query.dateType === dateType && this.query.maxTime === maxTime && this.query.minTime === minTime) { this.showCustomDateRangeDialog = false; diff --git a/src/views/mobile/transactions/ListPage.vue b/src/views/mobile/transactions/ListPage.vue index e3de161c..f352b293 100644 --- a/src/views/mobile/transactions/ListPage.vue +++ b/src/views/mobile/transactions/ListPage.vue @@ -542,6 +542,7 @@ import { getShiftedDateRangeAndDateType, getShiftedDateRangeAndDateTypeForBillingCycle, getDateTypeByDateRange, + getDateTypeByBillingCycleDateRange, getDateRangeByDateType, getDateRangeByBillingCycleDateType } from '@/lib/datetime.js'; @@ -909,7 +910,11 @@ export default { return; } - const dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal); + let dateType = getDateTypeByBillingCycleDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds)); + + if (!dateType) { + dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal); + } const changed = this.transactionsStore.updateTransactionListFilter({ dateType: dateType, @@ -1117,8 +1122,8 @@ export default { let newDateRange = null; - if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType]) { - newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(this.query.dateType, scale, this.firstDayOfWeek, this.accountsStore.getAccountStatementDate(this.query.accountIds)); + if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType] || this.query.dateType === this.allDateRanges.Custom.type) { + newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(minTime, maxTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds)); } if (!newDateRange) {