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,17 @@ 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 electronic document payment status.';
}
field("Paid Amount"; Rec."Paid Amount")
{
Visible = false;
}
}
group(ReceivingCompanyInfo)
{
Expand Down Expand Up @@ -346,6 +359,35 @@ 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;
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
10 changes: 9 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,14 @@ 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")));
ToolTip = 'Specifies the amount that has already been paid.';
}
}
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,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,61 @@
// ------------------------------------------------------------------------------------------------
// 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 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;

/// <summary>
/// Sets the global variable PaymentContext.
/// </summary>
/// <param name="PaymentContext">Payment context codeunit.</param>
procedure SetContext(PaymentContext: Codeunit PaymentContext)
GMatuleviciute marked this conversation as resolved.
Show resolved Hide resolved
begin
this.PaymentContext := PaymentContext;
end;

/// <summary>
/// Sets the IDocumentPaymentHandler instance.
/// </summary>
/// <param name="PaymentHandler">IDocumentPaymentHandler implementation used for receiving payment details.</param>
procedure SetInstance(PaymentHandler: Interface IDocumentPaymentHandler)
GMatuleviciute marked this conversation as resolved.
Show resolved Hide resolved
begin
this.IDocumentPaymentHandler := PaymentHandler;
end;


/// <summary>
/// Sets the parameters for the payment information receiving.
/// </summary>
/// <param name="EDocument">Electronic document for which payment is received.</param>
/// <param name="EDocumentService">Service for receiving payments.</param>
/// <param name="PaymentMetadata">TempBlob which contains received payment information.</param>
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,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;

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>
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
// 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,73 @@
// ------------------------------------------------------------------------------------------------
// 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>
/// <returns>codeunit Http Message State that contains http request and response messages.</returns>
procedure Http(): Codeunit "Http Message State"
begin
exit(this.HttpMessageState);
end;

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

/// <summary>
/// Retrieves the payment amount.
/// </summary>
/// <returns>Amount of the payment.</returns>
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>
/// <param name="Date">Date when the payment was made.</param>
/// <param name="Amount">Amount of the payment.</param>
procedure SetPaymentInformation(Date: Date; Amount: Decimal)
begin
this.Date := Date;
this.Amount := Amount;
end;

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

/// <summary>
/// Sets the payment status.
/// </summary>
/// <param name="NewPaymentStatus">New payment status.</param>
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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// ------------------------------------------------------------------------------------------------
// 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