From 4559f1cd3f17b38406fc88592b1119fab3eac9a6 Mon Sep 17 00:00:00 2001 From: JustinMacaulay Date: Wed, 4 Dec 2024 12:19:13 -0800 Subject: [PATCH 1/5] running into some issues caused by new changes to number of days --- .../support-details.component.ts | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts index 60829f362..587cfb6b7 100644 --- a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts +++ b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts @@ -29,7 +29,7 @@ import { AlertService } from 'src/app/shared/components/alert/alert.service'; import { ReferralCreationService } from '../../step-supports/referral-creation.service'; import { DateConversionService } from 'src/app/core/services/utility/dateConversion.service'; import { ComputeRulesService } from 'src/app/core/services/computeRules.service'; -import { firstValueFrom, Subscription } from 'rxjs'; +import {firstValueFrom, from, Subscription} from 'rxjs'; import { LoadEvacueeListService } from '../../../../core/services/load-evacuee-list.service'; import { MatDatepickerInputEvent, @@ -291,11 +291,13 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { this.createSupportDetailsForm(); this.supportDetailsForm.get('noOfDays').valueChanges.subscribe((value) => { + console.log('value', value); this.updateValidToDate(value); }); this.supportDetailsForm.get('fromDate').valueChanges.subscribe((value) => { if (value === null || value === '' || value === undefined) { + console.log('value', value); this.supportDetailsForm.get('noOfDays').patchValue(1); } }); @@ -513,9 +515,17 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { updateToDate(event: MatDatepickerInputEvent) { const days = this.supportDetailsForm.get('noOfDays').value; const currentVal = this.supportDetailsForm.get('fromDate').value; + const fromTime = this.supportDetailsForm.get('fromTime').value + const afterMidnightBeforeSix = this.isTimeBetween(fromTime, "00:00:00", "06:00:00") const date = new Date(currentVal); - const finalValue = this.datePipe.transform(date.setDate(date.getDate() + days), 'MM/dd/yyyy'); - this.supportDetailsForm.get('toDate').patchValue(new Date(finalValue)); + if(afterMidnightBeforeSix){ + let finalValue = this.datePipe.transform(date.setDate(date.getDate() + days -1), 'MM/dd/yyyy'); + this.supportDetailsForm.get('toDate').patchValue(new Date(finalValue)); + }else{ + let finalValue = this.datePipe.transform(date.setDate(date.getDate() + days), 'MM/dd/yyyy'); + this.supportDetailsForm.get('toDate').patchValue(new Date(finalValue)); + } + } /** @@ -525,13 +535,19 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { */ updateNoOfDays(event: MatDatepickerInputEvent) { const fromDate = this.datePipe.transform(this.supportDetailsForm.get('fromDate').value, 'dd-MMM-yyyy'); + const fromTime = this.supportDetailsForm.get('fromTime').value const toDate = this.datePipe.transform(event.value, 'dd-MMM-yyyy'); const dateDiff = new Date(toDate).getTime() - new Date(fromDate).getTime(); - const days = dateDiff / (1000 * 60 * 60 * 24); + let days = dateDiff / (1000 * 60 * 60 * 24); + + const afterMidnightBeforeSix = this.isTimeBetween(fromTime, "00:00:00", "06:00:00") if (days > 30) { this.supportDetailsForm.get('noOfDays').patchValue(null); } else { + if(afterMidnightBeforeSix){ + days = days + 1 + } this.supportDetailsForm.get('noOfDays').patchValue(days); } } @@ -984,4 +1000,21 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { ]); this.supportDetailsForm.get('paperSupportNumber').updateValueAndValidity(); } + + private isTimeBetween(time, from, to) { + // Split the times into hours, minutes, and seconds + const [hours, minutes, seconds] = time.split(':').map(Number); + const [fromHours, fromMinutes, fromSeconds] = from.split(':').map(Number); + const [toHours, toMinutes, toSeconds] = to.split(':').map(Number); + // Create Date objects for both times + const imputTime = new Date(); + imputTime.setHours(hours, minutes, seconds ? seconds : 0); + const fromTime = new Date(); + fromTime.setHours(fromHours, fromMinutes, fromSeconds); + const toTime = new Date(); + toTime.setHours(toHours, toMinutes, toSeconds); + // Compare the times + return imputTime >= fromTime && imputTime <= toTime; + } + // Example usage:console.log(isTimeBefore("12:30:45", "14:20:15")); // trueconsole.log(isTimeBefore("18:00:00", "10:00:00")); // false } From d94c3842a02bad1b1526cff9c2005f3f6ad57170 Mon Sep 17 00:00:00 2001 From: JustinMacaulay Date: Fri, 13 Dec 2024 10:28:21 -0800 Subject: [PATCH 2/5] linting fixes and small changes for support no of days --- .../support-details.component.ts | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts index 587cfb6b7..94de010ae 100644 --- a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts +++ b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts @@ -29,7 +29,7 @@ import { AlertService } from 'src/app/shared/components/alert/alert.service'; import { ReferralCreationService } from '../../step-supports/referral-creation.service'; import { DateConversionService } from 'src/app/core/services/utility/dateConversion.service'; import { ComputeRulesService } from 'src/app/core/services/computeRules.service'; -import {firstValueFrom, from, Subscription} from 'rxjs'; +import { firstValueFrom, Subscription } from 'rxjs'; import { LoadEvacueeListService } from '../../../../core/services/load-evacuee-list.service'; import { MatDatepickerInputEvent, @@ -515,17 +515,16 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { updateToDate(event: MatDatepickerInputEvent) { const days = this.supportDetailsForm.get('noOfDays').value; const currentVal = this.supportDetailsForm.get('fromDate').value; - const fromTime = this.supportDetailsForm.get('fromTime').value - const afterMidnightBeforeSix = this.isTimeBetween(fromTime, "00:00:00", "06:00:00") + const fromTime = this.supportDetailsForm.get('fromTime').value; + const afterMidnightBeforeSix = this.isTimeBetween(fromTime, '00:00:00', '06:00:00'); const date = new Date(currentVal); - if(afterMidnightBeforeSix){ - let finalValue = this.datePipe.transform(date.setDate(date.getDate() + days -1), 'MM/dd/yyyy'); + if (afterMidnightBeforeSix) { + let finalValue = this.datePipe.transform(date.setDate(date.getDate() + days - 1), 'MM/dd/yyyy'); this.supportDetailsForm.get('toDate').patchValue(new Date(finalValue)); - }else{ + } else { let finalValue = this.datePipe.transform(date.setDate(date.getDate() + days), 'MM/dd/yyyy'); this.supportDetailsForm.get('toDate').patchValue(new Date(finalValue)); } - } /** @@ -535,18 +534,18 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { */ updateNoOfDays(event: MatDatepickerInputEvent) { const fromDate = this.datePipe.transform(this.supportDetailsForm.get('fromDate').value, 'dd-MMM-yyyy'); - const fromTime = this.supportDetailsForm.get('fromTime').value + const fromTime = this.supportDetailsForm.get('fromTime').value; const toDate = this.datePipe.transform(event.value, 'dd-MMM-yyyy'); const dateDiff = new Date(toDate).getTime() - new Date(fromDate).getTime(); let days = dateDiff / (1000 * 60 * 60 * 24); - const afterMidnightBeforeSix = this.isTimeBetween(fromTime, "00:00:00", "06:00:00") + const afterMidnightBeforeSix = this.isTimeBetween(fromTime, '00:00:00', '06:00:00'); if (days > 30) { this.supportDetailsForm.get('noOfDays').patchValue(null); } else { - if(afterMidnightBeforeSix){ - days = days + 1 + if (afterMidnightBeforeSix) { + days = days + 1; } this.supportDetailsForm.get('noOfDays').patchValue(days); } @@ -1013,7 +1012,7 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { fromTime.setHours(fromHours, fromMinutes, fromSeconds); const toTime = new Date(); toTime.setHours(toHours, toMinutes, toSeconds); - // Compare the times + //Compare the times return imputTime >= fromTime && imputTime <= toTime; } // Example usage:console.log(isTimeBefore("12:30:45", "14:20:15")); // trueconsole.log(isTimeBefore("18:00:00", "10:00:00")); // false From cae868d13ca96ff97886fd5a49d51d8a6c9cd258 Mon Sep 17 00:00:00 2001 From: JustinMacaulay Date: Tue, 17 Dec 2024 09:29:46 -0800 Subject: [PATCH 3/5] added some new checks to make sure this logic only applies to housing. --- .../support-details.component.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts index 94de010ae..1bf8a025a 100644 --- a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts +++ b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts @@ -500,9 +500,16 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { */ updateValidToDate(days?: number): void { const currentVal = this.supportDetailsForm.get('fromDate').value; + const currentSupportType = this.stepSupportsService.supportTypeToAdd.value; if (days !== null && currentVal !== '') { const date = new Date(currentVal); - const finalValue = this.datePipe.transform(date.setDate(date.getDate() + days), 'MM/dd/yyyy'); + const fromTime = this.supportDetailsForm.get('fromTime').value; + const afterMidnightBeforeSix = this.isTimeBetween(fromTime, '00:00:00', '06:00:00'); + let totalDays = days; + if (afterMidnightBeforeSix && (currentSupportType === SupportSubCategory.Lodging_Hotel || currentSupportType === SupportSubCategory.Lodging_Allowance || currentSupportType === SupportSubCategory.Lodging_Group)) { + totalDays -= 1; + } + const finalValue = this.datePipe.transform(date.setDate(date.getDate() + totalDays), 'MM/dd/yyyy'); this.supportDetailsForm.get('toDate').patchValue(new Date(finalValue)); } } @@ -516,13 +523,14 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { const days = this.supportDetailsForm.get('noOfDays').value; const currentVal = this.supportDetailsForm.get('fromDate').value; const fromTime = this.supportDetailsForm.get('fromTime').value; + const currentSupportType = this.stepSupportsService.supportTypeToAdd.value; const afterMidnightBeforeSix = this.isTimeBetween(fromTime, '00:00:00', '06:00:00'); const date = new Date(currentVal); - if (afterMidnightBeforeSix) { - let finalValue = this.datePipe.transform(date.setDate(date.getDate() + days - 1), 'MM/dd/yyyy'); + let finalValue = this.datePipe.transform(date.setDate(date.getDate() + days), 'MM/dd/yyyy'); + if (afterMidnightBeforeSix && (currentSupportType === SupportSubCategory.Lodging_Hotel || currentSupportType === SupportSubCategory.Lodging_Allowance || currentSupportType === SupportSubCategory.Lodging_Group)) { + finalValue = this.datePipe.transform(date.setDate(date.getDate() + days - 1), 'MM/dd/yyyy'); this.supportDetailsForm.get('toDate').patchValue(new Date(finalValue)); } else { - let finalValue = this.datePipe.transform(date.setDate(date.getDate() + days), 'MM/dd/yyyy'); this.supportDetailsForm.get('toDate').patchValue(new Date(finalValue)); } } @@ -537,6 +545,7 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { const fromTime = this.supportDetailsForm.get('fromTime').value; const toDate = this.datePipe.transform(event.value, 'dd-MMM-yyyy'); const dateDiff = new Date(toDate).getTime() - new Date(fromDate).getTime(); + const currentSupportType = this.stepSupportsService.supportTypeToAdd.value; let days = dateDiff / (1000 * 60 * 60 * 24); const afterMidnightBeforeSix = this.isTimeBetween(fromTime, '00:00:00', '06:00:00'); @@ -544,7 +553,7 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { if (days > 30) { this.supportDetailsForm.get('noOfDays').patchValue(null); } else { - if (afterMidnightBeforeSix) { + if (afterMidnightBeforeSix && (currentSupportType === SupportSubCategory.Lodging_Hotel || currentSupportType === SupportSubCategory.Lodging_Allowance || currentSupportType === SupportSubCategory.Lodging_Group)) { days = days + 1; } this.supportDetailsForm.get('noOfDays').patchValue(days); From 388cde7756cbef67f395e83b94933d512b34ea72 Mon Sep 17 00:00:00 2001 From: JustinMacaulay Date: Tue, 17 Dec 2024 09:32:03 -0800 Subject: [PATCH 4/5] Removed console logs --- .../support-details/support-details.component.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts index 1bf8a025a..659d3cd04 100644 --- a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts +++ b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts @@ -291,13 +291,11 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { this.createSupportDetailsForm(); this.supportDetailsForm.get('noOfDays').valueChanges.subscribe((value) => { - console.log('value', value); this.updateValidToDate(value); }); this.supportDetailsForm.get('fromDate').valueChanges.subscribe((value) => { if (value === null || value === '' || value === undefined) { - console.log('value', value); this.supportDetailsForm.get('noOfDays').patchValue(1); } }); @@ -1024,5 +1022,4 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { //Compare the times return imputTime >= fromTime && imputTime <= toTime; } - // Example usage:console.log(isTimeBefore("12:30:45", "14:20:15")); // trueconsole.log(isTimeBefore("18:00:00", "10:00:00")); // false } From 74f9ccfe03d05eec67cae88d2ae18a4f0222857a Mon Sep 17 00:00:00 2001 From: JustinMacaulay Date: Tue, 17 Dec 2024 10:03:01 -0800 Subject: [PATCH 5/5] fixing linting issues --- .../support-details.component.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts index 659d3cd04..412fbccb3 100644 --- a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts +++ b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts @@ -504,7 +504,12 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { const fromTime = this.supportDetailsForm.get('fromTime').value; const afterMidnightBeforeSix = this.isTimeBetween(fromTime, '00:00:00', '06:00:00'); let totalDays = days; - if (afterMidnightBeforeSix && (currentSupportType === SupportSubCategory.Lodging_Hotel || currentSupportType === SupportSubCategory.Lodging_Allowance || currentSupportType === SupportSubCategory.Lodging_Group)) { + if ( + afterMidnightBeforeSix && + (currentSupportType === SupportSubCategory.Lodging_Hotel || + currentSupportType === SupportSubCategory.Lodging_Allowance || + currentSupportType === SupportSubCategory.Lodging_Group) + ) { totalDays -= 1; } const finalValue = this.datePipe.transform(date.setDate(date.getDate() + totalDays), 'MM/dd/yyyy'); @@ -525,7 +530,12 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { const afterMidnightBeforeSix = this.isTimeBetween(fromTime, '00:00:00', '06:00:00'); const date = new Date(currentVal); let finalValue = this.datePipe.transform(date.setDate(date.getDate() + days), 'MM/dd/yyyy'); - if (afterMidnightBeforeSix && (currentSupportType === SupportSubCategory.Lodging_Hotel || currentSupportType === SupportSubCategory.Lodging_Allowance || currentSupportType === SupportSubCategory.Lodging_Group)) { + if ( + afterMidnightBeforeSix && + (currentSupportType === SupportSubCategory.Lodging_Hotel || + currentSupportType === SupportSubCategory.Lodging_Allowance || + currentSupportType === SupportSubCategory.Lodging_Group) + ) { finalValue = this.datePipe.transform(date.setDate(date.getDate() + days - 1), 'MM/dd/yyyy'); this.supportDetailsForm.get('toDate').patchValue(new Date(finalValue)); } else { @@ -551,7 +561,12 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { if (days > 30) { this.supportDetailsForm.get('noOfDays').patchValue(null); } else { - if (afterMidnightBeforeSix && (currentSupportType === SupportSubCategory.Lodging_Hotel || currentSupportType === SupportSubCategory.Lodging_Allowance || currentSupportType === SupportSubCategory.Lodging_Group)) { + if ( + afterMidnightBeforeSix && + (currentSupportType === SupportSubCategory.Lodging_Hotel || + currentSupportType === SupportSubCategory.Lodging_Allowance || + currentSupportType === SupportSubCategory.Lodging_Group) + ) { days = days + 1; } this.supportDetailsForm.get('noOfDays').patchValue(days); @@ -789,6 +804,7 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { : this.setDefaultTimes(); } } + private createFromDate() { let existingSupports = this.existingSupports.filter( (x) => x.status !== SupportStatus.Cancelled.toString() && x.status !== SupportStatus.Void.toString()