Skip to content

Commit 8f30c2f

Browse files
CopilotGroenbech96Magnus Hartvig Grønbech
authored
Add Service Participants support for Company Information (#6372)
## Add Service Participants to Company Information This PR enables Belgian companies using Peppol to configure Service Participants on Company Information, so that incoming eDocuments using Peppol Scheme 0208 (Enterprise Number) are correctly matched and received. ### Changes Made - [x] **1. Extend E-Document Source Type Enum** - Added "Company" value (value 3) to enum 6123 "E-Document Source Type" - [x] **2. Add Page Extension for Company Information** - Created page extension 6165 for Company Information page - Added "E-Document Service Participation" field similar to Customer/Vendor extensions - Field shows count of Service Participants and drills down to the list - Uses empty string ('') as Participant code since Company Information is a singleton - [x] **3. Update Matching Logic (Backward Compatible)** - Added new overload `ValidateReceivingCompanyInfo(EDocument, EDocService)` that checks Service Participants first - Preserved original `ValidateReceivingCompanyInfo(EDocument)` signature for backward compatibility - New overload calls the original method after Service Participant check - `MatchCompanyByServiceParticipant` takes `EDocService` record parameter - Updated call site in EDocImport to pass `EDocService` record - Priority order: Service Participant ÔåÆ VAT Reg No. ÔåÆ GLN ÔåÆ Name/Address - [x] **4. Add Tests** - Added `ValidateReceivingCompanyInfoWithMatchingServiceParticipant` test: Verifies validation succeeds when a matching Company Service Participant exists - Added `ValidateReceivingCompanyInfoFallsBackToVATWhenNoServiceParticipant` test: Verifies fallback to VAT/GLN matching when no Service Participant matches - [x] **5. Fix Build Warnings/Errors** - Fixed AA0175: Use `IsEmpty()` instead of `FindFirst()` when only checking record existence - Fixed AL0118: Added missing `using Microsoft.eServices.EDocument.Integration;` for `Service Integration` enum - Fixed test permissions: Added `TestPermissions = Disabled;` to allow E-Document table inserts during tests <!-- START COPILOT CODING AGENT TIPS --> --- Ô£¿ Let Copilot coding agent [set things up for you](https://github.com/microsoft/BCApps/issues/new?title=Ô£¿+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) ÔÇö coding agent works faster and does higher quality work when set up for your repo. Fixes [AB#620793](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/620793) --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Groenbech96 <17690329+Groenbech96@users.noreply.github.com> Co-authored-by: Magnus Hartvig Grønbech <magnushar@microsoft.com>
1 parent ad923d7 commit 8f30c2f

5 files changed

Lines changed: 179 additions & 1 deletion

File tree

src/Apps/W1/EDocument/App/src/Document/EDocumentSourceType.Enum.al

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ enum 6123 "E-Document Source Type"
1212
value(0; Customer) { Caption = 'Customer'; }
1313
value(1; Vendor) { Caption = 'Vendor'; }
1414
value(2; Location) { Caption = 'Location'; }
15+
value(3; Company) { Caption = 'Company'; }
1516
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// ------------------------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License. See License.txt in the project root for license information.
4+
// ------------------------------------------------------------------------------------------------
5+
6+
namespace Microsoft.eServices.EDocument.Extensions;
7+
8+
using Microsoft.eServices.EDocument;
9+
using Microsoft.eServices.EDocument.Service.Participant;
10+
using Microsoft.Foundation.Company;
11+
12+
/// <summary>
13+
/// A page extension for the Company Information page to show the E-Document service participation.
14+
/// </summary>
15+
pageextension 6165 "E-Doc. Company Information" extends "Company Information"
16+
{
17+
layout
18+
{
19+
addafter(GLN)
20+
{
21+
field("E-Document Service Participation Ids"; ParticipantIdCount)
22+
{
23+
ApplicationArea = All;
24+
Caption = 'E-Document Service Participation';
25+
DrillDown = true;
26+
Editable = false;
27+
ToolTip = 'Specifies the company participation for the E-Document services.';
28+
Visible = EDocumentServiceExists;
29+
30+
trigger OnDrillDown()
31+
begin
32+
ServiceParticipant.RunServiceParticipantPage(Enum::"E-Document Source Type"::Company, '');
33+
end;
34+
}
35+
}
36+
}
37+
38+
39+
var
40+
ServiceParticipant: Codeunit "Service Participant";
41+
ParticipantIdCount: Integer;
42+
EDocumentServiceExists: Boolean;
43+
44+
45+
trigger OnAfterGetCurrRecord()
46+
begin
47+
if TryGetEDocumentServiceParticipation() then;
48+
end;
49+
50+
[TryFunction]
51+
local procedure TryGetEDocumentServiceParticipation()
52+
var
53+
EDocumentService: Record "E-Document Service";
54+
begin
55+
EDocumentServiceExists := not EDocumentService.IsEmpty();
56+
ParticipantIdCount := ServiceParticipant.GetParticipantIdCount(Enum::"E-Document Source Type"::Company, '');
57+
end;
58+
59+
}

src/Apps/W1/EDocument/App/src/Helpers/EDocumentImportHelper.Codeunit.al

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,21 @@ codeunit 6109 "E-Document Import Helper"
256256
LineDiscountAmountFieldRef.Value(LineDiscountAmount);
257257
end;
258258

259+
/// <summary>
260+
/// Use it to check if receiving company information is in line with Company Information.
261+
/// Also checks if the Receiving Company Id matches a Company Service Participant.
262+
/// </summary>
263+
/// <param name="EDocument">The E-Document record.</param>
264+
/// <param name="EDocService">The E-Document Service record to match against.</param>
265+
procedure ValidateReceivingCompanyInfo(EDocument: Record "E-Document"; EDocService: Record "E-Document Service")
266+
begin
267+
// First, check if the Receiving Company Id matches a Company Service Participant
268+
if MatchCompanyByServiceParticipant(EDocument, EDocService) then
269+
exit;
270+
271+
ValidateReceivingCompanyInfo(EDocument);
272+
end;
273+
259274
/// <summary>
260275
/// Use it to check if receiving company information is in line with Company Information.
261276
/// </summary>
@@ -281,6 +296,25 @@ codeunit 6109 "E-Document Import Helper"
281296
EDocErrorHelper.LogErrorMessage(EDocument, CompanyInformation, CompanyInformation.FieldNo("VAT Registration No."), StrSubstNo(InvalidCompanyInfoVATRegNoErr, EDocument."Receiving Company VAT Reg. No."));
282297
end;
283298

299+
/// <summary>
300+
/// Use it to check if receiving company information matches a Company Service Participant for a specific service.
301+
/// </summary>
302+
/// <param name="EDocument">The E-Document record.</param>
303+
/// <param name="EDocService">The E-Document Service record to match against.</param>
304+
/// <returns>True if a matching Company Service Participant is found.</returns>
305+
local procedure MatchCompanyByServiceParticipant(EDocument: Record "E-Document"; EDocService: Record "E-Document Service"): Boolean
306+
var
307+
ServiceParticipant: Record "Service Participant";
308+
begin
309+
if EDocument."Receiving Company Id" = '' then
310+
exit(false);
311+
312+
ServiceParticipant.SetRange("Participant Type", ServiceParticipant."Participant Type"::Company);
313+
ServiceParticipant.SetRange("Participant Identifier", EDocument."Receiving Company Id");
314+
ServiceParticipant.SetRange(Service, EDocService.Code);
315+
exit(not ServiceParticipant.IsEmpty());
316+
end;
317+
284318
/// <summary>
285319
/// Use it to check if receiving company name and address is in line with Company Information.
286320
/// </summary>

src/Apps/W1/EDocument/App/src/Processing/EDocImport.Codeunit.al

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ codeunit 6140 "E-Doc. Import"
282282
EDocErrorHelper.LogWarningMessage(EDocument, EDocument2, EDocument2.FieldNo("Incoming E-Document No."), DocAlreadyExistsMsg);
283283

284284
if EDocService."Validate Receiving Company" then
285-
EDocImportHelper.ValidateReceivingCompanyInfo(EDocument);
285+
EDocImportHelper.ValidateReceivingCompanyInfo(EDocument, EDocService);
286286
end else
287287
EDocErrorHelper.LogSimpleErrorMessage(EDocument, GetLastErrorText());
288288

src/Apps/W1/EDocument/Test/src/Receive/EDocHelperTest.Codeunit.al

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
namespace Microsoft.eServices.EDocument.Test;
66

77
using Microsoft.eServices.EDocument;
8+
using Microsoft.eServices.EDocument.Integration;
9+
using Microsoft.eServices.EDocument.Service.Participant;
10+
using Microsoft.Foundation.Company;
811
using Microsoft.Purchases.Document;
912

1013
codeunit 139799 "E-Doc. Helper Test"
1114
{
1215
Subtype = Test;
1316
Access = Internal;
17+
TestPermissions = Disabled;
1418

1519
var
1620
Assert: Codeunit "Assert";
21+
LibraryEDoc: Codeunit "Library - E-Document";
22+
LibraryLowerPermission: Codeunit "Library - Lower Permissions";
1723

1824
trigger OnRun()
1925
begin
@@ -48,4 +54,82 @@ codeunit 139799 "E-Doc. Helper Test"
4854
VendorNo := EDocumentImportHelper.FindVendor('', '', '');
4955
Assert.IsTrue(VendorNo = '', 'Vendor No. should be empty');
5056
end;
57+
58+
[Test]
59+
procedure ValidateReceivingCompanyInfoWithMatchingServiceParticipant()
60+
var
61+
EDocument: Record "E-Document";
62+
EDocService: Record "E-Document Service";
63+
ServiceParticipant: Record "Service Participant";
64+
EDocumentImportHelper: Codeunit "E-Document Import Helper";
65+
EDocErrorHelper: Codeunit "E-Document Error Helper";
66+
TestParticipantId: Text[200];
67+
begin
68+
LibraryLowerPermission.SetOutsideO365Scope();
69+
// [SCENARIO] Validation should succeed when a matching Company Service Participant exists
70+
// [GIVEN] An E-Document with a Receiving Company Id
71+
TestParticipantId := '0208:1234567890';
72+
EDocument.Init();
73+
EDocument."Entry No" := 0;
74+
EDocument."Receiving Company Id" := TestParticipantId;
75+
EDocument."Receiving Company GLN" := '';
76+
EDocument."Receiving Company VAT Reg. No." := '';
77+
EDocument.Insert(true);
78+
79+
// [GIVEN] An E-Document Service
80+
LibraryEDoc.CreateTestReceiveServiceForEDoc(EDocService, Enum::"Service Integration"::"Mock");
81+
82+
// [GIVEN] A matching Company Service Participant
83+
ServiceParticipant.Init();
84+
ServiceParticipant.Service := EDocService.Code;
85+
ServiceParticipant."Participant Type" := ServiceParticipant."Participant Type"::Company;
86+
ServiceParticipant.Participant := '';
87+
ServiceParticipant."Participant Identifier" := TestParticipantId;
88+
ServiceParticipant.Insert(true);
89+
90+
// [WHEN] Validating receiving company info
91+
EDocumentImportHelper.ValidateReceivingCompanyInfo(EDocument, EDocService);
92+
93+
// [THEN] No errors should be logged (validation should exit early due to Service Participant match)
94+
Assert.IsFalse(EDocErrorHelper.HasErrors(EDocument), 'No errors should be logged when Service Participant matches');
95+
96+
// Cleanup
97+
ServiceParticipant.Delete();
98+
EDocument.Delete();
99+
end;
100+
101+
[Test]
102+
procedure ValidateReceivingCompanyInfoFallsBackToVATWhenNoServiceParticipant()
103+
var
104+
EDocument: Record "E-Document";
105+
EDocService: Record "E-Document Service";
106+
CompanyInformation: Record "Company Information";
107+
EDocumentImportHelper: Codeunit "E-Document Import Helper";
108+
EDocErrorHelper: Codeunit "E-Document Error Helper";
109+
begin
110+
LibraryLowerPermission.SetOutsideO365Scope();
111+
// [SCENARIO] Validation should fall back to VAT/GLN matching when no Service Participant exists
112+
// [GIVEN] An E-Document with a Receiving Company Id that doesn't match any Service Participant
113+
// [GIVEN] But has matching VAT Registration No.
114+
CompanyInformation.Get();
115+
116+
EDocument.Init();
117+
EDocument."Entry No" := 0;
118+
EDocument."Receiving Company Id" := '0208:NOMATCH';
119+
EDocument."Receiving Company VAT Reg. No." := CompanyInformation."VAT Registration No.";
120+
EDocument."Receiving Company GLN" := '';
121+
EDocument.Insert(true);
122+
123+
// [GIVEN] An E-Document Service with no matching Company Service Participant
124+
LibraryEDoc.CreateTestReceiveServiceForEDoc(EDocService, Enum::"Service Integration"::"Mock");
125+
126+
// [WHEN] Validating receiving company info
127+
EDocumentImportHelper.ValidateReceivingCompanyInfo(EDocument, EDocService);
128+
129+
// [THEN] No errors should be logged (validation should succeed via VAT matching)
130+
Assert.IsFalse(EDocErrorHelper.HasErrors(EDocument), 'No errors should be logged when VAT Registration No. matches');
131+
132+
// Cleanup
133+
EDocument.Delete();
134+
end;
51135
}

0 commit comments

Comments
 (0)