|
329 | 329 | v-model="obj.formattedStartDate"
|
330 | 330 | :min="fiscalStartAndEndDates.startDate"
|
331 | 331 | :max="fiscalStartAndEndDates.endDate"
|
332 |
| - :rules="rules.required" |
| 332 | + :rules="[ |
| 333 | + ...rules.required, |
| 334 | + rules.min(fiscalStartAndEndDates.startDate, 'Must exceed fiscal year start date'), |
| 335 | + rules.max(fiscalStartAndEndDates.endDate, 'Must be before fiscal year end date'), |
| 336 | + ]" |
333 | 337 | :disabled="isReadOnly"
|
334 | 338 | :hide-details="isReadOnly"
|
335 |
| - label="Date" |
| 339 | + label="Start Date" |
336 | 340 | clearable
|
| 341 | + @input="isDateLegal(obj)" |
337 | 342 | />
|
338 | 343 | </v-col>
|
339 | 344 |
|
|
342 | 347 | v-model="obj.formattedEndDate"
|
343 | 348 | :min="obj.formattedStartDate"
|
344 | 349 | :max="fiscalStartAndEndDates.endDate"
|
345 |
| - :rules="rules.required" |
| 350 | + :rules="[ |
| 351 | + ...rules.required, |
| 352 | + rules.min(obj.formattedStartDate, 'Must exceed start date'), |
| 353 | + rules.max(fiscalStartAndEndDates.endDate, 'Must be before fiscal year end date'), |
| 354 | + ]" |
346 | 355 | :disabled="isReadOnly"
|
347 | 356 | :hide-details="isReadOnly"
|
348 | 357 | clearable
|
| 358 | + label="End Date" |
349 | 359 | @input="isDateLegal(obj)"
|
350 | 360 | />
|
351 | 361 | </v-col>
|
|
375 | 385 | </v-col>
|
376 | 386 |
|
377 | 387 | <span class="text-white"> . </span>
|
378 |
| - <v-row v-if="obj.isIllegal"> |
| 388 | + <v-row v-if="obj.datesOverlap || obj.datesInvalid"> |
379 | 389 | <v-card width="100%" class="mx-3 my-10">
|
380 | 390 | <AppAlertBanner type="error" class="mb-4 w-100">Invalid Dates</AppAlertBanner>
|
381 | 391 |
|
382 |
| - <v-card-text> |
| 392 | + <v-card-text v-if="obj.datesInvalid"> |
| 393 | + Closure Start Date: {{ obj.formattedStartDate }} |
| 394 | + <br /> |
| 395 | + Closure End Date: {{ obj.formattedEndDate }} <br /><br /> |
| 396 | + |
| 397 | + Please review your facility closure dates. |
| 398 | + <br /> |
| 399 | + </v-card-text> |
| 400 | + <v-card-text v-else-if="obj.datesOverlap"> |
383 | 401 | It appears that the closure start and end dates you've selected for this facility overlap with
|
384 | 402 | dates you've previously selected.
|
385 | 403 | <br /><br />
|
|
390 | 408 | Please review your existing facility closure dates to ensure consistency and avoid any potential
|
391 | 409 | overlap of Facility closure dates.
|
392 | 410 | <br />
|
393 |
| - Thank you for your attention |
394 | 411 | </v-card-text>
|
395 | 412 | </v-card>
|
396 | 413 | </v-row>
|
@@ -527,12 +544,12 @@ import alertMixin from '@/mixins/alertMixin.js';
|
527 | 544 | import globalMixin from '@/mixins/globalMixin.js';
|
528 | 545 | import ApiService from '@/common/apiService.js';
|
529 | 546 |
|
| 547 | +//builds an array of dates to keep track of all days of the selected closure period. |
| 548 | +//this array is used to check if a user selects an overlapping date |
530 | 549 | function dateFunction(date1, date2) {
|
531 | 550 | const startDate = new Date(date1);
|
532 | 551 | const endDate = new Date(date2);
|
533 |
| -
|
534 | 552 | const dates = [];
|
535 |
| -
|
536 | 553 | const currentDate = new Date(startDate.getTime());
|
537 | 554 |
|
538 | 555 | while (currentDate <= endDate) {
|
@@ -701,17 +718,44 @@ export default {
|
701 | 718 | });
|
702 | 719 | },
|
703 | 720 | isDateLegal(obj) {
|
| 721 | + // Get all dates from chosenDates except for the currently edited row |
| 722 | + const otherChosenDates = this.CCFRIFacilityModel.dates |
| 723 | + .filter((dateObj) => dateObj.id !== obj.id) |
| 724 | + .reduce((acc, dateObj) => { |
| 725 | + return [...acc, ...dateFunction(dateObj.formattedStartDate, dateObj.formattedEndDate)]; |
| 726 | + }, []); |
| 727 | +
|
704 | 728 | const dates = dateFunction(obj.formattedStartDate, obj.formattedEndDate);
|
705 |
| - obj.isIllegal = false; |
706 | 729 |
|
| 730 | + //datesOverlap flag is true if the selected dates are part of an overlap of other dates. |
| 731 | + //datesInvalid is true if user breaks any other date rule. |
| 732 | +
|
| 733 | + //We do not let users save invalid dates of any kind so there is no risk of a mis-calculation in Dynamics |
| 734 | + //Rules are: end date cannot be before start date |
| 735 | + //start date for either field cannot be before the start of fiscal year |
| 736 | + //end dates for either field cannot be after end of fiscal year |
| 737 | +
|
| 738 | + if ( |
| 739 | + obj.formattedEndDate < obj.formattedStartDate || |
| 740 | + obj.formattedStartDate < this.fiscalStartAndEndDates.startDate || |
| 741 | + obj.formattedEndDate < this.fiscalStartAndEndDates.startDate || |
| 742 | + obj.formattedStartDate > this.fiscalStartAndEndDates.endDate || |
| 743 | + obj.formattedEndDate > this.fiscalStartAndEndDates.endDate |
| 744 | + ) { |
| 745 | + obj.datesInvalid = true; |
| 746 | + return; |
| 747 | + } |
| 748 | +
|
| 749 | + obj.datesOverlap = false; |
| 750 | + obj.datesInvalid = false; |
707 | 751 | dates.forEach((date) => {
|
708 |
| - if (this.chosenDates.includes(date)) { |
709 |
| - obj.isIllegal = true; |
| 752 | + if (otherChosenDates.includes(date)) { |
| 753 | + obj.datesOverlap = true; |
710 | 754 | }
|
711 | 755 | });
|
712 | 756 | },
|
713 | 757 | hasIllegalDates() {
|
714 |
| - return this.CCFRIFacilityModel?.dates?.some((el) => el.isIllegal); |
| 758 | + return this.CCFRIFacilityModel?.dates?.some((el) => el.datesOverlap || el.datesInvalid); |
715 | 759 | },
|
716 | 760 | hasDataToDelete() {
|
717 | 761 | //checks all care types for the deleteMe flag. If true, we need to run save regardless if the model has been changed by the user.
|
|
0 commit comments