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 @@ -35,20 +35,11 @@ codeunit 6117 "E-Doc. Create Purchase Invoice" implements IEDocumentFinishDraft,
EDocImpSessionTelemetry: Codeunit "E-Doc. Imp. Session Telemetry";
EmptyRecordId: RecordId;
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.';
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.';
MissingInformationForMatchErr: Label 'Some of the draft lines that were matched to purchase order lines are missing unit of measure information. Please specify the unit of measure for those lines and try again.';
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"::ExceedsInvoiceableQty);
if not TempPOMatchWarnings.IsEmpty() then
Error(SomeLinesNotYetReceivedErr);
TempPOMatchWarnings.SetRange("Warning Type", "E-Doc PO Match Warning"::MissingInformationForMatch);
if not TempPOMatchWarnings.IsEmpty() then
Error(MissingInformationForMatchErr);
Expand Down Expand Up @@ -88,17 +79,12 @@ codeunit 6117 "E-Doc. Create Purchase Invoice" implements IEDocumentFinishDraft,
VendorLedgerEntry: Record "Vendor Ledger Entry";
EDocumentPurchaseHeader: Record "E-Document Purchase Header";
EDocumentPurchaseLine: Record "E-Document Purchase Line";
PurchaseLine: Record "Purchase Line";
EDocRecordLink: Record "E-Doc. Record Link";
EDocPurchaseDocumentHelper: Codeunit "E-Doc. Purch. Doc. Helper";
PurchCalcDiscByType: Codeunit "Purch - Calc Disc. By Type";
EDocLineByReceipt: Query "E-Doc. Line by Receipt";
LastReceiptNo: Code[20];
PurchaseLineNo: Integer;
StopCreatingPurchaseInvoice: Boolean;
VendorInvoiceNo: Code[35];
ReceiptNoLbl: Label 'Receipt No. %1:', Comment = '%1 = Receipt No.';
NullGuid: Guid;
begin
EDocumentPurchaseHeader.GetFromEDocument(EDocument);
if not EDocPurchaseDocumentHelper.AllDraftLinesHaveTypeAndNumber(EDocumentPurchaseHeader) then begin
Expand Down Expand Up @@ -142,41 +128,13 @@ codeunit 6117 "E-Doc. Create Purchase Invoice" implements IEDocumentFinishDraft,
end;
EDocRecordLink.InsertEDocumentHeaderLink(EDocumentPurchaseHeader, PurchaseHeader);

