Skip to content
Merged
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 @@ -14,7 +14,7 @@ using Microsoft.Purchases.Document;
using Microsoft.Purchases.Payables;
using Microsoft.Purchases.Posting;
using System.Telemetry;
using System.Utilities;
using Microsoft.eServices.EDocument.Processing;

/// <summary>
/// Dealing with the creation of the purchase invoice after the draft has been populated.
Expand All @@ -38,24 +38,25 @@ codeunit 6117 "E-Doc. Create Purchase Invoice" implements IEDocumentFinishDraft,
TempPOMatchWarnings: Record "E-Doc PO Match Warning" temporary;
EDocPOMatching: Codeunit "E-Doc. PO Matching";
DocumentAttachmentMgt: Codeunit "Document Attachment Mgmt";
ConfirmManagement: Codeunit "Confirm Management";
IEDocumentFinishPurchaseDraft: Interface IEDocumentCreatePurchaseInvoice;
YourMatchedLinesAreNotValidErr: Label 'The purchase invoice cannot be created because one or more of its matched lines are not valid matches. Review if your configuration allows for receiving at invoice.';
SomeLinesNotYetReceivedMsg: Label 'Some of the matched purchase order lines have not yet been received, when posting the invoice, receipts will be created if needed. Do you want to proceed with creating the purchase invoice?';
SomeLinesNotYetReceivedErr: Label 'Some of the matched purchase order lines have not yet been received, you need to either receive the lines or remove the matches.';
begin
EDocumentPurchaseHeader.GetFromEDocument(EDocument);

if not EDocPOMatching.VerifyEDocumentMatchedLinesAreValidMatches(EDocumentPurchaseHeader) then
Error(YourMatchedLinesAreNotValidErr);

EDocPOMatching.SuggestReceiptsForMatchedOrderLines(EDocumentPurchaseHeader);
EDocPOMatching.CalculatePOMatchWarnings(EDocumentPurchaseHeader, TempPOMatchWarnings);
TempPOMatchWarnings.SetRange("Warning Type", "E-Doc PO Match Warning"::NotYetReceived);
if not TempPOMatchWarnings.IsEmpty() then
if not ConfirmManagement.GetResponse(SomeLinesNotYetReceivedMsg) then
Error(''); // User cancelled the operation
Error(SomeLinesNotYetReceivedErr);

IEDocumentFinishPurchaseDraft := EDocImportParameters."Processing Customizations";
PurchaseHeader := IEDocumentFinishPurchaseDraft.CreatePurchaseInvoice(EDocument);

EDocPOMatching.TransferPOMatchesFromEDocumentToInvoice(EDocument, PurchaseHeader);
PurchaseHeader.SetRecFilter();
PurchaseHeader.FindFirst();
PurchaseHeader."Doc. Amount Incl. VAT" := EDocumentPurchaseHeader.Total;
Expand All @@ -78,11 +79,13 @@ codeunit 6117 "E-Doc. Create Purchase Invoice" implements IEDocumentFinishDraft,
procedure RevertDraftActions(EDocument: Record "E-Document")
var
PurchaseHeader: Record "Purchase Header";
EDocPOMatching: Codeunit "E-Doc. PO Matching";
DocumentAttachmentMgt: Codeunit "Document Attachment Mgmt";
begin
PurchaseHeader.SetRange("E-Document Link", EDocument.SystemId);
if not PurchaseHeader.FindFirst() then
exit;
EDocPOMatching.TransferPOMatchesFromInvoiceToEDocument(PurchaseHeader, EDocument);
DocumentAttachmentMgt.CopyAttachments(PurchaseHeader, EDocument);
DocumentAttachmentMgt.DeleteAttachedDocuments(PurchaseHeader);
PurchaseHeader.TestField("Document Type", "Purchase Document Type"::Invoice);
Expand All @@ -102,6 +105,7 @@ codeunit 6117 "E-Doc. Create Purchase Invoice" implements IEDocumentFinishDraft,
DimensionManagement: Codeunit DimensionManagement;
PurchCalcDiscByType: Codeunit "Purch - Calc Disc. By Type";
PurchaseLineCombinedDimensions: array[10] of Integer;
PurchaseLineNo: Integer;
StopCreatingPurchaseInvoice: Boolean;
VendorInvoiceNo: Code[35];
GlobalDim1, GlobalDim2 : Code[20];
Expand Down Expand Up @@ -142,16 +146,16 @@ codeunit 6117 "E-Doc. Create Purchase Invoice" implements IEDocumentFinishDraft,
PurchaseHeader.Modify();
end;

