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-Documents Core] - E-Invoice Preview FastTab #10

Closed
wants to merge 8 commits into from
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 @@ -28,6 +28,7 @@ permissionset 6100 "E-Doc. Core - Objects"
table "E-Doc. Imported Line" = X,
table "E-Doc. PO Match Prop. Buffer" = X,
table "Service Participant" = X,
table "E-Invoice Line" = X,
codeunit "E-Document Import Job" = X,
codeunit "E-Doc. Integration Management" = X,
codeunit "E-Doc. Mapping" = X,
Expand Down Expand Up @@ -91,5 +92,6 @@ permissionset 6100 "E-Doc. Core - Objects"
page "E-Doc. PO Copilot Prop" = X,
page "E-Doc. PO Match Prop. Sub" = X,
page "E-Doc. Order Match Act." = X,
page "Service Participants" = X;
page "Service Participants" = X,
page "E-Invoice Lines" = X;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ permissionset 6101 "E-Doc. Core - Read"
tabledata "E-Doc. Service Supported Type" = R,
tabledata "E-Doc. Imported Line" = R,
tabledata "E-Doc. Order Match" = R,
tabledata "Service Participant" = R;
tabledata "Service Participant" = R,
tabledata "E-Invoice Line" = R;
}
10 changes: 9 additions & 1 deletion Apps/W1/EDocument/app/src/Document/EDocument.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ page 6121 "E-Document"
ToolTip = 'Specifies the receiving company address.';
}
}
part(EInvoicePreview; "E-Invoice Lines")
{
Caption = 'E-Invoice Lines';
SubPageLink = "E-Document Entry No." = field("Entry No");
ShowFilter = false;
Visible = IsIncomingDoc and ShowPreview;
}
part(EdocoumentServiceStatus; "E-Document Service Status")
{
Caption = 'Service Status';
Expand Down Expand Up @@ -544,6 +551,7 @@ page 6121 "E-Document"
begin
IsProcessed := Rec.Status = Rec.Status::Processed;
IsIncomingDoc := Rec.Direction = Rec.Direction::Incoming;
ShowPreview := (Rec."Document Type" = Rec."Document Type"::"Purchase Invoice") or (Rec."Document Type" = Rec."Document Type"::"Purchase Credit Memo");

RecordLinkTxt := EDocumentHelper.GetRecordLinkText(Rec);
HasErrorsOrWarnings := (EDocumentErrorHelper.ErrorMessageCount(Rec) + EDocumentErrorHelper.WarningMessageCount(Rec)) > 0;
Expand Down Expand Up @@ -648,7 +656,7 @@ page 6121 "E-Document"
EDocumentHelper: Codeunit "E-Document Processing";
ErrorsAndWarningsNotification: Notification;
RecordLinkTxt, StyleStatusTxt : Text;
ShowRelink, ShowMapToOrder, HasErrorsOrWarnings, HasErrors, IsIncomingDoc, IsProcessed, CopilotVisible : Boolean;
ShowRelink, ShowMapToOrder, HasErrorsOrWarnings, HasErrors, IsIncomingDoc, IsProcessed, CopilotVisible, ShowPreview : Boolean;
EDocHasErrorOrWarningMsg: Label 'Errors or warnings found for E-Document. Please review below in "Error Messages" section.';
DocNotCreatedMsg: Label 'Failed to create new %1 from E-Document. Please review errors below.', Comment = '%1 - E-Document Document Type';

Expand Down
64 changes: 64 additions & 0 deletions Apps/W1/EDocument/app/src/InvoicePreview/EInvoiceLine.Table.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
table 6107 "E-Invoice Line"
{
Access = Internal;
Caption = 'E-Invoice Line';
DataClassification = CustomerContent;
Extensible = false;

fields
{
field(1; "E-Document Entry No."; Integer)
{
Caption = 'E-Document Entry No';
TableRelation = "E-Document";
ToolTip = 'Specifies the E-Document number that the line is related to.';
}
field(2; "Line No."; Integer)
{
Caption = 'Line No.';
ToolTip = 'Specifies the line number in the E-Document of the item or resource being purchased.';
}
field(3; "No."; Code[20])
{
Caption = 'No.';
ToolTip = 'Specifies what is being purchased.';
}
field(4; Description; Text[100])
{
Caption = 'Description';
ToolTip = 'Describes what is being purchased.';
}
field(5; "Unit of Measure Code"; Code[10])
{
Caption = 'Unit of Measure Code';
ToolTip = 'Specifies how each unit of the item or resource is measured, such as in pieces or hours.';
}
field(6; Quantity; Decimal)
{
Caption = 'Quantity';
DecimalPlaces = 0 : 5;
ToolTip = 'Specifies the quantity of what you''re buying. The number is based on the unit chosen in the Unit of Measure Code field.';
}
field(7; "Direct Unit Cost"; Decimal)
{
Caption = 'Direct Unit Cost';
ToolTip = 'Specifies the price of one unit of what you are buying.';
}
field(8; "Line Discount %"; Decimal)
{
Caption = 'Line Discount %';
DecimalPlaces = 0 : 5;
MaxValue = 100;
MinValue = 0;
ToolTip = 'Specifies the discount percentage that is granted for the item on the line.';
}
}

keys
{
key(Key1; "E-Document Entry No.", "Line No.")
{
Clustered = true;
}
}
}
38 changes: 38 additions & 0 deletions Apps/W1/EDocument/app/src/InvoicePreview/EInvoiceLines.Page.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
page 6100 "E-Invoice Lines"
{
ApplicationArea = Basic, Suite;
Caption = 'E-Invoice Lines';
DeleteAllowed = false;
Editable = false;
InsertAllowed = false;
PageType = ListPart;
SourceTable = "E-Invoice Line";

layout
{
area(Content)
{
repeater(EInvoiceLines)
{
field("No."; Rec."No.")
{
}
field(Description; Rec.Description)
{
}
field("Unit of Measure Code"; Rec."Unit of Measure Code")
{
}
field(Quantity; Rec.Quantity)
{
}
field("Direct Unit Cost"; Rec."Direct Unit Cost")
{
}
field("Line Discount %"; Rec."Line Discount %")
{
}
}
}
}
}
43 changes: 43 additions & 0 deletions Apps/W1/EDocument/app/src/Processing/EDocImport.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,52 @@ codeunit 6140 "E-Doc. Import"
SourceDocumentHeader.Copy(SourceDocumentHeaderMapped, true);
SourceDocumentLine.Copy(SourceDocumentLineMapped, true);

CreateEInvoicePreviewLines(EDocument, SourceDocumentLine);

OnAfterPrepareReceivedDoc(EDocument, TempBlob, SourceDocumentHeader, SourceDocumentLine, TempEDocMapping);
end;

local procedure CreateEInvoicePreviewLines(EDocument: Record "E-Document"; SourceDocumentLine: RecordRef)
var
EInvoiceLine: Record "E-Invoice Line";
begin
EInvoiceLine.SetRange("E-Document Entry No.", EDocument."Entry No");
if not EInvoiceLine.IsEmpty() then
EInvoiceLine.DeleteAll(true);

if (EDocument."Document Type" <> EDocument."Document Type"::"Purchase Invoice") and (EDocument."Document Type" <> EDocument."Document Type"::"Purchase Credit Memo") then
exit;

if SourceDocumentLine.FindSet() then
repeat
InsertEInvoiceLine(EDocument."Entry No", SourceDocumentLine);
until SourceDocumentLine.Next() = 0;
end;

local procedure InsertEInvoiceLine(EDocumentEntryNo: Integer; SourceDocumentLine: RecordRef)
var
EInvoiceLine: Record "E-Invoice Line";
PurchaseLine: Record "Purchase Line";
LineAmount: Decimal;
LineDiscountAmount: Decimal;
begin
EInvoiceLine.Init();
EInvoiceLine."E-Document Entry No." := EDocumentEntryNo;
EInvoiceLine."Line No." := SourceDocumentLine.Field(PurchaseLine.FieldNo("Line No.")).Value();
EInvoiceLine."No." := SourceDocumentLine.Field(PurchaseLine.FieldNo("Item Reference No.")).Value();
EInvoiceLine."Description" := SourceDocumentLine.Field(PurchaseLine.FieldNo("Description")).Value();
EInvoiceLine."Unit of Measure Code" := SourceDocumentLine.Field(PurchaseLine.FieldNo("Unit of Measure Code")).Value();
EInvoiceLine."Quantity" := SourceDocumentLine.Field(PurchaseLine.FieldNo("Quantity")).Value();
EInvoiceLine."Direct Unit Cost" := SourceDocumentLine.Field(PurchaseLine.FieldNo("Direct Unit Cost")).Value();

LineAmount := SourceDocumentLine.Field(PurchaseLine.FieldNo(Amount)).Value();
LineDiscountAmount := SourceDocumentLine.Field(PurchaseLine.FieldNo("Line Discount Amount")).Value();
if LineDiscountAmount <> 0 then
EInvoiceLine."Line Discount %" := 100 * (LineDiscountAmount / (LineAmount + LineDiscountAmount));

EInvoiceLine.Insert(true);
end;

local procedure CreateDocument(var EDocument: Record "E-Document"; var TempDocumentHeader: RecordRef; var TempDocumentLine: RecordRef; var DocumentHeader: RecordRef; PurchaseDocumentType: Enum "Purchase Document Type")
var
EDocumentCreatePurchase: Codeunit "E-Document Create Purch. Doc.";
Expand Down
24 changes: 0 additions & 24 deletions Apps/W1/EDocument/edocument_workspace.code-workspace

This file was deleted.

121 changes: 121 additions & 0 deletions Apps/W1/EDocument/test/src/Receive/EDocReceiveTest.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -2760,6 +2760,127 @@ codeunit 139628 "E-Doc. Receive Test"
end;


[Test]
[HandlerFunctions('ConfirmHandler')]
procedure PreviewEDocumentPurchaseInvoiceLines()
var
EDocService: Record "E-Document Service";
EDocument: Record "E-Document";
Item: Record Item;
DocumentAttachment: Record "Document Attachment";
VATPostingSetup: Record "VAT Posting Setup";
DocumentVendor: Record Vendor;
EDocumentPage: TestPage "E-Document";
EInvoiceLine: Record "E-Invoice Line";
begin
// [FEATURE] [E-Document] [Receive]
// [SCENARIO] Receive single e-document with two attachments without linking to purchase order
Initialize();
BindSubscription(EDocImplState);

// [GIVEN] e-Document service to receive one single purchase invoice
LibraryEDoc.CreateTestReceiveServiceForEDoc(EDocService, Enum::"E-Document Integration"::Mock);
SetDefaultEDocServiceValues(EDocService);
// [GIVEN] Vendor with VAT Posting Setup
CreateVendorWithVatPostingSetup(DocumentVendor, VATPostingSetup);
// [GIVEN] Item with item reference
CreateItemWithReference(Item, VATPostingSetup);
// [GIVEN] Incoming PEPPOL file
CreateIncomingPEPPOL(DocumentVendor);

// [WHEN] Running Receive
InvokeReceive(EDocService);
EDocumentPage.OpenView();
EDocumentPage.Last();

// [THEN] E-Invoice preview fast tab is visible and not editable
Assert.IsFalse(EDocumentPage.EInvoicePreview.Editable(), 'E-Invoice preview fast tab should not be editable');
// [THEN] E-Invoice lines are created
EDocument.FindLast();
EInvoiceLine.SetRange("E-Document Entry No.", EDocument."Entry No");
Assert.IsFalse(EInvoiceLine.IsEmpty(), 'E-Invoice lines not created.');
end;

local procedure CreateEDocServiceToReceivePurchaseOrder(var EDocService: Record "E-Document Service")
begin
LibraryEDoc.CreateTestReceiveServiceForEDoc(EDocService, Enum::"Service Integration"::Mock);
SetDefaultEDocServiceValues(EDocService);
end;

local procedure CreateVendorWithVatPostingSetup(var DocumentVendor: Record Vendor; var VATPostingSetup: Record "VAT Posting Setup")
begin
LibraryPurchase.CreateVendorWithVATRegNo(DocumentVendor);
LibraryERM.CreateVATPostingSetupWithAccounts(VATPostingSetup, Enum::"Tax Calculation Type"::"Normal VAT", 1);
DocumentVendor."VAT Bus. Posting Group" := VATPostingSetup."VAT Bus. Posting Group";
DocumentVendor."VAT Registration No." := 'GB123456789';
DocumentVendor."Receive E-Document To" := Enum::"E-Document Type"::"Purchase Invoice";
DocumentVendor.Modify(false);
end;

local procedure CreateItemWithReference(var Item: Record Item; var VATPostingSetup: Record "VAT Posting Setup")
var
ItemReference: Record "Item Reference";
begin
Item.FindFirst();
Item."VAT Prod. Posting Group" := VATPostingSetup."VAT Prod. Posting Group";
Item.Modify(false);
ItemReference.DeleteAll(false);
ItemReference."Item No." := Item."No.";
ItemReference."Reference No." := '1000';
ItemReference.Insert(false);
end;

local procedure CreateIncomingPEPPOL(var DocumentVendor: Record Vendor)
var
TempXMLBuffer: Record "XML Buffer" temporary;
TempBlob: Codeunit "Temp Blob";
Document: Text;
XMLInstream: InStream;
begin
TempXMLBuffer.LoadFromText(EDocReceiveFiles.GetDocument1());
TempXMLBuffer.Reset();
TempXMLBuffer.SetRange(Type, TempXMLBuffer.Type::Element);
TempXMLBuffer.SetRange(Path, '/Invoice/cac:AccountingSupplierParty/cac:Party/cbc:EndpointID');
TempXMLBuffer.FindFirst();
TempXMLBuffer.Value := DocumentVendor."VAT Registration No.";
TempXMLBuffer.Modify(false);

TempXMLBuffer.Reset();
TempXMLBuffer.FindFirst();
TempXMLBuffer.Save(TempBlob);

TempBlob.CreateInStream(XMLInstream, TextEncoding::UTF8);
XMLInstream.Read(Document);

LibraryVariableStorage.Clear();
LibraryVariableStorage.Enqueue(Document);
LibraryVariableStorage.Enqueue(1);
EDocImplState.SetVariableStorage(LibraryVariableStorage);
end;

local procedure InvokeReceive(var EDocService: Record "E-Document Service")
var
EDocServicePage: TestPage "E-Document Service";
begin
EDocServicePage.OpenView();
EDocServicePage.Filter.SetFilter(Code, EDocService.Code);
EDocServicePage.Receive.Invoke();
end;

local procedure SetDefaultEDocServiceValues(var EDocService: Record "E-Document Service")
begin
EDocService."Document Format" := "E-Document Format"::"PEPPOL BIS 3.0";
EDocService."Lookup Account Mapping" := false;
EDocService."Lookup Item GTIN" := false;
EDocService."Lookup Item Reference" := false;
EDocService."Resolve Unit Of Measure" := false;
EDocService."Validate Line Discount" := false;
EDocService."Verify Totals" := false;
EDocService."Use Batch Processing" := false;
EDocService."Validate Receiving Company" := false;
EDocService.Modify(false);
end;

#endif

}
Loading