PurchaseLineNo := EDocPurchaseDocumentHelper.GetLastPurchaseLineNo("Purchase Document Type"::Invoice, 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
// We create first the lines without any PO matches
EDocLineByReceipt.SetRange(EDocumentEntryNo, EDocument."Entry No");
EDocLineByReceipt.SetRange(ReceiptNo, '');
EDocLineByReceipt.SetRange(PurchaseLineSystemId, NullGuid);
EDocLineByReceipt.Open();
while EDocLineByReceipt.Read() do begin
EDocumentPurchaseLine.GetBySystemId(EDocLineByReceipt.SystemId);
PurchaseLineNo += 10000;
EDocPurchaseDocumentHelper.CreatePurchaseLineFromDraft(PurchaseHeader, EDocumentPurchaseLine, EDocumentPurchaseHeader."Total Discount" > 0, PurchaseLineNo);
end;
EDocLineByReceipt.Close();

// Then we create the lines with receipt no., adding comment lines for each receipt no.
LastReceiptNo := '';
EDocLineByReceipt.SetFilter(ReceiptNo, '<> %1', '');
EDocLineByReceipt.SetRange(PurchaseLineSystemId);
EDocLineByReceipt.Open();
while EDocLineByReceipt.Read() do begin
if LastReceiptNo <> EDocLineByReceipt.ReceiptNo then begin // A receipt no. for which we have not created a header comment line yet
Clear(PurchaseLine);
PurchaseLine."Document Type" := PurchaseHeader."Document Type";
PurchaseLine."Document No." := PurchaseHeader."No.";
PurchaseLineNo := EDocPurchaseDocumentHelper.GetLastPurchaseLineNo("Purchase Document Type"::Invoice, PurchaseHeader."No.");
EDocumentPurchaseLine.SetRange("E-Document Entry No.", EDocument."Entry No");
if EDocumentPurchaseLine.FindSet() then
repeat
PurchaseLineNo += 10000;
PurchaseLine."Line No." := PurchaseLineNo;
PurchaseLine.Type := PurchaseLine.Type::" ";
PurchaseLine.Description := StrSubstNo(ReceiptNoLbl, EDocLineByReceipt.ReceiptNo);
PurchaseLine.Insert();
end;
EDocumentPurchaseLine.GetBySystemId(EDocLineByReceipt.SystemId);
PurchaseLineNo += 10000;
EDocPurchaseDocumentHelper.CreatePurchaseLineFromDraft(PurchaseHeader, EDocumentPurchaseLine, EDocumentPurchaseHeader."Total Discount" > 0, PurchaseLineNo);
LastReceiptNo := EDocLineByReceipt.ReceiptNo;
end;
EDocLineByReceipt.Close();
EDocPurchaseDocumentHelper.CreatePurchaseLineFromDraft(PurchaseHeader, EDocumentPurchaseLine, EDocumentPurchaseHeader."Total Discount" > 0, PurchaseLineNo);
until EDocumentPurchaseLine.Next() = 0;
PurchaseHeader.Modify();
PurchCalcDiscByType.ApplyInvDiscBasedOnAmt(EDocumentPurchaseHeader."Total Discount", PurchaseHeader);
EDocPurchaseDocumentHelper.ApplyVATDifferenceToLines(PurchaseHeader, EDocumentPurchaseHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ page 6183 "E-Doc. Purchase Draft Subform"
field(MatchWarnings; MatchWarningsCaption)
{
ApplicationArea = All;
Caption = 'Order match warnings';
Caption = 'Warnings';
Editable = false;
Visible = HasEDocumentOrderMatchWarnings;
StyleExpr = MatchWarningsStyleExpr;
Expand Down Expand Up @@ -201,9 +201,9 @@ page 6183 "E-Doc. Purchase Draft Subform"
action(MatchToOrderLine)
{
ApplicationArea = All;
Caption = 'Match to order line';
Caption = 'Match to order lines';
Image = LinkWithExisting;
ToolTip = 'Match this incoming invoice line to a purchase order line.';
ToolTip = 'Matches this incoming invoice line to purchase order lines.';
Scope = Repeater;

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

Expand All @@ -248,9 +248,9 @@ page 6183 "E-Doc. Purchase Draft Subform"
action(OpenMatchedOrder)
{
ApplicationArea = All;
Caption = 'Open matched order';
Caption = 'Open matched orders';
Image = ViewOrder;
ToolTip = 'Opens the matched purchase order.';
ToolTip = 'Opens the matched purchase orders.';
Scope = Repeater;
Enabled = IsLineMatchedToOrderLine;

Expand All @@ -262,9 +262,9 @@ page 6183 "E-Doc. Purchase Draft Subform"
action(OpenMatchedReceipt)
{
ApplicationArea = All;
Caption = 'Open matched receipt';
Caption = 'Open matched receipts';
Image = PostedReceipt;
ToolTip = 'Opens the matched purchase receipt.';
ToolTip = 'Opens the matched purchase receipts.';
Scope = Repeater;
Enabled = IsLineMatchedToReceiptLine;

Expand Down Expand Up @@ -583,7 +583,7 @@ page 6183 "E-Doc. Purchase Draft Subform"
Page.Run(Page::"Purchase Order", PurchaseOrder);
exit;
end;
Page.Run(Page::"Purchase Orders", TempPurchaseOrders);
Page.Run(Page::"Purchase Order List", TempPurchaseOrders);
end;

local procedure UpdatePOMatching()
Expand Down Expand Up @@ -623,6 +623,7 @@ page 6183 "E-Doc. Purchase Draft Subform"
ExceedsInvoiceableQtyLbl: Label 'Exceeds quantity received';
ExceedsRemainingToInvoiceLbl: Label 'Exceeds remaining to invoice';
OverReceiptLbl: Label 'Over-receipt';
PriceDifferenceLbl: Label 'Price difference';
NoWarningsLbl: Label 'No warnings';
MultipleWarningsLbl: Label 'Multiple warnings';
MostSevereStyle: Text;
Expand Down Expand Up @@ -663,6 +664,12 @@ page 6183 "E-Doc. Purchase Draft Subform"
MatchWarningsCaption := OverReceiptLbl;
MostSevereStyle := 'Subordinate';
end;
Enum::"E-Doc PO Match Warning"::AmountMismatch:
begin
CurrentSeverity := 2;
MatchWarningsCaption := PriceDifferenceLbl;
MostSevereStyle := 'Ambiguous';
end;
end;
if CurrentSeverity > SeverityLevel then begin
SeverityLevel := CurrentSeverity;
Expand All @@ -689,7 +696,8 @@ page 6183 "E-Doc. Purchase Draft Subform"
WarningDetails.AppendLine('• ' + MissingInfoDetailLbl);
Enum::"E-Doc PO Match Warning"::ExceedsInvoiceableQty,
Enum::"E-Doc PO Match Warning"::ExceedsRemainingToInvoice,
Enum::"E-Doc PO Match Warning"::OverReceipt:
Enum::"E-Doc PO Match Warning"::OverReceipt,
Enum::"E-Doc PO Match Warning"::AmountMismatch:
WarningDetails.AppendLine('• ' + TempEDocumentPOMatchWarnings."Warning Message");
end;
until TempEDocumentPOMatchWarnings.Next() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ enum 6111 "E-Doc PO Match Warning"
value(5; OverReceipt)
{
}
value(6; AmountMismatch)
{
}
}
Loading
Loading