Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/site business licence upload #2115

Merged
merged 4 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class BusinessLicencePageComponent extends AbstractCommunitySiteRegistrat

// Create a business licence document each time a file is uploaded, and
// update the existing business licence
return (documentGuid !== currentBusinessLicence.businessLicenceDocument?.documentGuid)
return (documentGuid && documentGuid !== currentBusinessLicence.businessLicenceDocument?.documentGuid)
? this.siteResource.removeBusinessLicenceDocument(siteId, currentBusinessLicence.id)
.pipe(
exhaustMap(() => this.siteResource.createBusinessLicenceDocument(siteId, currentBusinessLicence.id, documentGuid)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ng-container>
</app-expiry-alert>

<app-alert *ngIf="siteErrors?.deviceProviderSite"
<app-alert *ngIf="hasErrors()"
type="danger"
icon="error">
<ng-container #alertContent
Expand Down Expand Up @@ -51,7 +51,7 @@
<div class="col text-right">
<button mat-flat-button
color="primary"
[disabled]="!accept.checked || siteErrors?.deviceProviderSite"
[disabled]="!accept.checked || hasErrors()"
(click)="onSubmit()">
Submit
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ export class OverviewPageComponent implements OnInit {
);
}

public hasErrors(): boolean {
return Object.values(this.siteErrors).some(val => val);
}

public ngOnInit(): void {
this.organization = (
this.overviewType === 'organization' ||
Expand Down Expand Up @@ -186,8 +190,6 @@ export class OverviewPageComponent implements OnInit {
};
}

this.siteErrors = this.getSiteErrors(site);

// Store a local copy of the site for overview
this.site = site;

Expand All @@ -199,7 +201,10 @@ export class OverviewPageComponent implements OnInit {
// updates when not already patched and contains changes
this.siteFormStateService.setForm(site);

this.isBusinessLicenceUpdated = this.siteFormStateService.businessLicenceFormState.isBusinessLicenceUpdated;
this.isBusinessLicenceUpdated = this.siteFormStateService.businessLicenceFormState.isBusinessLicenceUpdated
|| (this.siteFormStateService.businessLicenceFormState.businessLicenceGuid.value && !this.site.businessLicence.businessLicenceDocument);

this.siteErrors = this.getSiteErrors(site);
}

/**
Expand Down Expand Up @@ -227,7 +232,9 @@ export class OverviewPageComponent implements OnInit {
private getSiteErrors(site: Site): ValidationErrors {
return {
deviceProviderSite: !site.individualDeviceProviders?.length
&& site.careSettingCode === CareSettingEnum.DEVICE_PROVIDER
&& site.careSettingCode === CareSettingEnum.DEVICE_PROVIDER,
missingBusinessLicenceOrReason: !site.businessLicence.businessLicenceDocument
&& !site.businessLicence.deferredLicenceReason && !this.isBusinessLicenceUpdated
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,8 @@
{{ site?.pec | default }}
</app-enrollee-property>

<app-enrollee-property *ngIf="site.businessLicence?.deferredLicenceReason"
title="Deferred Business Licence Reason">
{{ site.businessLicence.deferredLicenceReason | default }}
</app-enrollee-property>

<ng-container *ngIf="!admin; else businessLicenceListView">
<ng-container *ngIf="site.businessLicence?.businessLicenceDocument">
<ng-container *ngIf="site.businessLicence?.businessLicenceDocument; else deferredLicence">

<app-enrollee-property title="Expiry"
[hasError]="!site.businessLicence?.expiryDate && withinRenewalPeriod"
Expand All @@ -117,8 +112,26 @@
</app-enrollee-property>

</ng-container>

<ng-template #deferredLicence>
<ng-container *ngIf="site.businessLicence?.deferredLicenceReason; else missingLicenceAndDeferral">
<app-enrollee-property title="Deferred Business Licence Reason">
{{ site.businessLicence.deferredLicenceReason | default }}
</app-enrollee-property>
</ng-container>
<ng-template #missingLicenceAndDeferral>
<app-enrollee-property [hasError]="siteErrors?.missingBusinessLicenceOrReason"
errorMessage="Must have a valid business licence or deferred reason"
title="Business Licence">
{{ (businessLicenceUpdated) ? "New business licence document has been uploaded for submission" : "-"}}
</app-enrollee-property>
</ng-template>
</ng-template>
</ng-container>




<ng-template #businessLicenceListView>
<ng-container *ngFor="let businessLicence of site.businessLicences">
<app-enrollee-property title="Expiry">
Expand Down
2 changes: 1 addition & 1 deletion prime-dotnet-webapi/Controllers/SitesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private async Task<bool> HandleBusinessLicenseUpdateAsync(CommunitySite site, Si
}

var existingLicence = site.BusinessLicence;
var isNewDocument = existingLicence.BusinessLicenceDocument.DocumentGuid != newLicence.DocumentGuid && newLicence.DocumentGuid != null;
var isNewDocument = existingLicence.BusinessLicenceDocument?.DocumentGuid != newLicence.DocumentGuid && newLicence.DocumentGuid != null;

if (site.ApprovedDate == null)
{
Expand Down