Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -364,7 +364,7 @@ describe('Account Enquiry - Minor Creditor Header', () => {
interceptAuthenticatedUser();
});

const minorCreditorAccountId = FINES_ACC_MINOR_CREDITOR_DETAILS_HEADER_MOCK.account_number;
const minorCreditorAccountId = FINES_ACC_MINOR_CREDITOR_DETAILS_HEADER_MOCK.creditor.account_number;
const minorCreditorComponentProperties: IComponentProperties = {
accountId: minorCreditorAccountId,
routeRoot: 'minor-creditor',
Expand All @@ -380,11 +380,10 @@ describe('Account Enquiry - Minor Creditor Header', () => {

it('AC1, AC2a: renders the Minor Creditor Account Header Summary', { tags: ['PO-1924'] }, () => {
const header = structuredClone(FINES_ACC_MINOR_CREDITOR_DETAILS_HEADER_MOCK);
header.has_associated_defendant = true;
header.awaiting_payout_amount = 100;
header.awarded_amount = 200;
header.paid_out_amount = 50;
header.outstanding_amount = 150;
header.financials.awaiting_payout = 100;
header.financials.awarded = 200;
header.financials.paid_out = 50;
header.financials.outstanding = 150;

interceptUserState(USER_STATE_MOCK_PERMISSION_BU77);
interceptMinorCreditorHeader(minorCreditorAccountId, header, '1');
Expand Down Expand Up @@ -416,8 +415,8 @@ describe('Account Enquiry - Minor Creditor Header', () => {

it('AC2b: hides Awarded and Outstanding when no defendant is associated', () => {
const header = structuredClone(FINES_ACC_MINOR_CREDITOR_DETAILS_HEADER_MOCK);
header.awaiting_payout_amount = 100;
header.paid_out_amount = 50;
header.financials.awaiting_payout = 100;
header.financials.paid_out = 50;

interceptUserState(USER_STATE_MOCK_PERMISSION_BU77);
interceptMinorCreditorHeader(minorCreditorAccountId, header, '1');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
<opal-lib-custom-account-information-item itemClasses="govuk-grid-column-one-quarter">
<h2 opal-lib-custom-account-information-item-label>Account type:</h2>
<p opal-lib-custom-account-information-item-value id="minor-creditor-account-type">
{{ accountData.creditor_account_type.display_name }}
{{ accountData.creditor.account_type.display_name }}
</p>
</opal-lib-custom-account-information-item>
<opal-lib-custom-account-information-item itemClasses="govuk-grid-column-one-quarter">
<h2 opal-lib-custom-account-information-item-label>Business Unit:</h2>
<p opal-lib-custom-account-information-item-value id="minor-creditor-business-unit">
{{ accountData.business_unit_summary.business_unit_name }} ({{
accountData.business_unit_summary.business_unit_id
}})
{{ accountData.business_unit.business_unit_name }} ({{ accountData.business_unit.business_unit_id }})
</p>
</opal-lib-custom-account-information-item>
</opal-lib-custom-account-information>
Expand All @@ -29,31 +27,31 @@ <h2 opal-lib-custom-account-information-item-label>Business Unit:</h2>
<hr class="govuk-section-break govuk-section-break--visible govuk-!-margin-bottom-3 govuk-!-margin-top-2" />

<opal-lib-custom-summary-metric-bar>
@if (accountData.has_associated_defendant) {
@if (accountData.creditor.has_associated_defendant) {
<opal-lib-custom-summary-metric-bar-item>
<p opal-lib-custom-summary-metric-bar-item-label>Awarded:</p>
<p opal-lib-custom-summary-metric-bar-item-value>
{{ accountData.awarded_amount | monetary }}
{{ accountData.financials.awarded | monetary }}
</p>
</opal-lib-custom-summary-metric-bar-item>
}
<opal-lib-custom-summary-metric-bar-item backgroundColour="govuk-lighter-blue-background-colour">
<p opal-lib-custom-summary-metric-bar-item-label textColour="govuk-dark-blue-text-colour">Paid out:</p>
<p opal-lib-custom-summary-metric-bar-item-value textColour="govuk-dark-blue-text-colour">
{{ accountData.paid_out_amount | monetary }}
{{ accountData.financials.paid_out | monetary }}
</p>
</opal-lib-custom-summary-metric-bar-item>
<opal-lib-custom-summary-metric-bar-item backgroundColour="govuk-lighter-blue-background-colour">
<p opal-lib-custom-summary-metric-bar-item-label textColour="govuk-dark-blue-text-colour">Awaiting payout:</p>
<p opal-lib-custom-summary-metric-bar-item-value textColour="govuk-dark-blue-text-colour">
{{ accountData.awaiting_payout_amount | monetary }}
{{ accountData.financials.awaiting_payout | monetary }}
</p>
</opal-lib-custom-summary-metric-bar-item>
@if (accountData.has_associated_defendant) {
@if (accountData.creditor.has_associated_defendant) {
<opal-lib-custom-summary-metric-bar-item backgroundColour="govuk-blue-background-colour">
<p opal-lib-custom-summary-metric-bar-item-label textColour="govuk-white-text-colour">Outstanding:</p>
<p opal-lib-custom-summary-metric-bar-item-value textColour="govuk-white-text-colour">
{{ accountData.outstanding_amount | monetary }}
{{ accountData.financials.outstanding | monetary }}
</p>
</opal-lib-custom-summary-metric-bar-item>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
export interface IOpalFinesAccountMinorCreditorDetailsHeader {
version: string | null;
creditor_account_id: number;
account_number: string;
creditor_account_type: {
type: string;
display_name: string;
};
business_unit_summary: {
business_unit_id: string;
business_unit_name: string;
welsh_speaking: string;
creditor: {
account_id: number;
account_number: string;
account_type: {
type: string;
display_name: string;
};
has_associated_defendant: boolean;
};
party_details: {
party: {
party_id: string;
organisation_flag: boolean;
organisation_details?: {
Expand All @@ -24,9 +22,15 @@ export interface IOpalFinesAccountMinorCreditorDetailsHeader {
surname: string;
};
};
awarded_amount: number;
paid_out_amount: number;
awaiting_payout_amount: number;
outstanding_amount: number;
has_associated_defendant: boolean;
business_unit: {
business_unit_id: string;
business_unit_name: string;
welsh_speaking: string;
};
financials: {
awarded: number;
paid_out: number;
awaiting_payout: number;
outstanding: number;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@ import { IOpalFinesAccountMinorCreditorDetailsHeader } from '../interfaces/fines

export const FINES_ACC_MINOR_CREDITOR_DETAILS_HEADER_MOCK: IOpalFinesAccountMinorCreditorDetailsHeader = {
version: null,
creditor_account_id: 99000000000800,
account_number: '87654321',
creditor_account_type: {
type: 'MN',
display_name: 'Minor Creditor',
creditor: {
account_id: 99000000000800,
account_number: '87654321',
account_type: {
type: 'MN',
display_name: 'Minor Creditor',
},
has_associated_defendant: false,
},
business_unit_summary: {
business_unit: {
business_unit_id: '77',
business_unit_name: 'Camberwell Green',
welsh_speaking: 'N',
},
party_details: {
party: {
party_id: '99000000000900',
organisation_flag: true,
organisation_details: {
organisation_name: 'Minor Creditor Test Ltd',
organisation_aliases: null,
},
},
awarded_amount: 0,
paid_out_amount: 0,
awaiting_payout_amount: 0,
outstanding_amount: 0,
has_associated_defendant: false,
financials: {
awarded: 0,
paid_out: 0,
awaiting_payout: 0,
outstanding: 0,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ describe('FinesAccPayloadService', () => {

it('should transform account header for store for a minor creditor (organisation)', () => {
mockMacPayloadService.getBusinessUnitBusinessUserId.mockReturnValue(
FINES_ACC_MINOR_CREDITOR_DETAILS_HEADER_MOCK.business_unit_summary.business_unit_id,
FINES_ACC_MINOR_CREDITOR_DETAILS_HEADER_MOCK.business_unit.business_unit_id,
);
const header: IOpalFinesAccountMinorCreditorDetailsHeader = structuredClone(
FINES_ACC_MINOR_CREDITOR_DETAILS_HEADER_MOCK,
Expand All @@ -230,63 +230,63 @@ describe('FinesAccPayloadService', () => {
const result: IFinesAccountState = service.transformAccountHeaderForStore(account_id, header, 'minorCreditor');

expect(result).toEqual({
account_number: header.account_number,
account_number: header.creditor.account_number,
account_id: account_id,
pg_party_id: null,
party_id: header.party_details.party_id,
party_type: header.creditor_account_type.display_name,
party_name: header.party_details.organisation_details?.organisation_name ?? null,
party_id: header.party.party_id,
party_type: header.creditor.account_type.display_name,
party_name: header.party.organisation_details?.organisation_name ?? null,
base_version: header.version,
business_unit_id: header.business_unit_summary.business_unit_id,
business_unit_user_id: header.business_unit_summary.business_unit_id,
welsh_speaking: header.business_unit_summary.welsh_speaking,
business_unit_id: header.business_unit.business_unit_id,
business_unit_user_id: header.business_unit.business_unit_id,
welsh_speaking: header.business_unit.welsh_speaking,
});

expect(mockMacPayloadService.getBusinessUnitBusinessUserId).toHaveBeenCalledWith(
Number(header.business_unit_summary.business_unit_id),
Number(header.business_unit.business_unit_id),
OPAL_USER_STATE_MOCK,
);
expect(mockGlobalStore.userState).toHaveBeenCalled();
});

it('should transform account header for store for a minor creditor (individual)', () => {
mockMacPayloadService.getBusinessUnitBusinessUserId.mockReturnValue(
FINES_ACC_MINOR_CREDITOR_DETAILS_HEADER_MOCK.business_unit_summary.business_unit_id,
FINES_ACC_MINOR_CREDITOR_DETAILS_HEADER_MOCK.business_unit.business_unit_id,
);
const header: IOpalFinesAccountMinorCreditorDetailsHeader = structuredClone(
FINES_ACC_MINOR_CREDITOR_DETAILS_HEADER_MOCK,
);
const account_id = 77;
header.party_details.organisation_flag = false;
header.party_details.individual_details = {
header.party.organisation_flag = false;
header.party.individual_details = {
title: 'Mr',
forenames: 'John',
surname: 'Doe',
};
delete header.party_details.organisation_details;
delete header.party.organisation_details;

const result: IFinesAccountState = service.transformAccountHeaderForStore(account_id, header, 'minorCreditor');

expect(result).toEqual({
account_number: header.account_number,
account_number: header.creditor.account_number,
account_id: account_id,
pg_party_id: null,
party_id: header.party_details.party_id,
party_type: header.creditor_account_type.display_name,
party_id: header.party.party_id,
party_type: header.creditor.account_type.display_name,
party_name:
header.party_details.individual_details?.title +
header.party.individual_details?.title +
' ' +
header.party_details.individual_details?.forenames +
header.party.individual_details?.forenames +
' ' +
header.party_details.individual_details?.surname?.toUpperCase(),
header.party.individual_details?.surname?.toUpperCase(),
base_version: header.version,
business_unit_id: header.business_unit_summary.business_unit_id,
business_unit_user_id: header.business_unit_summary.business_unit_id,
welsh_speaking: header.business_unit_summary.welsh_speaking,
business_unit_id: header.business_unit.business_unit_id,
business_unit_user_id: header.business_unit.business_unit_id,
welsh_speaking: header.business_unit.welsh_speaking,
});

expect(mockMacPayloadService.getBusinessUnitBusinessUserId).toHaveBeenCalledWith(
Number(header.business_unit_summary.business_unit_id),
Number(header.business_unit.business_unit_id),
OPAL_USER_STATE_MOCK,
);
expect(mockGlobalStore.userState).toHaveBeenCalled();
Expand Down
65 changes: 43 additions & 22 deletions src/app/flows/fines/fines-acc/services/fines-acc-payload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,50 +86,71 @@ export class FinesAccPayloadService {
headingData: IOpalFinesAccountDefendantDetailsHeader | IOpalFinesAccountMinorCreditorDetailsHeader,
partyType: 'defendant' | 'minorCreditor',
): IFinesAccountState {
// Build party_name safely
const party_name = headingData.party_details.organisation_flag
? (headingData.party_details.organisation_details?.organisation_name ?? '')
: [
headingData.party_details.individual_details?.title,
headingData.party_details.individual_details?.forenames,
headingData.party_details.individual_details?.surname
? headingData.party_details.individual_details.surname.toUpperCase()
: undefined,
]
.filter(Boolean)
.join(' ');

const business_unit_user_id = this.payloadService.getBusinessUnitBusinessUserId(
Number(headingData.business_unit_summary.business_unit_id),
this.globalStore.userState(),
);

let party_name: string;
let pg_party_id: string | null = null;
let party_type: string;
let party_id: string;
let account_number: string;
let business_unit_user_id: string | null;
let business_unit_id: string | null;
let business_unit_welsh_speaking: string | null;

if (partyType === 'defendant') {
const h = headingData as IOpalFinesAccountDefendantDetailsHeader;
pg_party_id = h.parent_guardian_party_id;
party_type = h.debtor_type;
party_id = h.defendant_account_party_id;
account_number = h.account_number;
party_name = h.party_details.organisation_flag
? (h.party_details.organisation_details?.organisation_name ?? '')
: [
h.party_details.individual_details?.title,
h.party_details.individual_details?.forenames,
h.party_details.individual_details?.surname
? h.party_details.individual_details.surname.toUpperCase()
: undefined,
]
.filter(Boolean)
.join(' ');
business_unit_user_id = this.payloadService.getBusinessUnitBusinessUserId(
Number(h.business_unit_summary.business_unit_id),
this.globalStore.userState(),
);
business_unit_id = h.business_unit_summary.business_unit_id;
business_unit_welsh_speaking = h.business_unit_summary.welsh_speaking;
} else {
const h = headingData as IOpalFinesAccountMinorCreditorDetailsHeader;
party_type = 'Minor Creditor';
party_id = h.party_details.party_id;
party_id = h.party.party_id;
account_number = h.creditor.account_number;
party_name = h.party.organisation_flag
? (h.party.organisation_details?.organisation_name ?? '')
: [
h.party.individual_details?.title,
h.party.individual_details?.forenames,
h.party.individual_details?.surname ? h.party.individual_details.surname.toUpperCase() : undefined,
]
.filter(Boolean)
.join(' ');
business_unit_user_id = this.payloadService.getBusinessUnitBusinessUserId(
Number(h.business_unit.business_unit_id),
this.globalStore.userState(),
);
business_unit_id = h.business_unit.business_unit_id;
business_unit_welsh_speaking = h.business_unit.welsh_speaking;
}

return {
account_number: headingData.account_number,
account_number,
account_id: Number(account_id),
pg_party_id,
party_id,
party_type,
party_name,
base_version: headingData.version,
business_unit_id: headingData.business_unit_summary.business_unit_id,
business_unit_id: business_unit_id,
business_unit_user_id,
welsh_speaking: headingData.business_unit_summary.welsh_speaking,
welsh_speaking: business_unit_welsh_speaking,
};
}

Expand Down