// Track changes for history
EDocumentPurchaseHistMapping.TrackRecord(EDocument, EDocumentPurchaseHeader, PurchaseHeader);

PurchaseLine."Line No." := GetLastLineNumberOnPurchaseInvoice(PurchaseHeader."No."); // We get the last line number, even if this is a new document since recurrent lines get inserted on the header's creation
LinkEDocumentHeaderToPurchaseHeader(EDocumentPurchaseHeader, PurchaseHeader);
PurchaseLineNo := GetLastLineNumberOnPurchaseInvoice(PurchaseHeader."No."); // We get the last line number, even if this is a new document since recurrent lines get inserted on the header's creation
EDocumentPurchaseLine.SetRange("E-Document Entry No.", EDocument."Entry No");
if EDocumentPurchaseLine.FindSet() then
repeat
Clear(PurchaseLine);
PurchaseLine."Document Type" := PurchaseHeader."Document Type";
PurchaseLine."Document No." := PurchaseHeader."No.";
PurchaseLine."Line No." += 10000;
PurchaseLineNo += 10000;
PurchaseLine."Line No." := PurchaseLineNo;
PurchaseLine."Unit of Measure Code" := CopyStr(EDocumentPurchaseLine."[BC] Unit of Measure", 1, MaxStrLen(PurchaseLine."Unit of Measure Code"));
PurchaseLine."Variant Code" := EDocumentPurchaseLine."[BC] Variant Code";
PurchaseLine.Type := EDocumentPurchaseLine."[BC] Purchase Line Type";
Expand All @@ -177,10 +181,7 @@ codeunit 6117 "E-Doc. Create Purchase Invoice" implements IEDocumentFinishDraft,
PurchaseLine.Validate("Shortcut Dimension 2 Code", EDocumentPurchaseLine."[BC] Shortcut Dimension 2 Code");
EDocumentPurchaseHistMapping.ApplyAdditionalFieldsFromHistoryToPurchaseLine(EDocumentPurchaseLine, PurchaseLine);
PurchaseLine.Insert();

// Track changes for history
EDocumentPurchaseHistMapping.TrackRecord(EDocument, EDocumentPurchaseLine, PurchaseLine);

LinkEDocumentLineToPurchaseLine(EDocumentPurchaseLine, PurchaseLine);
until EDocumentPurchaseLine.Next() = 0;
PurchaseHeader.Modify();
PurchCalcDiscByType.ApplyInvDiscBasedOnAmt(EDocumentPurchaseHeader."Total Discount", PurchaseHeader);
Expand Down Expand Up @@ -226,4 +227,28 @@ codeunit 6117 "E-Doc. Create Purchase Invoice" implements IEDocumentFinishDraft,
exit(PurchaseLine."Line No.");
end;

local procedure LinkEDocumentHeaderToPurchaseHeader(EDocumentPurchaseHeader: Record "E-Document Purchase Header"; PurchaseHeader: Record "Purchase Header")
var
EDocRecordLink: Record "E-Doc. Record Link";
begin
EDocRecordLink."Source Table No." := Database::"E-Document Purchase Header";
EDocRecordLink."Source SystemId" := EDocumentPurchaseHeader.SystemId;
EDocRecordLink."Target Table No." := Database::"Purchase Header";
EDocRecordLink."Target SystemId" := PurchaseHeader.SystemId;
EDocRecordLink."E-Document Entry No." := EDocumentPurchaseHeader."E-Document Entry No.";
EDocRecordLink.Insert();
end;

