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

[E-Document Core] - Extending the Core app with payments #5

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
88 changes: 88 additions & 0 deletions Apps/W1/EDocument/app/src/Document/EDocument.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ using Microsoft.eServices.EDocument.Integration.Receive;
using Microsoft.Bank.Reconciliation;
using Microsoft.eServices.EDocument.OrderMatch;
using Microsoft.eServices.EDocument.OrderMatch.Copilot;
using Microsoft.eServices.EDocument.Integration.Payments;
using Microsoft.eServices.EDocument.Payments;

page 6121 "E-Document"
{
Expand Down Expand Up @@ -119,6 +121,18 @@ page 6121 "E-Document"
Importance = Additional;
ToolTip = 'Specifies the electronic document posting date.';
}
field("Payment Status"; this.PaymentStatus)
{
Caption = 'Payment Status';
Visible = false;
Editable = false;
ToolTip = 'Specifies the payment status of the electronic document.';
}
field("Paid Amount"; Rec."Paid Amount")
{
Visible = false;
ToolTip = 'Specifies the paid amount of the electronic document.';
GMatuleviciute marked this conversation as resolved.
Show resolved Hide resolved
}
}
group(ReceivingCompanyInfo)
{
Expand Down Expand Up @@ -346,6 +360,34 @@ page 6121 "E-Document"
end;
}
}
group(Payments)
{
Caption = 'Payments';
action(ReceivePayments)
GMatuleviciute marked this conversation as resolved.
Show resolved Hide resolved
{
Caption = 'Receive Payments';
ToolTip = 'Receive payments for the electronic document.';
Image = Payment;
Visible = false;

trigger OnAction()
begin
this.ReceivePaymentsForEDoc();
end;
}
action(SendPayments)
{
Caption = 'Send Payment';
ToolTip = 'Send payment for the electronic document.';
Image = Payment;
Visible = false;

trigger OnAction()
begin
this.SendPaymentsForEDoc();
end;
}
}
group(Troubleshoot)
{
Caption = 'Troubleshoot';
Expand Down Expand Up @@ -507,6 +549,8 @@ page 6121 "E-Document"
SetIncomingDocActions();

EDocImport.ProcessEDocPendingOrderMatch(Rec);

this.SetPaymentStatus();
end;

local procedure SetStyle()
Expand Down Expand Up @@ -589,13 +633,57 @@ page 6121 "E-Document"
ShowRelink := false;
end;

local procedure SetPaymentStatus()
begin
if Rec."Paid Amount" = 0 then
this.PaymentStatus := this.PaymentStatus::"Not Paid"
else
if Rec."Paid Amount" < Rec."Amount Incl. VAT" then
this.PaymentStatus := this.PaymentStatus::"Partially Paid"
else
this.PaymentStatus := this.PaymentStatus::Paid
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.PaymentStatus := this.PaymentStatus::Paid; ( ; is missing)

end;

local procedure ReceivePaymentsForEDoc()
var
EDocService: Record "E-Document Service";
PaymentContext: Codeunit PaymentContext;
PaymentIntegrationManagement: Codeunit "Payment Integration Management";
EDocServices: Page "E-Document Services";
begin
EDocServices.LookupMode(true);
if EDocServices.RunModal() <> Action::LookupOK then
exit;

EDocServices.GetRecord(EDocService);
this.EDocumentErrorHelper.ClearPaymentErrorMessages(Rec);
PaymentIntegrationManagement.ReceivePayments(Rec, EDocService, PaymentContext);
end;

local procedure SendPaymentsForEDoc()
var
EDocService: Record "E-Document Service";
PaymentContext: Codeunit PaymentContext;
PaymentIntegrationManagement: Codeunit "Payment Integration Management";
EDocServices: Page "E-Document Services";
begin
EDocServices.LookupMode(true);
if EDocServices.RunModal() <> Action::LookupOK then
exit;

EDocServices.GetRecord(EDocService);
this.EDocumentErrorHelper.ClearPaymentErrorMessages(Rec);
PaymentIntegrationManagement.SendPayments(Rec, EDocService, PaymentContext);
end;

var
EDocumentBackgroundjobs: Codeunit "E-Document Background Jobs";
EDocIntegrationManagement: Codeunit "E-Doc. Integration Management";
EDocImport: Codeunit "E-Doc. Import";
EDocumentErrorHelper: Codeunit "E-Document Error Helper";
EDocumentHelper: Codeunit "E-Document Processing";
ErrorsAndWarningsNotification: Notification;
PaymentStatus: Enum "E-Document Payment Progress";
RecordLinkTxt, StyleStatusTxt : Text;
ShowRelink, ShowMapToOrder, HasErrorsOrWarnings, HasErrors, IsIncomingDoc, IsProcessed, CopilotVisible : Boolean;
EDocHasErrorOrWarningMsg: Label 'Errors or warnings found for E-Document. Please review below in "Error Messages" section.';
Expand Down
9 changes: 8 additions & 1 deletion Apps/W1/EDocument/app/src/Document/EDocument.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using System.Automation;
using System.IO;
using System.Reflection;
using System.Threading;
using Microsoft.eServices.EDocument.Payments;

table 6121 "E-Document"
{
Expand Down Expand Up @@ -182,7 +183,13 @@ table 6121 "E-Document"
Caption = 'Receiving Company Id';
ToolTip = 'Specifies the receiving company id, such as PEPPOL id, or other identifiers used in the electronic document exchange.';
}

field(32; "Paid Amount"; Decimal)
{
Caption = 'Paid Amount';
Editable = false;
FieldClass = FlowField;
CalcFormula = sum("E-Document Payment".Amount where("E-Document Entry No." = field("Entry No")));
}
}
keys
{
Expand Down
14 changes: 14 additions & 0 deletions Apps/W1/EDocument/app/src/Helpers/EDocumentErrorHelper.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.eServices.EDocument;

using System.Telemetry;
using System.Utilities;
using Microsoft.eServices.EDocument.Payments;

codeunit 6115 "E-Document Error Helper"
{
Expand Down Expand Up @@ -105,6 +106,19 @@ codeunit 6115 "E-Document Error Helper"
ErrorMessage.LogSimpleMessage(ErrorMessage."Message Type"::Error, Message);
end;

/// <summary>
/// Use it to clear errors for E-Document related to payments.
GMatuleviciute marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <param name="EDocument">The E-Document record.</param>
procedure ClearPaymentErrorMessages(EDocument: Record "E-Document")
var
ErrorMessage: Record "Error Message";
begin
ErrorMessage.SetRange("Context Record ID", EDocument.RecordId());
ErrorMessage.SetRange("Table Number", Database::"E-Document Payment");
ErrorMessage.DeleteAll(false);
end;

internal procedure GetTelemetryImplErrLbl(): Text
begin
exit(EDocTelemetryImplErr);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// ------------------------------------------------------------------------------------------------
// 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.Integration.Payments;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one feels like it should be under Integration/Payments/Implementations instead

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, the actual file path


using Microsoft.eServices.EDocument;
using Microsoft.eServices.EDocument.Integration.Interfaces;
using Microsoft.eServices.EDocument.Payments;
using System.Utilities;

/// <summary>
/// This codeunit is used to provide a default implementation for the "Document Payment Handler" interface.
/// </summary>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action Invoker?

codeunit 6105 "Empty Payment Handler" implements IDocumentPaymentHandler
{
Access = Internal;
InherentEntitlements = X;
InherentPermissions = X;

procedure Send(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentContext: Codeunit PaymentContext)
begin
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, preference: I prefer to see a // Do nothing comment within these placeholder implementations as it makes it clear this is intentionally empty.

// This method serves as a placeholder implementation for the IDocumentPaymentHandler interface.
end;

procedure Receive(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var PaymentsMetadata: Codeunit "Temp Blob List"; PaymentContext: Codeunit PaymentContext)
begin
// This method serves as a placeholder implementation for the IDocumentPaymentHandler interface.
end;

procedure GetDetails(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob"; PaymentContext: Codeunit PaymentContext)
begin
// This method serves as a placeholder implementation for the IDocumentPaymentHandler interface.
end;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ------------------------------------------------------------------------------------------------
// 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.Integration.Interfaces;

using Microsoft.eServices.EDocument;
using Microsoft.eServices.EDocument.Integration.Payments;
using System.Utilities;

/// <summary>
/// Interface for sending and receiving payment information for E-Documents using E-Document service
/// </summary>
interface IDocumentPaymentHandler
{
procedure Send(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentContext: Codeunit PaymentContext)

procedure Receive(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var PaymentsMetadata: Codeunit "Temp Blob List"; PaymentContext: Codeunit PaymentContext)

procedure GetDetails(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob"; PaymentContext: Codeunit PaymentContext)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ------------------------------------------------------------------------------------------------
// 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.Integration.Payments;


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One empty line should be between namespace and using

using System.Utilities;
using Microsoft.eServices.EDocument;
using Microsoft.eServices.EDocument.Integration.Interfaces;

codeunit 6107 "Get Payment Details"
{
Access = Internal;
InherentEntitlements = X;
InherentPermissions = X;

trigger OnRun()
begin
this.EDocumentService.TestField(Code);
this.IDocumentPaymentHandler.GetDetails(this.EDocument, this.EDocumentService, this.PaymentMetadata, this.PaymentContext);
end;

procedure SetContext(PaymentContext: Codeunit PaymentContext)
GMatuleviciute marked this conversation as resolved.
Show resolved Hide resolved
begin
this.PaymentContext := PaymentContext;
end;

procedure SetInstance(PaymentHandler: Interface IDocumentPaymentHandler)
GMatuleviciute marked this conversation as resolved.
Show resolved Hide resolved
begin
this.IDocumentPaymentHandler := PaymentHandler;
end;

procedure SetParameters(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob")
begin
this.EDocument.Copy(EDocument);
this.EDocumentService.Copy(EDocumentService);
this.PaymentMetadata := PaymentMetadata;
end;

var
EDocument: Record "E-Document";
EDocumentService: Record "E-Document Service";
PaymentMetadata: Codeunit "Temp Blob";
PaymentContext: Codeunit PaymentContext;
IDocumentPaymentHandler: Interface IDocumentPaymentHandler;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// ------------------------------------------------------------------------------------------------
// 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.Integration.Payments;

using Microsoft.eServices.EDocument.Integration;
using Microsoft.eServices.EDocument.Payments;

codeunit 6104 PaymentContext
{
/// <summary>
/// Get the Http Message State codeunit.
/// </summary>
procedure Http(): Codeunit "Http Message State"
begin
exit(this.HttpMessageState);
end;

/// <summary>
/// Retrieves the payment date.
/// </summary>
procedure GetDate(): Date
begin
exit(this.Date);
end;

/// <summary>
/// Retrieves the payment amount.
/// </summary>
procedure GetAmount(): Decimal
GMatuleviciute marked this conversation as resolved.
Show resolved Hide resolved
begin
exit(this.Amount);
end;

/// <summary>
/// Sets the payment date and amount.
/// </summary>
procedure SetPaymentInformation(Date: Date; Amount: Decimal)
begin
this.Date := Date;
this.Amount := Amount;
end;

/// <summary>
/// Retrieves the payment status.
/// </summary>
procedure GetPaymentStatus(): Enum "Payment Status"
begin
exit(this.PaymentStatus);
end;

/// <summary>
/// Sets the payment status.
/// </summary>
procedure SetPaymentStatus(NewPaymentStatus: Enum "Payment Status")
begin
this.PaymentStatus := NewPaymentStatus;
end;

var
HttpMessageState: Codeunit "Http Message State";
PaymentStatus: Enum "Payment Status";
Date: Date;
Amount: Decimal;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the empty line before the global variables and object closing bracket

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// ------------------------------------------------------------------------------------------------
// 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.Integration.Payments;
using Microsoft.eServices.EDocument.Integration.Interfaces;
GMatuleviciute marked this conversation as resolved.
Show resolved Hide resolved

enum 6105 "Payment Integration" implements IDocumentPaymentHandler
{
Extensible = true;
Access = Public;

value(0; "No Integration")
{
Caption = 'No Integration';
Implementation = IDocumentPaymentHandler = "Empty Payment Handler";
}
}
Loading