PROCEDURE SetApplyToAmount@20();
VAR
CustLedgEntry@1000 : Record 21;
VendLedgEntry@1001 : Record 25;
BEGIN
IF "Account Type" = "Account Type"::Customer THEN BEGIN
CustLedgEntry.SETCURRENTKEY("Document No.");
CustLedgEntry.SETRANGE("Document No.",Rec."Applies-To Doc. No.");
CustLedgEntry.SETRANGE("Customer No.","Account No.");
CustLedgEntry.SETRANGE(Open,TRUE);
IF CustLedgEntry.FIND('-') THEN BEGIN
CustLedgEntry.CALCFIELDS("Remaining Amount");
CustLedgEntry."Amount to Apply" := CustLedgEntry."Remaining Amount";
CODEUNIT.RUN(CODEUNIT::"Cust. Entry-Edit",CustLedgEntry);
END;
END ELSE IF "Account Type" = "Account Type"::Vendor THEN BEGIN
VendLedgEntry.SETCURRENTKEY("Document No.");
VendLedgEntry.SETRANGE("Document No.",Rec."Applies-To Doc. No.");
VendLedgEntry.SETRANGE("Vendor No.","Account No.");
VendLedgEntry.SETRANGE(Open,TRUE);
IF VendLedgEntry.FIND('-') THEN BEGIN
VendLedgEntry.CALCFIELDS("Remaining Amount");
VendLedgEntry."Amount to Apply" := VendLedgEntry."Remaining Amount";
CODEUNIT.RUN(CODEUNIT::"Vend. Entry-Edit",VendLedgEntry);
END;
END;
END;