Dynamics 365 Business Central

pageextension 50010 PostedPurchaseinvoice extends "Posted Purchase Invoices"
{
actions
{
addafter("&Invoice")
{
action("Create Purchase Order")
{
ApplicationArea = All;
Image = Invoice;
ToolTip = 'Create Purchase order';
Promoted = true;
PromotedCategory = Process;
trigger OnAction()
var
PurchInvHeader: Record "Purch. Inv. Header";
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
PurchInLine: Record "Purch. Inv. Line";
vendorNo: Code[20];
PurchaseOrderNo: Code[20];
LineExists: Boolean;
begin
CurrPage.SetSelectionFilter(Rec);
if Rec.FindSet() then begin
vendorNo := '';
PurchaseHeader.Init();
PurchaseHeader."Document Type" := PurchaseHeader."Document Type"::Order;
PurchaseHeader."No." := '';
PurchaseHeader.Validate("Buy-from Vendor No.", Rec."Buy-from Vendor No.");
PurchaseHeader.Validate("Vendor Invoice No.", Rec."Vendor Invoice No.");
PurchaseHeader.Insert(true);
PurchaseHeader."Document Date" := Rec."Document Date";
PurchaseHeader."Posting Date" := Rec."Posting Date";
PurchaseHeader."VAT Reporting Date" := Rec."VAT Reporting Date";
PurchaseHeader."Due Date" := Rec."Due Date";
PurchaseHeader."Order Date" := Rec."Order Date";
PurchaseHeader.Modify(true);
PurchaseOrderNo := PurchaseHeader."No.";
repeat
PurchInLine.Reset();
PurchInLine.SetRange("Document No.", Rec."No.");
if PurchInLine.FindSet() then begin
repeat
PurchaseLine.Reset();
PurchaseLine.SetRange("Document Type", PurchaseLine."Document Type"::Order);
PurchaseLine.SetRange("Document No.", PurchaseHeader."No.");
PurchaseLine.SetRange("Line No.", PurchInLine."Line No.");
if not PurchaseLine.Find() then begin
PurchaseLine.Init();
PurchaseLine."Document Type" := PurchaseLine."Document Type"::Order;
PurchaseLine."Document No." := PurchaseHeader."No.";
PurchaseLine.Type := PurchInLine.Type;
PurchaseLine."No." := PurchInLine."No.";
PurchaseLine.Validate(PurchaseLine."No.");
PurchaseLine."Line No." := PurchInLine."Line No.";
PurchaseLine.Validate(PurchaseLine."Line No.");
PurchaseLine.Quantity := PurchInLine.Quantity;
PurchaseLine.Validate(PurchaseLine.Quantity);
PurchaseLine."Direct Unit Cost" := PurchInLine."Direct Unit Cost";
PurchaseLine.Validate(PurchaseLine."Direct Unit Cost");
PurchaseLine.Insert(true);
end;
until PurchInLine.Next() = 0;
end;
until Rec.Next() = 0;
end;
Message(Rec."No.");
end;
}
}
}
}


help me to write my code

Answers

Sign In or Register to comment.