WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit a263971

Browse files
committed
check whether the billing cycle is chosen when set custom date range or backward/forward the date range
1 parent 7659e8f commit a263971

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

src/lib/datetime.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,22 @@ export function getShiftedDateRangeAndDateType(minTime, maxTime, scale, firstDay
488488
};
489489
}
490490

491-
export function getShiftedDateRangeAndDateTypeForBillingCycle(dateType, scale, firstDayOfWeek, statementDate) {
492-
if (dateType === dateTimeConstants.allDateRanges.PreviousBillingCycle.type && scale === 1) {
493-
return getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.CurrentBillingCycle.type, firstDayOfWeek, statementDate);
494-
} else if (dateType === dateTimeConstants.allDateRanges.CurrentBillingCycle.type && scale === -1) {
495-
return getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.PreviousBillingCycle.type, firstDayOfWeek, statementDate);
491+
export function getShiftedDateRangeAndDateTypeForBillingCycle(minTime, maxTime, scale, firstDayOfWeek, scene, statementDate) {
492+
if (!dateTimeConstants.allDateRanges.PreviousBillingCycle.availableScenes[scene] || !dateTimeConstants.allDateRanges.CurrentBillingCycle.availableScenes[scene]) {
493+
return;
494+
}
495+
496+
const previousBillingCycleRange = getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.PreviousBillingCycle.type, firstDayOfWeek, statementDate);
497+
const currentBillingCycleRange = getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.CurrentBillingCycle.type, firstDayOfWeek, statementDate);
498+
499+
if (previousBillingCycleRange && getUnixTimeBeforeUnixTime(previousBillingCycleRange.maxTime, 1, 'months') === maxTime && getUnixTimeBeforeUnixTime(previousBillingCycleRange.minTime, 1, 'months') === minTime && scale === 1) {
500+
return previousBillingCycleRange;
501+
} else if (previousBillingCycleRange && previousBillingCycleRange.maxTime === maxTime && previousBillingCycleRange.minTime === minTime && scale === 1) {
502+
return currentBillingCycleRange;
503+
} else if (currentBillingCycleRange && currentBillingCycleRange.maxTime === maxTime && currentBillingCycleRange.minTime === minTime && scale === -1) {
504+
return previousBillingCycleRange;
505+
} else if (currentBillingCycleRange && getUnixTimeAfterUnixTime(currentBillingCycleRange.maxTime, 1, 'months') === maxTime && getUnixTimeAfterUnixTime(currentBillingCycleRange.minTime, 1, 'months') === minTime && scale === -1) {
506+
return currentBillingCycleRange;
496507
}
497508

498509
return null;
@@ -523,6 +534,23 @@ export function getDateTypeByDateRange(minTime, maxTime, firstDayOfWeek, scene)
523534
return newDateType;
524535
}
525536

537+
export function getDateTypeByBillingCycleDateRange(minTime, maxTime, firstDayOfWeek, scene, statementDate) {
538+
if (!dateTimeConstants.allDateRanges.PreviousBillingCycle.availableScenes[scene] || !dateTimeConstants.allDateRanges.CurrentBillingCycle.availableScenes[scene]) {
539+
return;
540+
}
541+
542+
const previousBillingCycleRange = getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.PreviousBillingCycle.type, firstDayOfWeek, statementDate);
543+
const currentBillingCycleRange = getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.CurrentBillingCycle.type, firstDayOfWeek, statementDate);
544+
545+
if (previousBillingCycleRange && previousBillingCycleRange.maxTime === maxTime && previousBillingCycleRange.minTime === minTime) {
546+
return previousBillingCycleRange.dateType;
547+
} else if (currentBillingCycleRange && currentBillingCycleRange.maxTime === maxTime && currentBillingCycleRange.minTime === minTime) {
548+
return currentBillingCycleRange.dateType;
549+
}
550+
551+
return null;
552+
}
553+
526554
export function getDateRangeByDateType(dateType, firstDayOfWeek) {
527555
let maxTime = 0;
528556
let minTime = 0;

src/views/desktop/transactions/ListPage.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,9 @@ import {
617617
getShiftedDateRangeAndDateType,
618618
getShiftedDateRangeAndDateTypeForBillingCycle,
619619
getDateTypeByDateRange,
620-
getDateRangeByBillingCycleDateType,
620+
getDateTypeByBillingCycleDateRange,
621621
getDateRangeByDateType,
622+
getDateRangeByBillingCycleDateType,
622623
getRecentDateRangeType,
623624
isDateRangeMatchOneMonth
624625
} from '@/lib/datetime.js';
@@ -1213,8 +1214,8 @@ export default {
12131214
12141215
let newDateRange = null;
12151216
1216-
if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType]) {
1217-
newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(this.query.dateType, scale, this.firstDayOfWeek, this.accountsStore.getAccountStatementDate(this.query.accountIds));
1217+
if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType] || this.query.dateType === this.allDateRanges.Custom.type) {
1218+
newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(startTime, endTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds));
12181219
}
12191220
12201221
if (!newDateRange) {
@@ -1279,7 +1280,11 @@ export default {
12791280
return;
12801281
}
12811282
1282-
const dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
1283+
let dateType = getDateTypeByBillingCycleDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds));
1284+
1285+
if (!dateType) {
1286+
dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
1287+
}
12831288
12841289
if (this.query.dateType === dateType && this.query.maxTime === maxTime && this.query.minTime === minTime) {
12851290
this.showCustomDateRangeDialog = false;

src/views/mobile/transactions/ListPage.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ import {
542542
getShiftedDateRangeAndDateType,
543543
getShiftedDateRangeAndDateTypeForBillingCycle,
544544
getDateTypeByDateRange,
545+
getDateTypeByBillingCycleDateRange,
545546
getDateRangeByDateType,
546547
getDateRangeByBillingCycleDateType
547548
} from '@/lib/datetime.js';
@@ -909,7 +910,11 @@ export default {
909910
return;
910911
}
911912
912-
const dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
913+
let dateType = getDateTypeByBillingCycleDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds));
914+
915+
if (!dateType) {
916+
dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
917+
}
913918
914919
const changed = this.transactionsStore.updateTransactionListFilter({
915920
dateType: dateType,
@@ -1117,8 +1122,8 @@ export default {
11171122
11181123
let newDateRange = null;
11191124
1120-
if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType]) {
1121-
newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(this.query.dateType, scale, this.firstDayOfWeek, this.accountsStore.getAccountStatementDate(this.query.accountIds));
1125+
if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType] || this.query.dateType === this.allDateRanges.Custom.type) {
1126+
newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(minTime, maxTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds));
11221127
}
11231128
11241129
if (!newDateRange) {

0 commit comments

Comments
 (0)