Skip to content

Commit

Permalink
Add Request As for settlement reports. (#3579)
Browse files Browse the repository at this point in the history
  • Loading branch information
defectiveAi authored Sep 27, 2024
1 parent 162f42b commit 0d42a02
Show file tree
Hide file tree
Showing 15 changed files with 331 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,8 @@ input RequestSettlementReportInput {
useApi: Boolean!
energySupplier: String
csvLanguage: String
requestAsActorId: String
requestAsMarketRole: SettlementReportMarketRole
}

input ResetTwoFactorAuthenticationInput {
Expand Down Expand Up @@ -1453,6 +1455,14 @@ enum RequestCalculationDataType {
ALL_ENERGY
}

enum SettlementReportMarketRole {
OTHER
GRID_ACCESS_PROVIDER
ENERGY_SUPPLIER
SYSTEM_OPERATOR
DATA_HUB_ADMINISTRATOR
}

enum SettlementReportStatusType {
IN_PROGRESS
ERROR
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2020 Energinet DataHub A/S
//
// Licensed under the Apache License, Version 2.0 (the "License2");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Energinet.DataHub.WebApi.Clients.Wholesale.SettlementReports.Dto;

public enum SettlementReportMarketRole
{
Other,
GridAccessProvider,
EnergySupplier,
SystemOperator,
DataHubAdministrator,
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public sealed record SettlementReportRequestDto(
bool IncludeBasisData,
bool IncludeMonthlyAmount,
bool UseAPI,
SettlementReportRequestFilterDto Filter);
SettlementReportRequestFilterDto Filter,
string? ActorNumberOverride,
SettlementReportMarketRole? MarketRoleOverride);
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ await client.RequestAsync(
requestSettlementReportInput.IncludeBasisData,
requestSettlementReportInput.IncludeMonthlySums,
requestSettlementReportInput.UseApi,
requestFilter),
requestFilter,
requestSettlementReportInput.RequestAsActorId,
requestSettlementReportInput.RequestAsMarketRole),
default);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Energinet.DataHub.WebApi.Clients.Wholesale.SettlementReports.Dto;
using NodaTime;

namespace Energinet.DataHub.WebApi.GraphQL.Types.SettlementReports;
Expand All @@ -26,4 +27,6 @@ public record RequestSettlementReportInput(
bool IncludeBasisData,
bool UseApi,
string? EnergySupplier,
string? CsvLanguage);
string? CsvLanguage,
string? RequestAsActorId,
SettlementReportMarketRole? RequestAsMarketRole);
1 change: 0 additions & 1 deletion apps/dh/api-dh/source/DataHub.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using Energinet.DataHub.WebApi;
using Energinet.DataHub.WebApi.Registration;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using OpenTelemetry.Trace;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@
},
"requestReportModal": {
"title": "{{ wholesale.settlementReports.requestSettlementReport }}",
"requestAs": "Anmod som",
"calculationType": "Beregningstype",
"includeBasisData": "Inkluder datagrundlag",
"allowLargeTextFiles": "Tillad store filer",
Expand All @@ -1296,6 +1297,7 @@
"combineResultsInOneFile": "Kombiner resultater i en fil",
"cancel": "Fortryd",
"confirm": "{{ wholesale.settlementReports.requestSettlementReport }}",
"continue": "Næste",
"startDateIsBeforeMinDate": "Startdatoen kan ikke være ældre end 3,6 år + løbende måned",
"requestSuccess": "Afregningsrapport bestilt.",
"requestError": "Noget gik galt. Afregningsrapporten blev ikke bestilt. Prøv igen."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,7 @@
},
"requestReportModal": {
"title": "{{ wholesale.settlementReports.requestSettlementReport }}",
"requestAs": "Request as",
"calculationType": "Calculation type",
"includeBasisData": "Include basis data",
"allowLargeTextFiles": "Allow large files",
Expand All @@ -1296,6 +1297,7 @@
"gridAreaHint": "{{ count }} selected",
"combineResultsInOneFile": "Combine results in one file",
"cancel": "Cancel",
"continue": "Next",
"confirm": "{{ wholesale.settlementReports.requestSettlementReport }}",
"startDateIsBeforeMinDate": "Start date cannot be older than 3,6 years + the current month",
"requestSuccess": "Settlement report has been requested.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { exists } from '@energinet-datahub/dh/shared/util-operators';
import { WattDropdownOptions } from '@energinet-datahub/watt/dropdown';

export function getActorOptions(
eicFunctions: [EicFunction],
eicFunctions: EicFunction[],
valueType: 'glnOrEicNumber' | 'actorId' = 'glnOrEicNumber'
): Observable<WattDropdownOptions> {
const apollo = inject(Apollo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class DhActorStorage {
this.setSelectedActorId(actor.id);
};

getSelectedActor = () => {
getSelectedActor = (): SelectionActor | null => {
const selectedActorInLS = this._localStorage.getItem(this.selectedActorKey);
const selectedActorInSS = this._sessionStorage.getItem(this.selectedActorKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, inject } from '@angular/core';
import { Component, DestroyRef, inject } from '@angular/core';
import { TranslocoPipe } from '@ngneat/transloco';

import { WattButtonComponent } from '@energinet-datahub/watt/button';
import { WattModalService } from '@energinet-datahub/watt/modal';

import { DhRequestSettlementReportModalComponent } from '../modal/dh-request-settlement-report-modal.component';
import { DhRequestAsSettlementReportModalComponent } from '../modal/dh-request-as-settlement-report-modal.component';
import {
DhActorStorage,
PermissionService,
} from '@energinet-datahub/dh/shared/feature-authorization';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

@Component({
selector: 'dh-request-settlement-report-button',
Expand All @@ -34,10 +40,29 @@ import { DhRequestSettlementReportModalComponent } from '../modal/dh-request-set
})
export class DhRequestSettlementReportButtonComponent {
private readonly modalService = inject(WattModalService);
private readonly permissionService = inject(PermissionService);
private readonly actorStorage = inject(DhActorStorage);
private readonly destroyRef = inject(DestroyRef);

openModal() {
this.modalService.open({
component: DhRequestSettlementReportModalComponent,
});
this.permissionService
.isFas()
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((isFas) => {
if (isFas) {
this.modalService.open({
component: DhRequestAsSettlementReportModalComponent,
});
} else {
this.modalService.open({
component: DhRequestSettlementReportModalComponent,
data: {
isFas: false,
actorId: this.actorStorage.getSelectedActorId(),
marketRole: this.actorStorage.getSelectedActor()?.marketRole,
},
});
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!--
@license
Copyright 2020 Energinet DataHub A/S
Licensed under the Apache License, Version 2.0 (the "License2");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<watt-modal
#modal
[title]="t('title')"
*transloco="let t; read: 'wholesale.settlementReports.requestReportModal'"
>
<form id="request-as-settlement-report-form" [formGroup]="form" (ngSubmit)="submit()">
<vater-stack align="stretch" direction="column" gap="l">
<watt-dropdown
[label]="t('requestAs')"
[showResetOption]="false"
[formControl]="form.controls.actorId"
[options]="actorOptions$ | push"
/>
</vater-stack>
</form>

<watt-modal-actions>
<watt-button variant="secondary" (click)="modal.close(false)">{{ t("cancel") }}</watt-button>
<watt-button
type="submit"
formId="request-as-settlement-report-form"
[loading]="submitInProgress()"
>
{{ t("continue") }}
</watt-button>
</watt-modal-actions>
</watt-modal>
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
* @license
* Copyright 2020 Energinet DataHub A/S
*
* Licensed under the Apache License, Version 2.0 (the "License2");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, DestroyRef, inject, signal } from '@angular/core';
import {
FormControl,
FormGroup,
NonNullableFormBuilder,
ReactiveFormsModule,
Validators,
} from '@angular/forms';
import { getActorOptions } from '@energinet-datahub/dh/shared/data-access-graphql';
import { EicFunction, GetActorByIdDocument } from '@energinet-datahub/dh/shared/domain/graphql';
import { WattButtonComponent } from '@energinet-datahub/watt/button';
import { WattDropdownComponent } from '@energinet-datahub/watt/dropdown';
import { WattFieldErrorComponent } from '@energinet-datahub/watt/field';
import { WATT_MODAL, WattModalService, WattTypedModal } from '@energinet-datahub/watt/modal';
import { VaterStackComponent } from '@energinet-datahub/watt/vater';
import { TranslocoDirective } from '@ngneat/transloco';
import { RxPush } from '@rx-angular/template/push';

import { DhRequestSettlementReportModalComponent } from '../modal/dh-request-settlement-report-modal.component';
import { Apollo } from 'apollo-angular';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import {
DhActorStorage,
PermissionService,
} from '@energinet-datahub/dh/shared/feature-authorization';

type DhFormType = FormGroup<{
actorId: FormControl<string>;
}>;

@Component({
selector: 'dh-request-as-settlement-report-modal',
standalone: true,
imports: [
RxPush,
ReactiveFormsModule,
TranslocoDirective,

WATT_MODAL,
VaterStackComponent,
WattDropdownComponent,
WattButtonComponent,
WattFieldErrorComponent,
],
templateUrl: './dh-request-as-settlement-report-modal.component.html',
})
export class DhRequestAsSettlementReportModalComponent extends WattTypedModal {
private readonly formBuilder = inject(NonNullableFormBuilder);
private readonly modalService = inject(WattModalService);
private readonly destroyRef = inject(DestroyRef);
private readonly apollo = inject(Apollo);

private readonly permissionService = inject(PermissionService);
private readonly actorStorage = inject(DhActorStorage);

form: DhFormType = this.formBuilder.group({
actorId: new FormControl<string>(this.actorStorage.getSelectedActorId(), {
validators: Validators.required,
nonNullable: true,
}),
});

actorOptions$ = getActorOptions(
[EicFunction.DataHubAdministrator, EicFunction.GridAccessProvider, EicFunction.EnergySupplier],
'actorId'
);

submitInProgress = signal(false);

submit(): void {
if (this.form.invalid || !this.form.value.actorId) {
return;
}

this.submitInProgress.set(true);

if (this.form.value.actorId == this.actorStorage.getSelectedActorId()) {
this.permissionService
.isFas()
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((isFas) => {
this.modalService.close(true);
this.modalService.open({
component: DhRequestSettlementReportModalComponent,
data: {
isFas,
actorId: this.actorStorage.getSelectedActor()?.id,
marketRole: this.actorStorage.getSelectedActor()?.marketRole,
},
});

this.submitInProgress.set(false);
});
} else {
this.apollo
.query({
query: GetActorByIdDocument,
variables: {
id: this.form.value.actorId,
},
})
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((result) => {
this.modalService.close(true);
this.modalService.open({
component: DhRequestSettlementReportModalComponent,
data: {
isFas: false,
actorId: result.data.actorById.id,
marketRole: result.data.actorById.marketRole,
},
});

this.submitInProgress.set(false);
});
}
}
}
Loading

0 comments on commit 0d42a02

Please sign in to comment.