local procedure LinkEDocumentLineToPurchaseLine(EDocumentPurchaseLine: Record "E-Document Purchase Line"; PurchaseLine: Record "Purchase Line")
var
EDocRecordLink: Record "E-Doc. Record Link";
begin
EDocRecordLink."Source Table No." := Database::"E-Document Purchase Line";
EDocRecordLink."Source SystemId" := EDocumentPurchaseLine.SystemId;
EDocRecordLink."Target Table No." := Database::"Purchase Line";
EDocRecordLink."Target SystemId" := PurchaseLine.SystemId;
EDocRecordLink."E-Document Entry No." := EDocumentPurchaseLine."E-Document Entry No.";
EDocRecordLink.Insert();
end;

}
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ page 6183 "E-Doc. Purchase Draft Subform"
group("Order Matching")
{
Caption = 'Order matching';
action(MatchToOrderLines)
action(MatchToOrderLine)
{
ApplicationArea = All;
Caption = 'Match to order lines';
Caption = 'Match to order line';
Image = LinkWithExisting;
ToolTip = 'Match this incoming invoice line to purchase order lines.';
ToolTip = 'Match this incoming invoice line to a purchase order line.';
Scope = Repeater;

trigger OnAction()
Expand All @@ -192,9 +192,9 @@ page 6183 "E-Doc. Purchase Draft Subform"
action(SpecifyReceiptLines)
{
ApplicationArea = All;
Caption = 'Specify receipt lines';
Caption = 'Specify receipt line';
Image = ReceiptLines;
ToolTip = 'Specify the corresponding receipt lines to the matched order line.';
ToolTip = 'Specify the corresponding receipt line to the matched order line.';
Scope = Repeater;
Enabled = IsLineMatchedToOrderLine;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using Microsoft.Finance.Dimension;
using Microsoft.Finance.GeneralLedger.Account;
using Microsoft.FixedAssets.FixedAsset;
using Microsoft.Foundation.UOM;
using Microsoft.eServices.EDocument.Processing;
using Microsoft.Inventory.Item;
using Microsoft.Inventory.Item.Catalog;
using Microsoft.Projects.Resources.Resource;
Expand Down Expand Up @@ -336,6 +337,31 @@ table 6101 "E-Document Purchase Line"
exit(OldDimSetID <> "[BC] Dimension Set ID");
end;

internal procedure GetFromLinkedPurchaseLine(PurchaseLine: Record "Purchase Line"): Boolean
var
EDocumentRecordLink: Record "E-Doc. Record Link";
begin
Clear(Rec);
EDocumentRecordLink.SetRange("Source Table No.", Database::"E-Document Purchase Line");
EDocumentRecordLink.SetRange("Target Table No.", Database::"Purchase Line");
EDocumentRecordLink.SetRange("Target SystemId", PurchaseLine.SystemId);
if EDocumentRecordLink.FindFirst() then
exit(Rec.GetBySystemId(EDocumentRecordLink."Source SystemId"));
end;

internal procedure GetLinkedPurchaseLine(): Record "Purchase Line"
var
EDocumentRecordLink: Record "E-Doc. Record Link";
PurchaseLine: Record "Purchase Line";
begin
EDocumentRecordLink.SetRange("Source Table No.", Database::"E-Document Purchase Line");
EDocumentRecordLink.SetRange("Target Table No.", Database::"Purchase Line");
EDocumentRecordLink.SetRange("Source SystemId", Rec.SystemId);
if EDocumentRecordLink.FindFirst() then
if PurchaseLine.GetBySystemId(EDocumentRecordLink."Target SystemId") then
exit(PurchaseLine);
end;

procedure GetEDocumentPurchaseHeader() EDocumentPurchaseHeader: Record "E-Document Purchase Header"
begin
if EDocumentPurchaseHeader.Get(Rec."E-Document Entry No.") then;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ codeunit 6120 "E-Doc. Purchase Hist. Mapping"

var
EDocImpSessionTelemetry: Codeunit "E-Doc. Imp. Session Telemetry";
WrongVariantTypeErr: Label 'Only record types are allowed.';

procedure FindRelatedPurchaseHeaderInHistory(EDocument: Record "E-Document"; var EDocVendorAssignmentHistory: Record "E-Doc. Vendor Assign. History"): Boolean
var
Expand Down Expand Up @@ -204,28 +203,6 @@ codeunit 6120 "E-Doc. Purchase Hist. Mapping"
EDocActivityLogSession.Set(ActivityLogSessionToken, ActivityLog);
end;

/// <summary>
/// Track header and line mapping between source and target records.
/// </summary>
procedure TrackRecord(EDocument: Record "E-Document"; SourceRecord: Variant; TargetRecord: Variant)
var
EDocRecordLink: Record "E-Doc. Record Link";
SourceRecordRef, TargetRecordRef : RecordRef;
begin
if (not SourceRecord.IsRecord()) or (not TargetRecord.IsRecord()) then
Error(WrongVariantTypeErr);

SourceRecordRef.GetTable(SourceRecord);
TargetRecordRef.GetTable(TargetRecord);

EDocRecordLink."Source Table No." := SourceRecordRef.Number();
EDocRecordLink."Source SystemId" := SourceRecordRef.Field(SourceRecordRef.SystemIdNo).Value();
EDocRecordLink."Target Table No." := TargetRecordRef.Number();
EDocRecordLink."Target SystemId" := TargetRecordRef.Field(TargetRecordRef.SystemIdNo).Value();
EDocRecordLink."E-Document Entry No." := EDocument."Entry No";
if EDocRecordLink.Insert() then;
end;

/// <summary>
/// Applies the values configured as additional fields in the posted line, if the line had a historic match the values are retrieved from the Purchase Invoice Line.
/// </summary>
Expand Down
Loading
Loading