Skip to content
Open
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 @@ -12,4 +12,5 @@ enum 6123 "E-Document Source Type"
value(0; Customer) { Caption = 'Customer'; }
value(1; Vendor) { Caption = 'Vendor'; }
value(2; Location) { Caption = 'Location'; }
value(3; Company) { Caption = 'Company'; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace Microsoft.eServices.EDocument.Extensions;

using Microsoft.eServices.EDocument;
using Microsoft.eServices.EDocument.Service.Participant;
using Microsoft.Foundation.Company;

/// <summary>
/// A page extension for the Company Information page to show the E-Document service participation.
/// </summary>
pageextension 6165 "E-Doc. Company Information" extends "Company Information"
{
layout
{
addafter(GLN)
{
field("E-Document Service Participation Ids"; ParticipantIdCount)
{
ApplicationArea = All;
Caption = 'E-Document Service Participation';
DrillDown = true;
Editable = false;
ToolTip = 'Specifies the company participation for the E-Document services.';
Visible = EDocumentServiceExists;

trigger OnDrillDown()
begin
ServiceParticipant.RunServiceParticipantPage(Enum::"E-Document Source Type"::Company, '');
end;
}
}
}


var
ServiceParticipant: Codeunit "Service Participant";
ParticipantIdCount: Integer;
EDocumentServiceExists: Boolean;


trigger OnAfterGetCurrRecord()
begin
if TryGetEDocumentServiceParticipation() then;
end;

[TryFunction]
local procedure TryGetEDocumentServiceParticipation()
var
EDocumentService: Record "E-Document Service";
begin
EDocumentServiceExists := not EDocumentService.IsEmpty();
ParticipantIdCount := ServiceParticipant.GetParticipantIdCount(Enum::"E-Document Source Type"::Company, '');
end;

}
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ codeunit 6109 "E-Document Import Helper"
LineDiscountAmountFieldRef.Value(LineDiscountAmount);
end;

/// <summary>
/// Use it to check if receiving company information is in line with Company Information.
/// Also checks if the Receiving Company Id matches a Company Service Participant.
/// </summary>
/// <param name="EDocument">The E-Document record.</param>
/// <param name="EDocService">The E-Document Service record to match against.</param>
procedure ValidateReceivingCompanyInfo(EDocument: Record "E-Document"; EDocService: Record "E-Document Service")
begin
// First, check if the Receiving Company Id matches a Company Service Participant
if MatchCompanyByServiceParticipant(EDocument, EDocService) then
exit;

ValidateReceivingCompanyInfo(EDocument);
end;

/// <summary>
/// Use it to check if receiving company information is in line with Company Information.
/// </summary>
Expand All @@ -281,6 +296,25 @@ codeunit 6109 "E-Document Import Helper"
EDocErrorHelper.LogErrorMessage(EDocument, CompanyInformation, CompanyInformation.FieldNo("VAT Registration No."), StrSubstNo(InvalidCompanyInfoVATRegNoErr, EDocument."Receiving Company VAT Reg. No."));
end;

/// <summary>
/// Use it to check if receiving company information matches a Company Service Participant for a specific service.
/// </summary>
/// <param name="EDocument">The E-Document record.</param>
/// <param name="EDocService">The E-Document Service record to match against.</param>
/// <returns>True if a matching Company Service Participant is found.</returns>
local procedure MatchCompanyByServiceParticipant(EDocument: Record "E-Document"; EDocService: Record "E-Document Service"): Boolean
var
ServiceParticipant: Record "Service Participant";
begin
if EDocument."Receiving Company Id" = '' then
exit(false);

ServiceParticipant.SetRange("Participant Type", ServiceParticipant."Participant Type"::Company);
ServiceParticipant.SetRange("Participant Identifier", EDocument."Receiving Company Id");
ServiceParticipant.SetRange(Service, EDocService.Code);
exit(not ServiceParticipant.IsEmpty());
end;

/// <summary>
/// Use it to check if receiving company name and address is in line with Company Information.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ codeunit 6140 "E-Doc. Import"
EDocErrorHelper.LogWarningMessage(EDocument, EDocument2, EDocument2.FieldNo("Incoming E-Document No."), DocAlreadyExistsMsg);

if EDocService."Validate Receiving Company" then
EDocImportHelper.ValidateReceivingCompanyInfo(EDocument);
EDocImportHelper.ValidateReceivingCompanyInfo(EDocument, EDocService);
end else
EDocErrorHelper.LogSimpleErrorMessage(EDocument, GetLastErrorText());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
namespace Microsoft.eServices.EDocument.Test;

using Microsoft.eServices.EDocument;
using Microsoft.eServices.EDocument.Integration;
using Microsoft.eServices.EDocument.Service.Participant;
using Microsoft.Foundation.Company;
using Microsoft.Purchases.Document;

codeunit 139799 "E-Doc. Helper Test"
{
Subtype = Test;
Access = Internal;
TestPermissions = Disabled;

var
Assert: Codeunit "Assert";
LibraryEDoc: Codeunit "Library - E-Document";
LibraryLowerPermission: Codeunit "Library - Lower Permissions";

trigger OnRun()
begin
Expand Down Expand Up @@ -48,4 +54,82 @@ codeunit 139799 "E-Doc. Helper Test"
VendorNo := EDocumentImportHelper.FindVendor('', '', '');
Assert.IsTrue(VendorNo = '', 'Vendor No. should be empty');
end;

[Test]
procedure ValidateReceivingCompanyInfoWithMatchingServiceParticipant()
var
EDocument: Record "E-Document";
EDocService: Record "E-Document Service";
ServiceParticipant: Record "Service Participant";
EDocumentImportHelper: Codeunit "E-Document Import Helper";
EDocErrorHelper: Codeunit "E-Document Error Helper";
TestParticipantId: Text[200];
begin
LibraryLowerPermission.SetOutsideO365Scope();
// [SCENARIO] Validation should succeed when a matching Company Service Participant exists
// [GIVEN] An E-Document with a Receiving Company Id
TestParticipantId := '0208:1234567890';
EDocument.Init();
EDocument."Entry No" := 0;
EDocument."Receiving Company Id" := TestParticipantId;
EDocument."Receiving Company GLN" := '';
EDocument."Receiving Company VAT Reg. No." := '';
EDocument.Insert(true);

// [GIVEN] An E-Document Service
LibraryEDoc.CreateTestReceiveServiceForEDoc(EDocService, Enum::"Service Integration"::"Mock");

// [GIVEN] A matching Company Service Participant
ServiceParticipant.Init();
ServiceParticipant.Service := EDocService.Code;
ServiceParticipant."Participant Type" := ServiceParticipant."Participant Type"::Company;
ServiceParticipant.Participant := '';
ServiceParticipant."Participant Identifier" := TestParticipantId;
ServiceParticipant.Insert(true);

// [WHEN] Validating receiving company info
EDocumentImportHelper.ValidateReceivingCompanyInfo(EDocument, EDocService);

// [THEN] No errors should be logged (validation should exit early due to Service Participant match)
Assert.IsFalse(EDocErrorHelper.HasErrors(EDocument), 'No errors should be logged when Service Participant matches');

// Cleanup
ServiceParticipant.Delete();
EDocument.Delete();
end;

[Test]
procedure ValidateReceivingCompanyInfoFallsBackToVATWhenNoServiceParticipant()
var
EDocument: Record "E-Document";
EDocService: Record "E-Document Service";
CompanyInformation: Record "Company Information";
EDocumentImportHelper: Codeunit "E-Document Import Helper";
EDocErrorHelper: Codeunit "E-Document Error Helper";
begin
LibraryLowerPermission.SetOutsideO365Scope();
// [SCENARIO] Validation should fall back to VAT/GLN matching when no Service Participant exists
// [GIVEN] An E-Document with a Receiving Company Id that doesn't match any Service Participant
// [GIVEN] But has matching VAT Registration No.
CompanyInformation.Get();

EDocument.Init();
EDocument."Entry No" := 0;
EDocument."Receiving Company Id" := '0208:NOMATCH';
EDocument."Receiving Company VAT Reg. No." := CompanyInformation."VAT Registration No.";
EDocument."Receiving Company GLN" := '';
EDocument.Insert(true);

// [GIVEN] An E-Document Service with no matching Company Service Participant
LibraryEDoc.CreateTestReceiveServiceForEDoc(EDocService, Enum::"Service Integration"::"Mock");

// [WHEN] Validating receiving company info
EDocumentImportHelper.ValidateReceivingCompanyInfo(EDocument, EDocService);

// [THEN] No errors should be logged (validation should succeed via VAT matching)
Assert.IsFalse(EDocErrorHelper.HasErrors(EDocument), 'No errors should be logged when VAT Registration No. matches');

// Cleanup
EDocument.Delete();
end;
}
Loading