Skip to content

Commit

Permalink
18273 Extension Request Scenario 2 (bcgov#580)
Browse files Browse the repository at this point in the history
* Extension Request Scenario 2

* Fix lint issue

* Fix min expiry date

* Restore comment on isFirstAgm

* Move currentDate to data object

* Fix agm year not clearing on firstAgm change

* Update watcher comment

* Update version to 7.0.10 and fix unit tests
  • Loading branch information
leodube-aot authored and JazzarKarim committed Jan 27, 2024
1 parent 898d28c commit 039d828
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 61 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "business-filings-ui",
"version": "7.0.9",
"version": "7.0.10",
"private": true,
"appName": "Filings UI",
"sbcName": "SBC Common Components",
Expand Down
169 changes: 121 additions & 48 deletions src/components/AgmExtension/ExtensionRequest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,8 @@

<script lang="ts">
import { Component, Emit, Prop, Vue, Watch } from 'vue-property-decorator'
import { Getter } from 'pinia-class'
import { VcardTemplate } from '@/components/common'
import { AgmExtEvalIF } from '@/interfaces'
import { useRootStore } from '@/stores'
import { DatePicker } from '@bcrs-shared-components/date-picker'
import AgmYear from '@/components/AgmLocationChange/AgmYear.vue'
import { DateUtilities } from '@/services'
Expand All @@ -185,8 +183,6 @@ export default class ExtensionRequest extends Vue {
@Prop({ default: false }) readonly showErrors!: boolean
@Getter(useRootStore) getCurrentDate!: string
/** The extension expiry date text. */
extensionExpiryDateText = ''
Expand Down Expand Up @@ -218,6 +214,7 @@ export default class ExtensionRequest extends Vue {
}
set agmYear (value: string) {
this.data.agmYear = value
const data = { ...this.data, agmYear: value }
this.emitData(data)
}
Expand All @@ -228,7 +225,7 @@ export default class ExtensionRequest extends Vue {
return DateUtilities.addMonthsToDate(30, DateUtilities.dateToYyyyMmDd(this.data.incorporationDate))
} else {
// For subsequent AGMs, max shouldn't be later than reference date + 15 months + 12 months
return 'placeholder for future work'
return DateUtilities.addMonthsToDate(27, this.data.prevAgmDate)
}
}
Expand All @@ -238,28 +235,29 @@ export default class ExtensionRequest extends Vue {
return DateUtilities.addMonthsToDate(19, DateUtilities.dateToYyyyMmDd(this.data.incorporationDate))
} else {
// For subsequent AGMs, min shouldn't be later than reference date + 15 months + 1 month
return 'placeholder for future work'
return DateUtilities.addMonthsToDate(16, this.data.prevAgmDate)
}
}
/**
* Whether to disable the editing of AGM Year field.
* Editable (false) when Is this first AGM is set to No.
* Non-Editable (true) when we first load (null) or Is first AGM is Yes.
* Set the agmYear as incorporation date if not null and true.
*/
/** Whether to disable the editing of AGM Year field. */
get isFirstAgm (): boolean {
if (this.data.isFirstAgm !== null) {
if (this.data.isFirstAgm) {
this.data.agmYear = this.data.incorporationDate.getFullYear().toString()
return true
} else {
this.data.agmYear = ''
return false
}
} else {
// Field disabled on first load when value is null
if (this.data.isFirstAgm == null) {
return true
}
// Field disabled when it is first agm
return this.data.isFirstAgm
}
/** Called when isFirstAgm radio group changes. */
@Watch('data.isFirstAgm')
onIsFirstAgmChanged (val: boolean): void {
if (val) {
this.data.agmYear = this.data.incorporationDate.getFullYear().toString()
} else {
this.data.agmYear = ''
}
}
/** Called when extension date picker changes. */
Expand All @@ -268,61 +266,136 @@ export default class ExtensionRequest extends Vue {
this.data.prevExpiryDate = val
}
@Watch('intendedAgmDateText')
/** Called when intended AGM date picker changes. */
@Watch('intendedAgmDateText')
onAgmIntendedDatePickerChanged (val: string): void {
this.data.intendedAgmDate = val
}
@Watch('previousAgmDateText')
/** Called when previous AGM date picker changes. */
@Watch('previousAgmDateText')
onPreviousAgmDatePickerChanged (val: string): void {
this.data.prevAgmDate = val
}
@Watch('data.currentDate')
@Watch('data.isPrevExtension')
@Watch('previousAgmDateText')
@Watch('extensionExpiryDateText')
onIsPrevExtensionChanged (): void {
/* eslint-disable brace-style */
const currentDate = DateUtilities.yyyyMmDdToDate(this.data.currentDate)
this.data.isEligible = null
if (!this.data.isPrevExtension && this.isFirstAgm) { // This is the first extension request for this AGM
// cutOffDate is the date where eligibility will be false if passed in a particular rule.
// IF First AGM and has an extension been request for this AGM year already is false
this.data.extensionDuration = null
// IF first AGM extension
// AND NOT extension requested this year
if (
this.isFirstAgm &&
!this.data.isPrevExtension &&
this.data.incorporationDate
) {
// cutOffDate: the date where eligibility will be false if passed in a particular rule.
const cutOffYyyyMmDd = DateUtilities.addMonthsToDate(
18, DateUtilities.dateToYyyyMmDd(this.data.incorporationDate))
const cutOffDate = DateUtilities.yyyyMmDdToDate(cutOffYyyyMmDd)
const currentDate = DateUtilities.yyyyMmDdToDate(this.getCurrentDate)
// IF CurrentDate > (IncorporationDate + 18 Months + 5 days) --> INELIGIBLE
// ELSE --> ELIGIBLE --> Extension Duration = 6 months
// IF CurrentDate > (IncorporationDate + 18 Months + 5 days)
// THEN NOT ELIGIBLE
if ((DateUtilities.daysBetweenTwoDates(cutOffDate, currentDate) - 5) > 0) {
this.data.isEligible = false
} else {
}
// ELSE ELIGIBLE, ExtensionDuration = 6 months
else {
this.data.isEligible = true
this.data.extensionDuration = 6
}
} else if (this.data.isPrevExtension && this.isFirstAgm && this.extensionExpiryDateText) {
// Yes - Specify the date the extension expires
// IF First AGM and has an extension been request for this AGM year already is true
}
// ELSE IF first AGM extension
// AND extension requested this year
else if (
this.isFirstAgm &&
this.data.isPrevExtension &&
this.extensionExpiryDateText &&
this.data.incorporationDate
) {
const cutOffYyyyMmDd = DateUtilities.addMonthsToDate(
30, DateUtilities.dateToYyyyMmDd(this.data.incorporationDate))
const cutOffDate = DateUtilities.yyyyMmDdToDate(cutOffYyyyMmDd)
const expiryDate = DateUtilities.yyyyMmDdToDate(this.extensionExpiryDateText)
// IF ExpirationDate >= (IncorporationDate + 18 months + 12 months) --> INELIGIBLE
// ELSE --> Check ELSE BLOCK
// IF ExpirationDate >= (IncorporationDate + 18 months + 12 months)
// THEN NOT ELIGIBLE
if ((DateUtilities.daysBetweenTwoDates(cutOffDate, expiryDate)) >= 0) {
this.data.isEligible = false
} else {
// IF CurrentDate > (ExpirationDate + 5 days) --> INELIGIBLE
// ELSE --> ELIGIBLE --> ExtensionDuration = MIN(6, 12 - totalExtensionApproved)
// totalExtensionApproved = (ExpirationDate - 18 months - IncorporationDate) in months
const currentDate = DateUtilities.yyyyMmDdToDate(this.getCurrentDate)
if ((DateUtilities.daysBetweenTwoDates(expiryDate, currentDate)) > 5) {
this.data.isEligible = false
} else {
this.data.isEligible = true
const totalExtensionApproved = DateUtilities.subtractDates(
DateUtilities.dateToYyyyMmDd(this.data.incorporationDate), this.extensionExpiryDateText) - 18
this.data.extensionDuration = Math.min(6, (12 - totalExtensionApproved))
}
}
// ELSE IF CurrentDate > (ExpirationDate + 5 days)
// THEN NOT ELIGIBLE
else if ((DateUtilities.daysBetweenTwoDates(expiryDate, currentDate)) > 5) {
this.data.isEligible = false
}
// ELSE ELIGIBLE, ExtensionDuration = MIN(6, 12 - totalExtensionApproved)
else {
this.data.isEligible = true
// totalExtensionApproved: (ExpirationDate - 18 months - IncorporationDate) in months
const totalExtensionApproved = DateUtilities.subtractDates(
DateUtilities.dateToYyyyMmDd(this.data.incorporationDate), this.extensionExpiryDateText) - 18
this.data.extensionDuration = Math.min(6, (12 - totalExtensionApproved))
}
}
// ELSE IF NOT first agm extension
// AND NOT extension requested this year
else if (
!this.isFirstAgm &&
!this.data.isPrevExtension &&
this.previousAgmDateText
) {
const cutOffYyyyMmDd = DateUtilities.addMonthsToDate(
15, this.previousAgmDateText)
const cutOffDate = DateUtilities.yyyyMmDdToDate(cutOffYyyyMmDd)
// IF CurrentDate > (PrevAgmDate + 15 Months + 5 days)
// THEN NOT ELIGIBLE
if ((DateUtilities.daysBetweenTwoDates(cutOffDate, currentDate) - 5) > 0) {
this.data.isEligible = false
}
// ELSE ELIGIBLE, ExtensionDuration = 6 months
else {
this.data.isEligible = true
this.data.extensionDuration = 6
}
}
// ELSE IF NOT first agm extension
// AND extension requested this year
else if (
!this.isFirstAgm &&
this.data.isPrevExtension &&
this.previousAgmDateText &&
this.extensionExpiryDateText
) {
const cutOffDate = DateUtilities.yyyyMmDdToDate(this.previousAgmDateText)
const expiryDate = DateUtilities.yyyyMmDdToDate(this.extensionExpiryDateText)
// IF CurrentDate > (ExpirationDate + 5 days)
// THEN NOT ELIGIBLE
if ((DateUtilities.daysBetweenTwoDates(expiryDate, currentDate)) > 5) {
this.data.isEligible = false
}
// ELSE IF (ExpirationDate - PrevAgmDate) > 12 months
// THEN NOT ELIGIBLE
else if ((DateUtilities.daysBetweenTwoDates(cutOffDate, expiryDate)) > 365) {
this.data.isEligible = false
}
// ELSE ELIGIBLE, ExtensionDuration = 12 months - ExpiryDate - PrevAgmDate
else {
this.data.isEligible = true
this.data.extensionDuration = 12 - DateUtilities.subtractDates(
this.previousAgmDateText,
this.extensionExpiryDateText
)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/agm-ext-eval-interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** Object that stores AGM Extension evaluation fields. */
export interface AgmExtEvalIF {
currentDate: string // YYYY-MM-DD
alreadyExtended: boolean
requestExpired: boolean
isGoodStanding: boolean
Expand All @@ -17,6 +18,7 @@ export interface AgmExtEvalIF {

/** An empty AGM Extension Evaluation object. Note: don't assign this - make a copy instead. */
export const EmptyAgmExtEval: AgmExtEvalIF = {
currentDate: null,
alreadyExtended: null,
requestExpired: null,
isGoodStanding: null,
Expand Down
4 changes: 2 additions & 2 deletions src/services/date-utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ export default class DateUtilities {
* @example (18, 2023-02-03) -> "2024-08-03"
*/
static addMonthsToDate (month: number, date: string): string {
if (!date) {
date = '2023-01-01'
if (!month || !date) {
return null
}
const temp = this.yyyyMmDdToDate(date)
temp.setMonth(temp.getMonth() + month)
Expand Down
1 change: 1 addition & 0 deletions src/views/AgmExtension.vue
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export default class AgmExtension extends Mixins(CommonMixin, DateMixin,
/** Called when component is mounted. */
mounted (): void {
this.data.currentDate = this.getCurrentDate
this.data.isGoodStanding = this.isGoodStanding
this.data.incorporationDate = this.getFoundingDate
Expand Down
1 change: 1 addition & 0 deletions tests/unit/AgmExtension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ describe('AGM Extension view', () => {
agmExtension: {
agmDueDate: null,
agmYear: null,
currentDate: '2023-11-06',
extensionDuration: NaN,
incorporationDate: new Date('2000-01-01T08:00:00.000Z'),
isEligible: true,
Expand Down
13 changes: 5 additions & 8 deletions tests/unit/ExtensionRequest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ describe('ExtensionRequest', () => {
expect(rows.at(1).find('.col-sm-3').text()).toBe('AGM Year')
expect(rows.at(1).find('.col-sm-9 .v-text-field').exists()).toBe(true)

expect(rows.at(2).find('.col-sm-3').text()).toBe('Previous AGM date or a reference date')
expect(rows.at(2).find('.col-sm-9').findComponent(DatePicker).exists()).toBe(true)

expect(rows.at(3).find('.col-sm-3').text()).toBe('Has an extension been requested for this AGM year already?')
expect(rows.at(3).find('.col-sm-9').text())
expect(rows.at(2).find('.col-sm-3').text()).toBe('Has an extension been requested for this AGM year already?')
expect(rows.at(2).find('.col-sm-9').text())
.toContain('Yes - Specify the date the extension expiresDate of extension expiry')
expect(rows.at(3).find('.col-sm-9').text()).toContain('No - this is the first extension request for this AGM')
expect(rows.at(2).find('.col-sm-9').text()).toContain('No - this is the first extension request for this AGM')

expect(rows.at(4).find('.col-sm-3').text()).toBe('Intended date this AGM will be held')
expect(rows.at(4).find('.col-sm-9').findComponent(DatePicker).exists()).toBe(true)
expect(rows.at(3).find('.col-sm-3').text()).toBe('Intended date this AGM will be held')
expect(rows.at(3).find('.col-sm-9').findComponent(DatePicker).exists()).toBe(true)

wrapper.destroy()
})
Expand Down

0 comments on commit 039d828

Please sign in to comment.