Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

This article applies to Microsoft Dynamics NAV for all countries and all language locales.

Symptoms

Assume that you use multiple decimal places in quantity and discount in Microsoft Dynamics NAV 2009. When you use the prepayment and partially shipments, the prepayment amount to deduct is rounded incorrectly. The prepayment amount to deduct differs from the line amount. Therefore, when you invoice the amount, the result is incorrect. This problem occurs on the sales side and on the purchase side.

This problem occurs in the following products:

  • Microsoft Dynamics NAV 2009 R2

  • Microsoft Dynamics NAV 2009 Service Pack 1

Resolution

Hotfix information

A supported hotfix is now available from Microsoft. However, it is only intended to correct the problem that is described in this article. Apply it only to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Microsoft Dynamics NAV 2009 service pack or the next Microsoft Dynamics NAV version that contains this hotfix.

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Technical Support Professional for Microsoft Dynamics and related products determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.


Installation information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Note Before you install this hotfix, verify that all Microsoft Navision client users are logged off the system. This includes Microsoft Navision Application Services (NAS) client users. You should be the only client user who is logged on when you implement this hotfix.

To implement this hotfix, you must have a developer license.

We recommend that the user account in the Windows Logins window or in the Database Logins window be assigned the "SUPER" role ID. If the user account cannot be assigned the "SUPER" role ID, you must verify that the user account has the following permissions:

  • The Modify permission for the object that you will be changing.

  • The Execute permission for the System Object ID 5210 object and for the System Object ID 9015 object.



Note You do not have to have rights to the data stores unless you have to perform data repair.

Code changes

Note Always test code fixes in a controlled environment before you apply the fixes to your production computers.
To resolve this problem, follow these steps:

  1. Change the code in the UpdateAmounts function in the Sales Line table (37) as follows:
    Existing code

    ...
    UpdateVATAmounts;

    // Delete the following lines.
    IF "Prepayment %" <> 0 THEN BEGIN
    IF Quantity < 0 THEN
    FIELDERROR(Quantity,STRSUBSTNO(Text047,FIELDCAPTION("Prepayment %")));
    IF "Unit Price" < 0 THEN
    FIELDERROR("Unit Price",STRSUBSTNO(Text047,FIELDCAPTION("Prepayment %")));
    END;
    IF SalesHeader."Document Type" <> SalesHeader."Document Type"::Invoice THEN BEGIN
    "Prepayment VAT Difference" := 0;
    "Prepmt. Line Amount" := ROUND("Line Amount" * "Prepayment %" / 100,Currency."Amount Rounding Precision");
    IF "Prepmt. Line Amount" < "Prepmt. Amt. Inv." THEN
    FIELDERROR("Prepmt. Line Amount",STRSUBSTNO(Text049,"Prepmt. Amt. Inv."));
    IF "Prepmt. Line Amount" <> 0 THEN BEGIN
    RemLineAmountToInvoice :=
    ROUND("Line Amount" * (Quantity - "Quantity Invoiced") / Quantity,Currency."Amount Rounding Precision");
    IF RemLineAmountToInvoice < ("Prepmt. Line Amount" - "Prepmt Amt Deducted") THEN
    FIELDERROR("Prepmt. Line Amount",STRSUBSTNO(Text045,RemLineAmountToInvoice + "Prepmt Amt Deducted"));
    END;
    END;
    // End of the lines.

    InitOutstandingAmount;
    ...

    Replacement code

    ...
    UpdateVATAmounts;

    // Add the following lines.

    IF NOT "Prepayment Line" THEN BEGIN
    IF "Prepayment %" <> 0 THEN BEGIN
    IF Quantity < 0 THEN
    FIELDERROR(Quantity,STRSUBSTNO(Text047,FIELDCAPTION("Prepayment %")));
    IF "Unit Price" < 0 THEN
    FIELDERROR("Unit Price",STRSUBSTNO(Text047,FIELDCAPTION("Prepayment %")));
    END;
    IF SalesHeader."Document Type" <> SalesHeader."Document Type"::Invoice THEN BEGIN
    "Prepayment VAT Difference" := 0;
    "Prepmt. Line Amount" := ROUND("Line Amount" * "Prepayment %" / 100,Currency."Amount Rounding Precision");
    IF "Prepmt. Line Amount" < "Prepmt. Amt. Inv." THEN
    FIELDERROR("Prepmt. Line Amount",STRSUBSTNO(Text049,"Prepmt. Amt. Inv."));
    IF "Prepmt. Line Amount" <> 0 THEN BEGIN
    RemLineAmountToInvoice :=
    ROUND("Line Amount" * (Quantity - "Quantity Invoiced") / Quantity,Currency."Amount Rounding Precision");
    IF RemLineAmountToInvoice < ("Prepmt. Line Amount" - "Prepmt Amt Deducted") THEN
    FIELDERROR("Prepmt. Line Amount",STRSUBSTNO(Text045,RemLineAmountToInvoice + "Prepmt Amt Deducted"));
    END;
    END;
    END;

    // End of the lines.

    InitOutstandingAmount;
    ...
  2. Change the code in the CalcVATAmountLines function in the Sales Line table (37) as follows:
    Existing code 1

    ...
    VATAmountLine."Line Amount" :=

    // Delete the following lines.
    VATAmountLine."Line Amount" +
    (ROUND(QtyToHandle * "Unit Price" - ("Line Discount Amount" * QtyToHandle / Quantity),
    Currency."Amount Rounding Precision"));
    IF "Allow Invoice Disc." THEN
    VATAmountLine."Inv. Disc. Base Amount" :=
    VATAmountLine."Inv. Disc. Base Amount" +
    (ROUND(QtyToHandle * "Unit Price" - ("Line Discount Amount" * QtyToHandle / Quantity),
    Currency."Amount Rounding Precision"));
    // End of the lines.

    IF SalesHeader."Invoice Discount Calculation" <> SalesHeader."Invoice Discount Calculation"::Amount THEN

    ...

    Replacement code 1

    ...
    VATAmountLine."Line Amount" :=

    // Add the following lines.
    VATAmountLine."Line Amount" + GetLineAmountToHandle(QtyToHandle);
    IF "Allow Invoice Disc." THEN
    VATAmountLine."Inv. Disc. Base Amount" :=
    VATAmountLine."Inv. Disc. Base Amount" + GetLineAmountToHandle(QtyToHandle);
    // End of the lines.

    IF SalesHeader."Invoice Discount Calculation" <> SalesHeader."Invoice Discount Calculation"::Amount THEN
    ...

    Existing code 2

    ...
    VATAmountLine."Line Amount" :=

    // Delete the following lines.
    VATAmountLine."Line Amount" +
    (ROUND(QtyToHandle * "Unit Price" - ("Line Discount Amount" * QtyToHandle / Quantity),
    Currency."Amount Rounding Precision"));
    IF "Allow Invoice Disc." THEN
    VATAmountLine."Inv. Disc. Base Amount" :=
    VATAmountLine."Inv. Disc. Base Amount" +
    (ROUND(QtyToHandle * "Unit Price" - ("Line Discount Amount" * QtyToHandle / Quantity),
    Currency."Amount Rounding Precision"));
    // End of the lines.

    VATAmountLine."Invoice Discount Amount" :=
    ...

    Replacement code 2

    ...
    VATAmountLine."Line Amount" :=

    // Add the following lines.
    VATAmountLine."Line Amount" + GetLineAmountToHandle(QtyToHandle);
    IF "Allow Invoice Disc." THEN
    VATAmountLine."Inv. Disc. Base Amount" :=
    VATAmountLine."Inv. Disc. Base Amount" + GetLineAmountToHandle(QtyToHandle);
    // End of the lines.

    VATAmountLine."Invoice Discount Amount" :=
    ...
  3. Change the code in the CalcPrepaymentToDeduct function in the Sales Line table (37) as follows:
    Existing code

    ...
    GetSalesHeader;

    // Delete the following lines.
    "Prepmt Amt to Deduct" :=
    ROUND(
    ("Prepmt. Amt. Inv." - "Prepmt Amt Deducted") *
    "Qty. to Invoice" / (Quantity - "Quantity Invoiced"),Currency."Amount Rounding Precision")
    END ELSE
    "Prepmt Amt to Deduct" := 0
    // End of the lines.

    END;
    ...

    Replacement code

    ...
    GetSalesHeader;

    // Add the following lines.
    IF ("Prepayment %" = 100) AND NOT IsFinalInvoice THEN
    "Prepmt Amt to Deduct" := GetLineAmountToHandle("Qty. to Invoice")
    ELSE
    "Prepmt Amt to Deduct" :=
    ROUND(
    ("Prepmt. Amt. Inv." - "Prepmt Amt Deducted") *
    "Qty. to Invoice" / (Quantity - "Quantity Invoiced"),Currency."Amount Rounding Precision")
    END ELSE
    "Prepmt Amt to Deduct" := 0
    END;

    PROCEDURE IsFinalInvoice@116() : Boolean;
    BEGIN
    EXIT("Qty. to Invoice" = Quantity - "Quantity Invoiced");
    END;

    PROCEDURE GetLineAmountToHandle@117(QtyToHandle@1002 : Decimal) : Decimal;
    VAR
    LineAmount@1001 : Decimal;
    LineDiscAmount@1000 : Decimal;
    BEGIN
    LineAmount := ROUND(QtyToHandle * "Unit Price",Currency."Amount Rounding Precision");
    LineDiscAmount := ROUND("Line Discount Amount" * QtyToHandle / Quantity,Currency."Amount Rounding Precision");
    EXIT(LineAmount - LineDiscAmount);
    // End of the lines.

    END;
    ...
  4. Change the code in the UpdatePrePaymentAmounts function in the Sales Line table (37) as follows:
    Existing code

    ...
    IF SalesOrderLine.GET(SalesOrderLine."Document Type"::Order,ShipmentLine."Order No.",ShipmentLine."Order Line No.") THEN BEGIN

    // Delete the following lines.
    "Prepmt Amt to Deduct" :=
    ROUND((SalesOrderLine."Prepmt. Amt. Inv." - SalesOrderLine."Prepmt Amt Deducted") *
    Quantity / (SalesOrderLine.Quantity - SalesOrderLine."Quantity Invoiced"),Currency."Amount Rounding Precision");
    // End of the lines.

    "Prepmt VAT Diff. to Deduct" := "Prepayment VAT Difference" - "Prepmt VAT Diff. Deducted";
    ...

    Replacement code

    ...
    IF SalesOrderLine.GET(SalesOrderLine."Document Type"::Order,ShipmentLine."Order No.",ShipmentLine."Order Line No.") THEN BEGIN

    // Add the following lines.
    IF ("Prepayment %" = 100) AND (Quantity <> SalesOrderLine.Quantity - SalesOrderLine."Quantity Invoiced") THEN
    "Prepmt Amt to Deduct" := "Line Amount"
    ELSE
    "Prepmt Amt to Deduct" :=
    ROUND((SalesOrderLine."Prepmt. Amt. Inv." - SalesOrderLine."Prepmt Amt Deducted") *
    Quantity / (SalesOrderLine.Quantity - SalesOrderLine."Quantity Invoiced"),Currency."Amount Rounding Precision");
    // End of the lines.

    "Prepmt VAT Diff. to Deduct" := "Prepayment VAT Difference" - "Prepmt VAT Diff. Deducted";
    ...
  5. Change the code in the UpdateAmounts function in the Purchase Line table (39) as follows:
    Existing code

    ...
    // Delete the following lines.
    IF "Prepayment %" <> 0 THEN BEGIN
    IF Quantity < 0 THEN
    FIELDERROR(Quantity,STRSUBSTNO(Text043,FIELDCAPTION("Prepayment %")));
    IF "Direct Unit Cost" < 0 THEN
    FIELDERROR("Direct Unit Cost",STRSUBSTNO(Text043,FIELDCAPTION("Prepayment %")));
    END;
    IF PurchHeader."Document Type" <> PurchHeader."Document Type"::Invoice THEN BEGIN
    "Prepayment VAT Difference" := 0;
    "Prepmt. Line Amount" := ROUND("Line Amount" * "Prepayment %" / 100,Currency."Amount Rounding Precision");
    IF "Prepmt. Line Amount" < "Prepmt. Amt. Inv." THEN
    FIELDERROR("Prepmt. Line Amount",STRSUBSTNO(Text037,"Prepmt. Amt. Inv."));
    IF "Prepmt. Line Amount" <> 0 THEN BEGIN
    RemLineAmountToInvoice :=
    ROUND("Line Amount" * (Quantity - "Quantity Invoiced") / Quantity,Currency."Amount Rounding Precision");
    IF RemLineAmountToInvoice < ("Prepmt. Line Amount" - "Prepmt Amt Deducted") THEN
    FIELDERROR("Prepmt. Line Amount",STRSUBSTNO(Text039,RemLineAmountToInvoice + "Prepmt Amt Deducted"));
    END;
    END;
    // End of the lines.

    IF PurchHeader.Status = PurchHeader.Status::Released THEN
    ...

    Replacement code

    ...
    // Add the following lines.
    IF NOT "Prepayment Line" THEN BEGIN
    IF "Prepayment %" <> 0 THEN BEGIN
    IF Quantity < 0 THEN
    FIELDERROR(Quantity,STRSUBSTNO(Text043,FIELDCAPTION("Prepayment %")));
    IF "Direct Unit Cost" < 0 THEN
    FIELDERROR("Direct Unit Cost",STRSUBSTNO(Text043,FIELDCAPTION("Prepayment %")));
    END;
    IF PurchHeader."Document Type" <> PurchHeader."Document Type"::Invoice THEN BEGIN
    "Prepayment VAT Difference" := 0;
    "Prepmt. Line Amount" := ROUND("Line Amount" * "Prepayment %" / 100,Currency."Amount Rounding Precision");
    IF "Prepmt. Line Amount" < "Prepmt. Amt. Inv." THEN
    FIELDERROR("Prepmt. Line Amount",STRSUBSTNO(Text037,"Prepmt. Amt. Inv."));
    IF "Prepmt. Line Amount" <> 0 THEN BEGIN
    RemLineAmountToInvoice :=
    ROUND("Line Amount" * (Quantity - "Quantity Invoiced") / Quantity,Currency."Amount Rounding Precision");
    IF RemLineAmountToInvoice < ("Prepmt. Line Amount" - "Prepmt Amt Deducted") THEN
    FIELDERROR("Prepmt. Line Amount",STRSUBSTNO(Text039,RemLineAmountToInvoice + "Prepmt Amt Deducted"));
    END;
    END;
    END;

    // End of the lines.

    IF PurchHeader.Status = PurchHeader.Status::Released THEN
    ...
  6. Change the code in the CalcVATAmountLines function in the Purchase Line table (39) as follows:
    Existing code 1

    ...
    VATAmountLine."Line Amount" :=

    // Delete the following lines.
    VATAmountLine."Line Amount" +
    (ROUND(QtyToHandle * "Direct Unit Cost" - ("Line Discount Amount" * QtyToHandle / Quantity),
    Currency."Amount Rounding Precision"));
    IF "Allow Invoice Disc." THEN
    VATAmountLine."Inv. Disc. Base Amount" :=
    VATAmountLine."Inv. Disc. Base Amount" +
    (ROUND(QtyToHandle * "Direct Unit Cost" - ("Line Discount Amount" * QtyToHandle / Quantity),
    Currency."Amount Rounding Precision"));
    // End of the lines.

    IF (PurchHeader."Invoice Discount Calculation" <> PurchHeader."Invoice Discount Calculation"::Amount) THEN
    ...

    Replacement code 1

    ...
    VATAmountLine."Line Amount" :=

    // Add the following lines.
    VATAmountLine."Line Amount" + GetLineAmountToHandle(QtyToHandle);
    IF "Allow Invoice Disc." THEN
    VATAmountLine."Inv. Disc. Base Amount" :=
    VATAmountLine."Inv. Disc. Base Amount" + GetLineAmountToHandle(QtyToHandle);
    // End of the lines.

    IF (PurchHeader."Invoice Discount Calculation" <> PurchHeader."Invoice Discount Calculation"::Amount) THEN
    ...

    Existing code 2

    ...
    VATAmountLine."Line Amount" :=

    // Delete the following lines.
    VATAmountLine."Line Amount" +
    (ROUND(QtyToHandle * "Direct Unit Cost" - ("Line Discount Amount" * QtyToHandle / Quantity),
    Currency."Amount Rounding Precision"));
    IF "Allow Invoice Disc." THEN
    VATAmountLine."Inv. Disc. Base Amount" :=
    VATAmountLine."Inv. Disc. Base Amount" +
    (ROUND(QtyToHandle * "Direct Unit Cost" - ("Line Discount Amount" * QtyToHandle / Quantity),
    Currency."Amount Rounding Precision"));
    // End of the lines.

    VATAmountLine."Invoice Discount Amount" :=
    ...

    Replacement code 2

    ...
    VATAmountLine."Line Amount" :=

    // Add the following lines.
    VATAmountLine."Line Amount" + GetLineAmountToHandle(QtyToHandle);
    IF "Allow Invoice Disc." THEN
    VATAmountLine."Inv. Disc. Base Amount" :=
    VATAmountLine."Inv. Disc. Base Amount" + GetLineAmountToHandle(QtyToHandle);
    // End of the lines.

    VATAmountLine."Invoice Discount Amount" :=
    ...
  7. Change the code in the CalcPrepaymentToDeduct function in the Purchase Line table (39) as follows:
    Existing code

    ...
    GetPurchHeader;

    // Delete the following lines.
    "Prepmt Amt to Deduct" :=
    ROUND(
    ("Prepmt. Amt. Inv." - "Prepmt Amt Deducted") *
    "Qty. to Invoice" / (Quantity - "Quantity Invoiced"),Currency."Amount Rounding Precision")
    END ELSE
    "Prepmt Amt to Deduct" := 0
    // End of the lines.

    END;
    ...

    Replacement code

    ...
    GetPurchHeader;

    // Add the following lines.
    IF ("Prepayment %" = 100) AND NOT IsFinalInvoice THEN
    "Prepmt Amt to Deduct" := GetLineAmountToHandle("Qty. to Invoice")
    ELSE
    "Prepmt Amt to Deduct" :=
    ROUND(
    ("Prepmt. Amt. Inv." - "Prepmt Amt Deducted") *
    "Qty. to Invoice" / (Quantity - "Quantity Invoiced"),Currency."Amount Rounding Precision")
    END ELSE
    "Prepmt Amt to Deduct" := 0
    END;

    PROCEDURE IsFinalInvoice@116() : Boolean;
    BEGIN
    EXIT("Qty. to Invoice" = Quantity - "Quantity Invoiced");
    END;

    PROCEDURE GetLineAmountToHandle@117(QtyToHandle@1002 : Decimal) : Decimal;
    VAR
    LineAmount@1001 : Decimal;
    LineDiscAmount@1000 : Decimal;
    BEGIN
    LineAmount := ROUND(QtyToHandle * "Direct Unit Cost",Currency."Amount Rounding Precision");
    LineDiscAmount := ROUND("Line Discount Amount" * QtyToHandle / Quantity,Currency."Amount Rounding Precision");
    EXIT(LineAmount - LineDiscAmount);
    // End of the lines.

    END;
    ...
  8. Change the code in the UpdatePrePaymentAmounts function in the Purchase Line table (39) as follows:
    Existing code 1

    ...
    // Delete the following line.
    LOCAL PROCEDURE UpdatePrePaymentAmounts@65();

    VAR
    ...

    Replacement code 1

    ...
    // Add the following line.
    PROCEDURE UpdatePrePaymentAmounts@65();

    VAR
    ...

    Existing code 2

    ...
    IF PurchOrderLine.GET(PurchOrderLine."Document Type"::Order,ReceiptLine."Order No.",ReceiptLine."Order Line No.") THEN BEGIN

    // Delete the following lines.
    "Prepmt Amt to Deduct" :=
    ROUND((PurchOrderLine."Prepmt. Amt. Inv." - PurchOrderLine."Prepmt Amt Deducted") *
    Quantity / (PurchOrderLine.Quantity - PurchOrderLine."Quantity Invoiced"),Currency."Amount Rounding Precision");
    // End of the lines.

    "Prepmt VAT Diff. to Deduct" := "Prepayment VAT Difference" - "Prepmt VAT Diff. Deducted";
    ...

    Replacement code 2

    ...
    IF PurchOrderLine.GET(PurchOrderLine."Document Type"::Order,ReceiptLine."Order No.",ReceiptLine."Order Line No.") THEN BEGIN

    // Add the following lines.
    IF ("Prepayment %" = 100) AND (Quantity <> PurchOrderLine.Quantity - PurchOrderLine."Quantity Invoiced") THEN
    "Prepmt Amt to Deduct" := "Line Amount"
    ELSE
    "Prepmt Amt to Deduct" :=
    ROUND((PurchOrderLine."Prepmt. Amt. Inv." - PurchOrderLine."Prepmt Amt Deducted") *
    Quantity / (PurchOrderLine.Quantity - PurchOrderLine."Quantity Invoiced"),Currency."Amount Rounding Precision");
    // End of the lines.

    "Prepmt VAT Diff. to Deduct" := "Prepayment VAT Difference" - "Prepmt VAT Diff. Deducted";
    ...
  9. Change the code in the InsertInvLineFromShptLine function in the Sales Shipment Line table (111) as follows:
    Existing code

    ...
    SalesLine."Allow Invoice Disc." := SalesOrderLine."Allow Invoice Disc.";

    // Delete the following line.
    SalesLine.VALIDATE("Line Discount %",SalesOrderLine."Line Discount %");

    SalesSetup.GET;
    ...

    Replacement code

    ...
    SalesLine."Allow Invoice Disc." := SalesOrderLine."Allow Invoice Disc.";

    // Add the following lines.
    SalesLine.VALIDATE(
    "Line Discount Amount",
    ROUND(
    SalesOrderLine."Line Discount Amount" * SalesLine.Quantity / SalesOrderLine.Quantity,
    Currency."Amount Rounding Precision"));
    SalesLine."Line Discount %" := SalesOrderLine."Line Discount %";
    SalesLine.UpdatePrePaymentAmounts;
    // End of the lines.

    SalesSetup.GET;
    ...
  10. Change the code in the InsertInvLineFromRcptLine function in the Purch. Rcpt. Line table (121) as follows:
    Existing code

    ...
    InsertInvLineFromRcptLine
    PurchLine.VALIDATE("Direct Unit Cost",PurchOrderLine."Direct Unit Cost");

    // Delete the following line.
    PurchLine.VALIDATE("Line Discount %",PurchOrderLine."Line Discount %");

    PurchSetup.GET;
    ...

    Replacement code

    ...
    PurchLine.VALIDATE("Direct Unit Cost",PurchOrderLine."Direct Unit Cost");

    // Add the following lines.
    PurchLine.VALIDATE(
    "Line Discount Amount",
    ROUND(
    PurchOrderLine."Line Discount Amount" * PurchLine.Quantity / PurchOrderLine.Quantity,
    Currency."Amount Rounding Precision"));
    PurchLine."Line Discount %" := PurchOrderLine."Line Discount %";
    PurchLine.UpdatePrePaymentAmounts;
    // End of the lines.

    PurchSetup.GET;
    ...
  11. Change the code in the InsertInvLineBuffer function in the Prepayment Inv. Line Buffer table (461) as follows:
    Existing code

    ...
    InsertInvLineBuffer
    MODIFY;

    // Delete the following lines.
    END ELSE BEGIN
    INSERT;
    END;
    // End of the lines.

    END;
    ...

    Replacement code

    ...
    MODIFY;

    // Add the following lines.
    END ELSE
    INSERT;
    // End of the lines.

    END;
    ...
  12. Change the code in the FillAdjInvLineBuf function in the Prepayment Inv. Line Buffer table (461) as follows:
    Existing code

    ...
    // Delete the following line.
    PROCEDURE FillAdjInvLineBuf@6(PrepmtInvLineBuf@1000 : Record 461;GLAccountNo@1003 : Code[20];CorrAmount@1002 : Decimal);

    BEGIN
    ...

    Replacement code

    ...
    // Add the following line.
    PROCEDURE FillAdjInvLineBuffer@6(PrepmtInvLineBuf@1000 : Record 461;GLAccountNo@1003 : Code[20];CorrAmount@1002 : Decimal);

    BEGIN
    ...
  13. Change the code of Properties in the Sales-Post Codeunit (80) as follows:
    Existing code

    ...
    MergeSaleslines(SalesHeader,SalesLine,TempPrepaymentSalesLine,CombinedSalesLineTemp);
    ...

    Replacement code

    ...
    MergeSaleslines(SalesHeader,SalesLine,TempPrepaymentSalesLine,CombinedSalesLineTemp);

    // Add the following line.
    AdjustFinalInvWith100PctPrepmt(CombinedSalesLineTemp);
    ...
  14. Change the code in the InsertPrepmtAdjInvPostingBuf function in the Sales-Post Codeunit (80) as follows:
    Existing code

    ...
    BEGIN

    // Delete the following lines.
    IF PrepmtSalesLine."Prepayment Line" THEN
    IF PrepmtSalesLine."Prepmt. Amount Inv. (LCY)" <> 0 THEN BEGIN
    AdjAmount := -PrepmtSalesLine."Prepmt. Amount Inv. (LCY)";
    FillPrepmtAdjInvPostingBuffer(
    SalesPostPrepayments.GetPrepmtAccNo(
    PrepmtSalesLine."Gen. Bus. Posting Group",PrepmtSalesLine."Gen. Prod. Posting Group"),
    AdjAmount);
    FillPrepmtAdjInvPostingBuffer(
    SalesPostPrepayments.GetCorrBalAccNo(SalesHeader,AdjAmount),
    -AdjAmount);
    END;
    // End of the lines.

    END;
    ...

    Replacement code

    ...
    BEGIN

    // Add the following lines.
    WITH PrepmtSalesLine DO
    IF "Prepayment Line" THEN
    IF "Prepmt. Amount Inv. (LCY)" <> 0 THEN BEGIN
    AdjAmount := -"Prepmt. Amount Inv. (LCY)";
    FillPrepmtAdjInvPostingBuffer("No.",AdjAmount);
    FillPrepmtAdjInvPostingBuffer(
    SalesPostPrepayments.GetCorrBalAccNo(SalesHeader,AdjAmount > 0),
    -AdjAmount);
    END ELSE
    IF ("Prepayment %" = 100) AND ("Prepmt. VAT Amount Inv. (LCY)" <> 0) THEN
    FillPrepmtAdjInvPostingBuffer(
    SalesPostPrepayments.GetInvRoundingAccNo(SalesHeader."Customer Posting Group"),
    "Prepmt. VAT Amount Inv. (LCY)");
    // End of the lines.

    END;
    ...
  15. Change the code in the DivideAmount function in the Sales-Post Codeunit (80) as follows:
    Existing code

    ...
    END;

    // Delete the following lines.
    "Line Amount" := ROUND(SalesLineQty * "Unit Price",Currency."Amount Rounding Precision");
    IF SalesLineQty <> Quantity THEN
    "Line Discount Amount" :=
    ROUND("Line Amount" * "Line Discount %" / 100,Currency."Amount Rounding Precision");
    "Line Amount" := "Line Amount" - "Line Discount Amount";
    // End of the lines.
    ...

    Replacement code

    ...
    END;

    // Add the following lines.
    "Line Amount" := GetLineAmountToHandle(SalesLineQty) + GetPrepmtDiffToLineAmount(SalesLine);
    IF SalesLineQty <> Quantity THEN
    "Line Discount Amount" :=
    ROUND("Line Discount Amount" * SalesLineQty / Quantity,Currency."Amount Rounding Precision");
    // End of the lines.
    ...
  16. Change the code in the CreatePrepaymentLines function in the Sales-Post Codeunit (80) as follows:
    Existing code 1

    ...
    // Delete the following lines.
    CASE TRUE OF
    ("Prepmt Amt to Deduct" <> 0) AND
    ("Prepmt Amt to Deduct" > ROUND(Fraction * "Line Amount",Currency."Amount Rounding Precision")):
    FIELDERROR(
    "Prepmt Amt to Deduct",
    STRSUBSTNO(Text047,
    ROUND(Fraction * "Line Amount",Currency."Amount Rounding Precision")));
    ("Prepmt. Amt. Inv." <> 0) AND
    (ROUND((1 - Fraction) * "Line Amount",Currency."Amount Rounding Precision") <
    ROUND(
    ROUND(
    ROUND("Unit Price" * (Quantity - "Quantity Invoiced" - "Qty. to Invoice"),Currency."Amount Rounding Precision") *
    (1 - ("Line Discount %" / 100)),Currency."Amount Rounding Precision") *
    "Prepayment %" / 100,Currency."Amount Rounding Precision")):
    FIELDERROR(
    "Prepmt Amt to Deduct",
    STRSUBSTNO(Text048,
    ROUND(
    "Prepmt. Amt. Inv." - "Prepmt Amt Deducted" - (1 - Fraction) * "Line Amount",
    Currency."Amount Rounding Precision")));
    END;
    // End of the lines.

    END ELSE
    ...

    Replacement code 1

    ...
    // Add the following lines.
    IF "Prepayment %" <> 100 THEN
    CASE TRUE OF
    ("Prepmt Amt to Deduct" <> 0) AND
    ("Prepmt Amt to Deduct" > ROUND(Fraction * "Line Amount",Currency."Amount Rounding Precision")):
    FIELDERROR(
    "Prepmt Amt to Deduct",
    STRSUBSTNO(Text047,
    ROUND(Fraction * "Line Amount",Currency."Amount Rounding Precision")));
    ("Prepmt. Amt. Inv." <> 0) AND
    (ROUND((1 - Fraction) * "Line Amount",Currency."Amount Rounding Precision") <
    ROUND(
    ROUND(
    ROUND("Unit Price" * (Quantity - "Quantity Invoiced" - "Qty. to Invoice"),Currency."Amount Rounding Precision") *
    (1 - ("Line Discount %" / 100)),Currency."Amount Rounding Precision") *
    "Prepayment %" / 100,Currency."Amount Rounding Precision")):
    FIELDERROR(
    "Prepmt Amt to Deduct",
    STRSUBSTNO(Text048,
    ROUND(
    "Prepmt. Amt. Inv." - "Prepmt Amt Deducted" - (1 - Fraction) * "Line Amount",
    Currency."Amount Rounding Precision")));
    END;
    // End of the lines.

    END ELSE
    ...

    Existing code 2

    ...
    TempPrepmtSalesLine."Prepmt Amt to Deduct" := PrepmtAmtToDeduct;
    TempPrepmtSalesLine.MODIFY;
    ...

    Replacement code 2

    ...
    TempPrepmtSalesLine."Prepmt Amt to Deduct" := PrepmtAmtToDeduct;

    // Add the following lines.
    IF "Prepayment %" < TempPrepmtSalesLine."Prepayment %" THEN
    TempPrepmtSalesLine."Prepayment %" := "Prepayment %";
    // End of the lines.

    TempPrepmtSalesLine.MODIFY;
    ...

    Existing code 3

    ...
    TempPrepmtSalesLine."Prepmt Amt to Deduct" := PrepmtAmtToDeduct;
    TempPrepmtSalesLine."Prepayment Line" := TRUE;
    ...

    Replacement code 3

    ...
    TempPrepmtSalesLine."Prepmt Amt to Deduct" := PrepmtAmtToDeduct;

    // Add the following line.
    TempPrepmtSalesLine."Prepayment %" := "Prepayment %";

    TempPrepmtSalesLine."Prepayment Line" := TRUE;
    ...
  17. Change the code in the InsertedPrepmtVATBaseToDeduct function in the Sales-Post Codeunit (80) as follows:
    Existing code

    ...
    END;

    // Delete the following lines.
    TempPrepmtDeductLCYSalesLine := SalesLine;
    TempPrepmtDeductLCYSalesLine."Attached to Line No." := PrepmtLineNo;
    TempPrepmtDeductLCYSalesLine."VAT Base Amount" := PrepmtVATBaseToDeduct;
    TempPrepmtDeductLCYSalesLine.INSERT;
    // End of the lines.

    EXIT(PrepmtVATBaseToDeduct);
    ...

    Replacement code

    ...
    // Add the following lines.
    WITH TempPrepmtDeductLCYSalesLine DO BEGIN
    TempPrepmtDeductLCYSalesLine := SalesLine;
    IF "Document Type" = "Document Type"::Order THEN
    "Qty. to Invoice" := GetQtyToInvoice(SalesLine)
    ELSE
    GetLineDataFromOrder(TempPrepmtDeductLCYSalesLine);
    CalcPrepaymentToDeduct;
    "Line Amount" := GetLineAmountToHandle("Qty. to Invoice");
    "Attached to Line No." := PrepmtLineNo;
    "VAT Base Amount" := PrepmtVATBaseToDeduct;
    INSERT;
    END;
    // End of the lines.

    EXIT(PrepmtVATBaseToDeduct);
    ...
  18. Change the code in the DividePrepmtAmountLCY function in the Sales-Post Codeunit (80) as follows:
    Existing code 1

    ...
    ActualCurrencyFactor@1002 : Decimal;

    // Delete the following lines.
    PrepmtAmount@1005 : Decimal;
    PrepmtAmtReminder@1004 : Decimal;
    PrepmtAmountRnded@1003 : Decimal;
    // End of the lines.

    BEGIN
    ...

    Replacement code 1

    ...
    ActualCurrencyFactor@1002 : Decimal;
    BEGIN
    ...

    Existing code 2

    ...
    // Delete the following lines.
    TempPrepmtDeductLCYSalesLine.RESET;
    TempPrepmtDeductLCYSalesLine.SETRANGE("Attached to Line No.","Line No.");
    IF TempPrepmtDeductLCYSalesLine.FINDSET(TRUE) THEN
    REPEAT
    PrepmtAmount := PrepmtAmtReminder + ActualCurrencyFactor * TempPrepmtDeductLCYSalesLine."VAT Base Amount";
    PrepmtAmountRnded := ROUND(PrepmtAmount,GLSetup."Amount Rounding Precision");
    PrepmtAmtReminder := PrepmtAmount - PrepmtAmountRnded;
    TempPrepmtDeductLCYSalesLine."Prepmt. Amount Inv. (LCY)" := PrepmtAmountRnded;
    TempPrepmtDeductLCYSalesLine.MODIFY;
    UNTIL TempPrepmtDeductLCYSalesLine.NEXT = 0;
    // End of the lines.

    UNTIL NEXT = 0;
    ...

    Replacement code 2

    ...
    // Add the following lines.
    UpdatePrepmtAmountInvBuf("Line No.",ActualCurrencyFactor);
    UNTIL NEXT = 0;
    END;
    END;

    LOCAL PROCEDURE UpdatePrepmtAmountInvBuf@92(PrepmtSalesLineNo@1000 : Integer;CurrencyFactor@1004 : Decimal);
    VAR
    PrepmtAmtReminder@1002 : Decimal;
    BEGIN
    WITH TempPrepmtDeductLCYSalesLine DO BEGIN
    RESET;
    SETRANGE("Attached to Line No.",PrepmtSalesLineNo);
    IF FINDSET(TRUE) THEN
    REPEAT
    "Prepmt. Amount Inv. (LCY)" :=
    CalcRoundedAmount(CurrencyFactor * "VAT Base Amount",PrepmtAmtReminder);
    MODIFY;
    // End of the lines.

    UNTIL NEXT = 0;
    ...
  19. Change the code in the AdjustPrepmtAmountLCY function in the Sales-Post Codeunit (80) as follows:
    Existing code

    ...
    SalesLine@1005 : Record 37;

    // Delete the following lines.
    DeductionFactor@1001 : Decimal;
    PrepmtAmtLCYDifference@1002 : Decimal;
    TotalPrepmtAmtLCYDifference@1003 : Decimal;
    TotalPrepmtAmtLCY@1004 : Decimal;
    PrepmtVATAmtLCYDifference@1006 : Decimal;
    TotalPrepmtVATAmtLCYDifference@1007 : Decimal;
    TotalPrepmtVATAmtLCY@1008 : Decimal;
    CalculatedVATAmountLCY@1009 : Decimal;
    PrepmtVATAmount@1010 : Decimal;
    PrepmtVATAmtReminder@1011 : Decimal;
    PrepmtVATAmountRnded@1012 : Decimal;
    NewAmountIncludingVAT@1013 : Decimal;
    BEGIN
    IF PrepmtSalesLine."Prepayment Line" THEN BEGIN
    CalculatedVATAmountLCY := PrepmtSalesLine."Amount Including VAT" - PrepmtSalesLine.Amount;

    TempPrepmtDeductLCYSalesLine.SETRANGE("Attached to Line No.",PrepmtSalesLine."Line No.");
    IF TempPrepmtDeductLCYSalesLine.FINDSET(TRUE) THEN
    REPEAT
    SalesLine := TempPrepmtDeductLCYSalesLine;
    SalesLine.FIND;
    IF SalesLine."Document Type" = SalesLine."Document Type"::Invoice THEN
    GetSalesOrderLine(SalesLine,SalesLine);

    SalesLine."Prepmt Amt to Deduct" := CalcPrepmtAmtToDeduct(SalesLine);
    DeductionFactor :=
    SalesLine."Prepmt Amt to Deduct" /
    (SalesLine."Prepmt. Amt. Inv." - SalesLine."Prepmt Amt Deducted");
    PrepmtAmtLCYDifference :=
    TempPrepmtDeductLCYSalesLine."Prepmt. Amount Inv. (LCY)" -
    ROUND(DeductionFactor * SalesLine."Prepmt. Amount Inv. (LCY)");
    TempPrepmtDeductLCYSalesLine."Prepmt. Amount Inv. (LCY)" :=
    TempPrepmtDeductLCYSalesLine."Prepmt. Amount Inv. (LCY)" - PrepmtAmtLCYDifference;

    PrepmtVATAmount :=
    PrepmtVATAmtReminder + CalculatedVATAmountLCY * SalesLine."Prepmt Amt to Deduct" / PrepmtSalesLine."Unit Price";
    PrepmtVATAmountRnded := ROUND(PrepmtVATAmount,GLSetup."Amount Rounding Precision");
    PrepmtVATAmtReminder := PrepmtVATAmount - PrepmtVATAmountRnded;
    TempPrepmtDeductLCYSalesLine."Prepmt. VAT Amount Inv. (LCY)" := PrepmtVATAmountRnded;

    PrepmtVATAmtLCYDifference :=
    TempPrepmtDeductLCYSalesLine."Prepmt. VAT Amount Inv. (LCY)" -
    ROUND(DeductionFactor * SalesLine."Prepmt. VAT Amount Inv. (LCY)");
    TempPrepmtDeductLCYSalesLine."Prepmt. VAT Amount Inv. (LCY)" :=
    TempPrepmtDeductLCYSalesLine."Prepmt. VAT Amount Inv. (LCY)" - PrepmtVATAmtLCYDifference;

    TempPrepmtDeductLCYSalesLine.MODIFY;

    TotalPrepmtAmtLCYDifference := TotalPrepmtAmtLCYDifference + PrepmtAmtLCYDifference;
    TotalPrepmtAmtLCY := TotalPrepmtAmtLCY + TempPrepmtDeductLCYSalesLine."Prepmt. Amount Inv. (LCY)";

    TotalPrepmtVATAmtLCYDifference := TotalPrepmtVATAmtLCYDifference + PrepmtVATAmtLCYDifference;
    TotalPrepmtVATAmtLCY := TotalPrepmtVATAmtLCY + TempPrepmtDeductLCYSalesLine."Prepmt. VAT Amount Inv. (LCY)";
    UNTIL TempPrepmtDeductLCYSalesLine.NEXT = 0;
    IF ABS(TotalPrepmtAmtLCYDifference) <= GLSetup."Amount Rounding Precision" THEN
    TotalPrepmtAmtLCYDifference := 0;
    PrepmtSalesLine."Prepmt. Amount Inv. (LCY)" := TotalPrepmtAmtLCYDifference;
    PrepmtSalesLine.Amount := TotalPrepmtAmtLCY + TotalPrepmtAmtLCYDifference;

    IF ABS(TotalPrepmtVATAmtLCYDifference) <= GLSetup."Amount Rounding Precision" THEN
    TotalPrepmtVATAmtLCYDifference := 0;
    PrepmtSalesLine."Prepmt. VAT Amount Inv. (LCY)" := TotalPrepmtVATAmtLCYDifference;
    NewAmountIncludingVAT := PrepmtSalesLine.Amount + TotalPrepmtVATAmtLCY + TotalPrepmtVATAmtLCYDifference;
    Increment(TotalSalesLineLCY."Amount Including VAT",PrepmtSalesLine."Amount Including VAT" - NewAmountIncludingVAT);
    IF SalesLine."Currency Code" = '' THEN
    TotalSalesLine."Amount Including VAT" := TotalSalesLineLCY."Amount Including VAT";
    PrepmtSalesLine."Amount Including VAT" := NewAmountIncludingVAT;
    END;
    END;

    PROCEDURE CalcPrepmtAmtToDeduct@71(SalesLine@1000 : Record 37) : Decimal;
    // End of the lines.

    VAR
    ...

    Replacement code

    ...
    SalesLine@1005 : Record 37;

    // Add the following lines.
    SalesInvoiceLine@1013 : Record 37;
    DeductionFactor@1001 : Decimal;
    PrepmtVATPart@1009 : Decimal;
    PrepmtVATAmtReminder@1010 : Decimal;
    TotalRoundingAmount@1011 : ARRAY [2] OF Decimal;
    TotalPrepmtAmount@1002 : ARRAY [2] OF Decimal;
    BEGIN
    IF PrepmtSalesLine."Prepayment Line" THEN BEGIN
    PrepmtVATPart :=
    (PrepmtSalesLine."Amount Including VAT" - PrepmtSalesLine.Amount) / PrepmtSalesLine."Unit Price";

    WITH TempPrepmtDeductLCYSalesLine DO BEGIN
    RESET;
    SETRANGE("Attached to Line No.",PrepmtSalesLine."Line No.");
    IF FINDSET(TRUE) THEN
    REPEAT
    SalesLine := TempPrepmtDeductLCYSalesLine;
    SalesLine.FIND;
    IF "Document Type" = "Document Type"::Invoice THEN BEGIN
    SalesInvoiceLine := SalesLine;
    GetSalesOrderLine(SalesLine,SalesInvoiceLine);
    SalesLine."Qty. to Invoice" := SalesInvoiceLine."Qty. to Invoice";
    END;
    SalesLine."Prepmt Amt to Deduct" := CalcPrepmtAmtToDeduct(SalesLine);
    DeductionFactor :=
    SalesLine."Prepmt Amt to Deduct" /
    (SalesLine."Prepmt. Amt. Inv." - SalesLine."Prepmt Amt Deducted");

    "Prepmt. VAT Amount Inv. (LCY)" :=
    CalcRoundedAmount(SalesLine."Prepmt Amt to Deduct" * PrepmtVATPart,PrepmtVATAmtReminder);
    IF ("Prepayment %" <> 100) OR IsFinalInvoice THEN
    CalcPrepmtRoundingAmounts(TempPrepmtDeductLCYSalesLine,SalesLine,DeductionFactor,TotalRoundingAmount);
    MODIFY;

    TotalPrepmtAmount[1] += "Prepmt. Amount Inv. (LCY)";
    TotalPrepmtAmount[2] += "Prepmt. VAT Amount Inv. (LCY)";
    UNTIL NEXT = 0;
    END;

    UpdatePrepmtSalesLineWithRound(PrepmtSalesLine,TotalRoundingAmount,TotalPrepmtAmount);
    END;
    END;

    PROCEDURE CalcPrepmtAmtToDeduct@71(SalesLine@1000 : Record 37) : Decimal;
    BEGIN
    WITH SalesLine DO BEGIN
    "Qty. to Invoice" := GetQtyToInvoice(SalesLine);
    CalcPrepaymentToDeduct;
    EXIT("Prepmt Amt to Deduct");
    END;
    END;

    LOCAL PROCEDURE GetQtyToInvoice@93(SalesLine@1000 : Record 37) : Decimal;
    // End of the lines.

    VAR
    ...
  20. Change the code in the CalcPrepmtAmtToDeduct function in the Sales-Post Codeunit (80) as follows:
    Existing code

    ...
    AllowedQtyToInvoice := AllowedQtyToInvoice + "Qty. to Ship";

    // Delete the following lines.

    IF "Qty. to Invoice" > AllowedQtyToInvoice THEN BEGIN
    "Qty. to Invoice" := AllowedQtyToInvoice;
    CalcPrepaymentToDeduct;
    END;

    EXIT("Prepmt Amt to Deduct");
    END;
    // End of the lines.

    END;
    ...

    Replacement code

    ...
    AllowedQtyToInvoice := AllowedQtyToInvoice + "Qty. to Ship";

    // Add the following lines.
    IF "Qty. to Invoice" > AllowedQtyToInvoice THEN
    EXIT(AllowedQtyToInvoice);
    EXIT("Qty. to Invoice");
    END;
    END;

    LOCAL PROCEDURE GetLineDataFromOrder@94(VAR SalesLine@1000 : Record 37);
    VAR
    SalesShptLine@1001 : Record 111;
    SalesOrderLine@1002 : Record 37;
    BEGIN
    WITH SalesLine DO BEGIN
    SalesShptLine.GET("Shipment No.","Shipment Line No.");
    SalesOrderLine.GET("Document Type"::Order,SalesShptLine."Order No.",SalesShptLine."Order Line No.");

    Quantity := SalesOrderLine.Quantity;
    "Qty. Shipped Not Invoiced" := SalesOrderLine."Qty. Shipped Not Invoiced";
    "Quantity Invoiced" := SalesOrderLine."Quantity Invoiced";
    "Prepmt Amt Deducted" := SalesOrderLine."Prepmt Amt Deducted";
    "Prepmt. Amt. Inv." := SalesOrderLine."Prepmt. Amt. Inv.";
    "Line Discount Amount" := SalesOrderLine."Line Discount Amount";
    END;
    END;

    LOCAL PROCEDURE CalcPrepmtRoundingAmounts@79(VAR PrepmtSalesLineBuf@1000 : Record 37;SalesLine@1003 : Record 37;DeductionFactor@1001 : Decimal;VAR TotalRoundingAmount@1002 : ARRAY [2] OF Decimal);
    VAR
    RoundingAmount@1004 : ARRAY [2] OF Decimal;
    BEGIN
    WITH PrepmtSalesLineBuf DO BEGIN
    RoundingAmount[1] :=
    "Prepmt. Amount Inv. (LCY)" - ROUND(DeductionFactor * SalesLine."Prepmt. Amount Inv. (LCY)");
    "Prepmt. Amount Inv. (LCY)" := "Prepmt. Amount Inv. (LCY)" - RoundingAmount[1];
    TotalRoundingAmount[1] += RoundingAmount[1];

    RoundingAmount[2] :=
    "Prepmt. VAT Amount Inv. (LCY)" - ROUND(DeductionFactor * SalesLine."Prepmt. VAT Amount Inv. (LCY)");
    "Prepmt. VAT Amount Inv. (LCY)" := "Prepmt. VAT Amount Inv. (LCY)" - RoundingAmount[2];
    TotalRoundingAmount[2] += RoundingAmount[2];
    END;
    END;

    LOCAL PROCEDURE UpdatePrepmtSalesLineWithRound@89(VAR PrepmtSalesLine@1002 : Record 37;TotalRoundingAmount@1001 : ARRAY [2] OF Decimal;TotalPrepmtAmount@1000 : ARRAY [2] OF Decimal);
    VAR
    NewAmountIncludingVAT@1003 : Decimal;
    Prepmt100PctVATRoundingAmt@1004 : Decimal;
    BEGIN
    WITH PrepmtSalesLine DO BEGIN
    IF ABS(TotalRoundingAmount[1]) <= GLSetup."Amount Rounding Precision" THEN BEGIN
    IF "Prepayment %" = 100 THEN
    Prepmt100PctVATRoundingAmt := TotalRoundingAmount[1];
    TotalRoundingAmount[1] := 0;
    END;
    "Prepmt. Amount Inv. (LCY)" := TotalRoundingAmount[1];
    Amount := TotalPrepmtAmount[1] + TotalRoundingAmount[1];

    IF ABS(TotalRoundingAmount[2]) <= GLSetup."Amount Rounding Precision" THEN BEGIN
    IF ("Prepayment %" = 100) AND ("Prepmt. Amount Inv. (LCY)" = 0) THEN
    Prepmt100PctVATRoundingAmt += TotalRoundingAmount[2];
    TotalRoundingAmount[2] := 0;
    END;
    "Prepmt. VAT Amount Inv. (LCY)" := TotalRoundingAmount[2] + Prepmt100PctVATRoundingAmt;
    NewAmountIncludingVAT := Amount + TotalPrepmtAmount[2] + TotalRoundingAmount[2];
    Increment(TotalSalesLineLCY."Amount Including VAT","Amount Including VAT" - NewAmountIncludingVAT - Prepmt100PctVATRoundingAmt);
    IF "Currency Code" = '' THEN
    TotalSalesLine."Amount Including VAT" := TotalSalesLineLCY."Amount Including VAT";
    "Amount Including VAT" := NewAmountIncludingVAT;
    END;
    END;

    LOCAL PROCEDURE CalcRoundedAmount@91(Amount@1000 : Decimal;VAR Reminder@1001 : Decimal) : Decimal;
    VAR
    AmountRnded@1002 : Decimal;
    BEGIN
    Amount := Amount + Reminder;
    AmountRnded := ROUND(Amount,GLSetup."Amount Rounding Precision");
    Reminder := Amount - AmountRnded;
    EXIT(AmountRnded);
    // End of the lines.

    END;
    ...
  21. Change the code in the AdjustFinalInvWith100PctPrepmt function in the Sales-Post Codeunit (80) as follows:
    Existing code

    ...
    PROCEDURE MergeSaleslines@52(SalesHeader@1000000004 : Record 36;VAR Salesline@1000 : Record 37;VAR Salesline2@1000000002 : Record 37;VAR MergedSalesline@1000000003 : Record 37);
    ...

    Replacement code

    ...
    // Add the following lines.
    LOCAL PROCEDURE AdjustFinalInvWith100PctPrepmt@97(VAR TempSalesLine@1000 : TEMPORARY Record 37);
    VAR
    DiffToLineDiscAmt@1001 : Decimal;
    BEGIN
    WITH TempPrepmtDeductLCYSalesLine DO BEGIN
    RESET;
    SETRANGE("Prepayment %",100);
    IF FINDSET(TRUE) THEN
    REPEAT
    IF IsFinalInvoice THEN BEGIN
    DiffToLineDiscAmt := "Prepmt Amt to Deduct" - "Line Amount";
    IF "Document Type" = "Document Type"::Order THEN
    DiffToLineDiscAmt := DiffToLineDiscAmt * Quantity / "Qty. to Invoice";
    IF DiffToLineDiscAmt <> 0 THEN BEGIN
    TempSalesLine.GET("Document Type","Document No.","Line No.");
    TempSalesLine."Line Discount Amount" -= DiffToLineDiscAmt;
    TempSalesLine.MODIFY;

    "Line Discount Amount" := TempSalesLine."Line Discount Amount";
    MODIFY;
    END;
    END;
    UNTIL NEXT = 0;
    RESET;
    END;
    END;

    LOCAL PROCEDURE GetPrepmtDiffToLineAmount@98(SalesLine@1000 : Record 37) : Decimal;
    BEGIN
    WITH TempPrepmtDeductLCYSalesLine DO
    IF (SalesLine."Prepayment %" = 100) THEN
    IF GET(SalesLine."Document Type",SalesLine."Document No.",SalesLine."Line No.") THEN
    EXIT("Prepmt Amt to Deduct" - "Line Amount");
    EXIT(0);
    END;

    // End of the lines.

    PROCEDURE MergeSaleslines@52(SalesHeader@1000000004 : Record 36;VAR Salesline@1000 : Record 37;VAR Salesline2@1000000002 : Record 37;VAR MergedSalesline@1000000003 : Record 37);
    ...
  22. Change the code in the TestGetShipmentPPmtAmtToDeduct function in the Sales-Post Codeunit (80) as follows:
    Existing code

    ...
    TempTotalSalesLine."Prepmt Amt to Deduct" := TempTotalSalesLine."Prepmt Amt to Deduct" + SalesLine2."Prepmt Amt to Deduct";
    TempTotalSalesLine.MODIFY;
    ...

    Replacement code

    ...
    TempTotalSalesLine."Prepmt Amt to Deduct" := TempTotalSalesLine."Prepmt Amt to Deduct" + SalesLine2."Prepmt Amt to Deduct";

    // Add the following line.
    AdjustInvLineWith100PctPrepmt(SalesLine2,TempTotalSalesLine);

    TempTotalSalesLine.MODIFY;
    ...
  23. Change the code in the AdjustInvLineWith100PctPrepmt function in the Sales-Post Codeunit (80) as follows:
    Existing code

    ...
    PROCEDURE ArchiveUnpostedOrder@56();
    ...

    Replacement code

    ...
    // Add the following lines.
    LOCAL PROCEDURE AdjustInvLineWith100PctPrepmt@99(VAR SalesInvoiceLine@1000 : Record 37;VAR TempTotalSalesLine@1001 : TEMPORARY Record 37);
    VAR
    SalesOrderLine@1003 : Record 37;
    DiffAmtToDeduct@1002 : Decimal;
    BEGIN
    IF SalesInvoiceLine."Prepayment %" = 100 THEN BEGIN
    SalesOrderLine := TempTotalSalesLine;
    SalesOrderLine.FIND;
    IF TempTotalSalesLine."Qty. to Invoice" = SalesOrderLine.Quantity - SalesOrderLine."Quantity Invoiced" THEN BEGIN
    DiffAmtToDeduct :=
    SalesOrderLine."Prepmt. Amt. Inv." - SalesOrderLine."Prepmt Amt Deducted" - TempTotalSalesLine."Prepmt Amt to Deduct";
    IF DiffAmtToDeduct <> 0 THEN BEGIN
    SalesInvoiceLine."Prepmt Amt to Deduct" := SalesInvoiceLine."Prepmt Amt to Deduct" + DiffAmtToDeduct;
    SalesInvoiceLine."Line Amount" := SalesInvoiceLine."Prepmt Amt to Deduct";
    SalesInvoiceLine."Line Discount Amount" := SalesInvoiceLine."Line Discount Amount" - DiffAmtToDeduct;
    SalesInvoiceLine.MODIFY;
    TempTotalSalesLine."Prepmt Amt to Deduct" := TempTotalSalesLine."Prepmt Amt to Deduct" + DiffAmtToDeduct;
    END;
    END;
    END;
    END;

    // End of the lines.

    PROCEDURE ArchiveUnpostedOrder@56();
    ...
  24. Change the code of Properties in the Purch.-Post codeunit (90) as follows:
    Existing code 1

    ...
    MergePurchLines(PurchHeader,PurchLine,TempPrepmtPurchLine,CombinedPurchLineTemp);
    ...

    Replacement code 1

    ...
    MergePurchLines(PurchHeader,PurchLine,TempPrepmtPurchLine,CombinedPurchLineTemp);

    // Add the following line.
    AdjustFinalInvWith100PctPrepmt(CombinedPurchLineTemp);
    ...

    Existing code 2

    ...
    Window.UPDATE(2,LineCount);

    // Delete the following lines.
    IF Invoice THEN
    TestPrepmtAmount;
    // End of the lines.

    IF PurchLine.Type = PurchLine.Type::"Charge (Item)" THEN BEGIN
    ...

    Replacement code 2

    ...
    Window.UPDATE(2,LineCount);
    IF PurchLine.Type = PurchLine.Type::"Charge (Item)" THEN BEGIN
    ...
  25. Delete the following global variable in the Purch.-Post codeunit (90):

    Text049@1174 : TextConst 'ENU=must be fully preinvoiced before you can ship or invoice %1.';
  26. Change the code in the InsertPrepmtAdjInvPostingBuf function in the Purch.-Post codeunit (90) as follows:
    Existing code

    ...
    BEGIN

    // Delete the following lines.
    IF PrepmtPurchLine."Prepayment Line" THEN
    IF PrepmtPurchLine."Prepmt. Amount Inv. (LCY)" <> 0 THEN BEGIN
    AdjAmount := -PrepmtPurchLine."Prepmt. Amount Inv. (LCY)";
    FillPrepmtAdjInvPostingBuffer(
    PurchPostPrepayments.GetPrepmtAccNo(
    PrepmtPurchLine."Gen. Bus. Posting Group",PrepmtPurchLine."Gen. Prod. Posting Group"),
    AdjAmount);
    FillPrepmtAdjInvPostingBuffer(
    PurchPostPrepayments.GetCorrBalAccNo(PurchHeader,AdjAmount),
    -AdjAmount);
    END;
    // End of the lines.

    END;
    ...

    Replacement code

    ...
    BEGIN

    // Add the following lines.
    WITH PrepmtPurchLine DO
    IF "Prepayment Line" THEN
    IF "Prepmt. Amount Inv. (LCY)" <> 0 THEN BEGIN
    AdjAmount := -"Prepmt. Amount Inv. (LCY)";
    FillPrepmtAdjInvPostingBuffer("No.",AdjAmount);
    FillPrepmtAdjInvPostingBuffer(
    PurchPostPrepayments.GetCorrBalAccNo(PurchHeader,AdjAmount > 0),
    -AdjAmount);
    END ELSE
    IF ("Prepayment %" = 100) AND ("Prepmt. VAT Amount Inv. (LCY)" <> 0) THEN
    FillPrepmtAdjInvPostingBuffer(
    PurchPostPrepayments.GetInvRoundingAccNo(PurchHeader."Vendor Posting Group"),
    "Prepmt. VAT Amount Inv. (LCY)");
    // End of the lines.

    END;
    ...
  27. Change the code in the DivideAmount function in the Purch.-Post codeunit (90) as follows:
    Existing code

    ...
    END;

    // Delete the following lines.
    "Line Amount" := ROUND(PurchLineQty * "Direct Unit Cost",Currency."Amount Rounding Precision");
    IF PurchLineQty <> Quantity THEN
    "Line Discount Amount" :=
    ROUND("Line Amount" * "Line Discount %" / 100,Currency."Amount Rounding Precision");
    "Line Amount" := "Line Amount" - "Line Discount Amount";
    // End of the lines.
    ...

    Replacement code

    ...
    END;

    // Add the following lines.
    "Line Amount" := GetLineAmountToHandle(PurchLineQty) + GetPrepmtDiffToLineAmount(PurchLine);
    IF PurchLineQty <> Quantity THEN
    "Line Discount Amount" :=
    ROUND("Line Discount Amount" * PurchLineQty / Quantity,Currency."Amount Rounding Precision");
    // End of the lines.
    ...
  28. Delete the TestPrepmtAmount function in the Purch.-Post codeunit (90).

  29. Change the code in the CreatePrepmtLines function in the Purch.-Post codeunit (90) as follows:
    Existing code 1

    ...
    // Delete the following lines.
    CASE TRUE OF
    ("Prepmt Amt to Deduct" <> 0) AND
    (ROUND(Fraction * "Line Amount",Currency."Amount Rounding Precision") < "Prepmt Amt to Deduct"):
    FIELDERROR(
    "Prepmt Amt to Deduct",
    STRSUBSTNO(
    Text047,
    ROUND(Fraction * "Line Amount",Currency."Amount Rounding Precision")));
    ("Prepmt. Amt. Inv." <> 0) AND
    (ROUND((1 - Fraction) * "Line Amount",Currency."Amount Rounding Precision") <
    ROUND(
    ROUND(
    ROUND("Direct Unit Cost" * (Quantity - "Quantity Invoiced" - "Qty. to Invoice"),
    Currency."Amount Rounding Precision") *
    (1 - "Line Discount %" / 100),Currency."Amount Rounding Precision") *
    "Prepayment %" / 100,Currency."Amount Rounding Precision")):
    FIELDERROR(
    "Prepmt Amt to Deduct",
    STRSUBSTNO(
    Text048,
    ROUND(
    "Prepmt. Amt. Inv." - "Prepmt Amt Deducted" -
    (1 - Fraction) * "Line Amount",Currency."Amount Rounding Precision")));
    END;
    // End of the lines.

    END ELSE
    ...

    Replacement code 1

    ...
    // Add the following lines.
    IF "Prepayment %" <> 100 THEN
    CASE TRUE OF
    ("Prepmt Amt to Deduct" <> 0) AND
    (ROUND(Fraction * "Line Amount",Currency."Amount Rounding Precision") < "Prepmt Amt to Deduct"):
    FIELDERROR(
    "Prepmt Amt to Deduct",
    STRSUBSTNO(
    Text047,
    ROUND(Fraction * "Line Amount",Currency."Amount Rounding Precision")));
    ("Prepmt. Amt. Inv." <> 0) AND
    (ROUND((1 - Fraction) * "Line Amount",Currency."Amount Rounding Precision") <
    ROUND(
    ROUND(
    ROUND("Direct Unit Cost" * (Quantity - "Quantity Invoiced" - "Qty. to Invoice"),
    Currency."Amount Rounding Precision") *
    (1 - "Line Discount %" / 100),Currency."Amount Rounding Precision") *
    "Prepayment %" / 100,Currency."Amount Rounding Precision")):
    FIELDERROR(
    "Prepmt Amt to Deduct",
    STRSUBSTNO(
    Text048,
    ROUND(
    "Prepmt. Amt. Inv." - "Prepmt Amt Deducted" -
    (1 - Fraction) * "Line Amount",Currency."Amount Rounding Precision")));
    END;
    // End of the lines.

    END ELSE
    ...

    Existing code 2

    ...
    TempPrepmtPurchLine."Prepmt Amt to Deduct" := PrepmtAmtToDeduct;
    TempPrepmtPurchLine.MODIFY;
    ...

    Replacement code 2

    ...
    TempPrepmtPurchLine."Prepmt Amt to Deduct" := PrepmtAmtToDeduct;

    // Add the following lines.
    IF "Prepayment %" < TempPrepmtPurchLine."Prepayment %" THEN
    TempPrepmtPurchLine."Prepayment %" := "Prepayment %";
    // End of the lines.

    TempPrepmtPurchLine.MODIFY;
    ...

    Existing code 3

    ...
    TempPrepmtPurchLine."Prepmt Amt to Deduct" := PrepmtAmtToDeduct;
    TempPrepmtPurchLine."Prepayment Line" := TRUE;
    ...

    Replacement code 3

    ...
    TempPrepmtPurchLine."Prepmt Amt to Deduct" := PrepmtAmtToDeduct;

    // Add the following line.
    TempPrepmtPurchLine."Prepayment %" := "Prepayment %";

    TempPrepmtPurchLine."Prepayment Line" := TRUE;
    ...
  30. Change the code in the InsertedPrepmtVATBaseToDeduct function in the Purch.-Post codeunit (90) as follows:
    Existing code

    ...
    END;

    // Delete the following lines.
    TempPrepmtDeductLCYPurchLine := PurchLine;
    TempPrepmtDeductLCYPurchLine."Attached to Line No." := PrepmtLineNo;
    TempPrepmtDeductLCYPurchLine."VAT Base Amount" := PrepmtVATBaseToDeduct;
    TempPrepmtDeductLCYPurchLine.INSERT;
    // End of the lines.

    EXIT(PrepmtVATBaseToDeduct);
    ...

    Replacement code

    ...
    END;

    // Add the following lines.
    WITH TempPrepmtDeductLCYPurchLine DO BEGIN
    TempPrepmtDeductLCYPurchLine := PurchLine;
    IF "Document Type" = "Document Type"::Order THEN
    "Qty. to Invoice" := GetQtyToInvoice(PurchLine)
    ELSE
    GetLineDataFromOrder(TempPrepmtDeductLCYPurchLine);
    CalcPrepaymentToDeduct;
    "Line Amount" := GetLineAmountToHandle("Qty. to Invoice");
    "Attached to Line No." := PrepmtLineNo;
    "VAT Base Amount" := PrepmtVATBaseToDeduct;
    INSERT;
    END;
    // End of the lines.

    EXIT(PrepmtVATBaseToDeduct);
    ...
  31. Change the code in the DividePrepmtAmountLCY function in the Purch.-Post codeunit (90) as follows:
    Existing code 1

    ...
    ActualCurrencyFactor@1002 : Decimal;

    // Delete the following lines.
    PrepmtAmount@1005 : Decimal;
    PrepmtAmtReminder@1004 : Decimal;
    PrepmtAmountRnded@1003 : Decimal;
    // End of the lines.

    BEGIN
    ...

    Replacement code 1

    ...
    ActualCurrencyFactor@1002 : Decimal;
    BEGIN
    ...

    Existing code 2

    ...

    // Delete the following lines.
    TempPrepmtDeductLCYPurchLine.RESET;
    TempPrepmtDeductLCYPurchLine.SETRANGE("Attached to Line No.","Line No.");
    IF TempPrepmtDeductLCYPurchLine.FINDSET(TRUE) THEN
    REPEAT
    PrepmtAmount := PrepmtAmtReminder + ActualCurrencyFactor * TempPrepmtDeductLCYPurchLine."VAT Base Amount";
    PrepmtAmountRnded := ROUND(PrepmtAmount,GLSetup."Amount Rounding Precision");
    PrepmtAmtReminder := PrepmtAmount - PrepmtAmountRnded;
    TempPrepmtDeductLCYPurchLine."Prepmt. Amount Inv. (LCY)" := PrepmtAmountRnded;
    TempPrepmtDeductLCYPurchLine.MODIFY;
    UNTIL TempPrepmtDeductLCYPurchLine.NEXT = 0;
    // End of the lines.

    UNTIL NEXT = 0;
    ...

    Replacement code 2

    ...
    // Add the following lines.
    UpdatePrepmtAmountInvBuf("Line No.",ActualCurrencyFactor);
    UNTIL NEXT = 0;
    END;
    END;

    LOCAL PROCEDURE UpdatePrepmtAmountInvBuf@78(PrepmtSalesLineNo@1000 : Integer;CurrencyFactor@1004 : Decimal);
    VAR
    PrepmtAmtReminder@1002 : Decimal;
    BEGIN
    WITH TempPrepmtDeductLCYPurchLine DO BEGIN
    RESET;
    SETRANGE("Attached to Line No.",PrepmtSalesLineNo);
    IF FINDSET(TRUE) THEN
    REPEAT
    "Prepmt. Amount Inv. (LCY)" :=
    CalcRoundedAmount(CurrencyFactor * "VAT Base Amount",PrepmtAmtReminder);
    MODIFY;
    // End of the lines.

    UNTIL NEXT = 0;
    ...
  32. Change the code in the AdjustPrepmtAmountLCY function in the Purch.-Post codeunit (90) as follows:
    Existing code

    ...
    PurchLine@1005 : Record 39;

    // Delete the following lines.
    DeductionFactor@1001 : Decimal;
    PrepmtAmtLCYDifference@1002 : Decimal;
    TotalPrepmtAmtLCYDifference@1003 : Decimal;
    TotalPrepmtAmtLCY@1004 : Decimal;
    PrepmtVATAmtLCYDifference@1006 : Decimal;
    TotalPrepmtVATAmtLCYDifference@1007 : Decimal;
    TotalPrepmtVATAmtLCY@1008 : Decimal;
    CalculatedVATAmountLCY@1009 : Decimal;
    PrepmtVATAmount@1010 : Decimal;
    PrepmtVATAmtReminder@1011 : Decimal;
    PrepmtVATAmountRnded@1012 : Decimal;
    NewAmountIncludingVAT@1013 : Decimal;
    BEGIN
    IF PrepmtPurchLine."Prepayment Line" THEN BEGIN
    CalculatedVATAmountLCY := PrepmtPurchLine."Amount Including VAT" - PrepmtPurchLine.Amount;

    TempPrepmtDeductLCYPurchLine.SETRANGE("Attached to Line No.",PrepmtPurchLine."Line No.");
    IF TempPrepmtDeductLCYPurchLine.FINDSET(TRUE) THEN
    REPEAT
    PurchLine := TempPrepmtDeductLCYPurchLine;
    PurchLine.FIND;
    IF PurchLine."Document Type" = PurchLine."Document Type"::Invoice THEN
    GetPurchOrderLine(PurchLine,PurchLine);

    PurchLine."Prepmt Amt to Deduct" := CalcPrepmtAmtToDeduct(PurchLine);
    DeductionFactor :=
    PurchLine."Prepmt Amt to Deduct" /
    (PurchLine."Prepmt. Amt. Inv." - PurchLine."Prepmt Amt Deducted");
    PrepmtAmtLCYDifference :=
    TempPrepmtDeductLCYPurchLine."Prepmt. Amount Inv. (LCY)" -
    ROUND(DeductionFactor * PurchLine."Prepmt. Amount Inv. (LCY)");
    TempPrepmtDeductLCYPurchLine."Prepmt. Amount Inv. (LCY)" :=
    TempPrepmtDeductLCYPurchLine."Prepmt. Amount Inv. (LCY)" - PrepmtAmtLCYDifference;

    PrepmtVATAmount :=
    PrepmtVATAmtReminder + CalculatedVATAmountLCY * PurchLine."Prepmt Amt to Deduct" / PrepmtPurchLine."Direct Unit Cost";
    PrepmtVATAmountRnded := ROUND(PrepmtVATAmount,GLSetup."Amount Rounding Precision");
    PrepmtVATAmtReminder := PrepmtVATAmount - PrepmtVATAmountRnded;
    TempPrepmtDeductLCYPurchLine."Prepmt. VAT Amount Inv. (LCY)" := -PrepmtVATAmountRnded;

    PrepmtVATAmtLCYDifference :=
    TempPrepmtDeductLCYPurchLine."Prepmt. VAT Amount Inv. (LCY)" -
    ROUND(DeductionFactor * PurchLine."Prepmt. VAT Amount Inv. (LCY)");
    TempPrepmtDeductLCYPurchLine."Prepmt. VAT Amount Inv. (LCY)" :=
    TempPrepmtDeductLCYPurchLine."Prepmt. VAT Amount Inv. (LCY)" - PrepmtVATAmtLCYDifference;

    TempPrepmtDeductLCYPurchLine.MODIFY;

    TotalPrepmtAmtLCYDifference := TotalPrepmtAmtLCYDifference + PrepmtAmtLCYDifference;
    TotalPrepmtAmtLCY := TotalPrepmtAmtLCY + TempPrepmtDeductLCYPurchLine."Prepmt. Amount Inv. (LCY)";

    TotalPrepmtVATAmtLCYDifference := TotalPrepmtVATAmtLCYDifference + PrepmtVATAmtLCYDifference;
    TotalPrepmtVATAmtLCY := TotalPrepmtVATAmtLCY + TempPrepmtDeductLCYPurchLine."Prepmt. VAT Amount Inv. (LCY)";
    UNTIL TempPrepmtDeductLCYPurchLine.NEXT = 0;
    IF ABS(TotalPrepmtAmtLCYDifference) <= GLSetup."Amount Rounding Precision" THEN
    TotalPrepmtAmtLCYDifference := 0;
    PrepmtPurchLine."Prepmt. Amount Inv. (LCY)" := -TotalPrepmtAmtLCYDifference;
    PrepmtPurchLine.Amount := -(TotalPrepmtAmtLCY + TotalPrepmtAmtLCYDifference);

    IF ABS(TotalPrepmtVATAmtLCYDifference) <= GLSetup."Amount Rounding Precision" THEN
    TotalPrepmtVATAmtLCYDifference := 0;
    PrepmtPurchLine."Prepmt. VAT Amount Inv. (LCY)" := -TotalPrepmtVATAmtLCYDifference;
    NewAmountIncludingVAT := PrepmtPurchLine.Amount - (TotalPrepmtVATAmtLCY + TotalPrepmtVATAmtLCYDifference);

    Increment(TotalPurchLineLCY."Amount Including VAT",-(PrepmtPurchLine."Amount Including VAT" - NewAmountIncludingVAT));
    IF PurchLine."Currency Code" = '' THEN
    TotalPurchLine."Amount Including VAT" := TotalPurchLineLCY."Amount Including VAT";
    PrepmtPurchLine."Amount Including VAT" := NewAmountIncludingVAT;
    END;
    END;

    LOCAL PROCEDURE CalcPrepmtAmtToDeduct@71(PurchLine@1000 : Record 39) : Decimal;
    // End of the lines.

    VAR
    ...

    Replacement code

    ...
    PurchLine@1005 : Record 39;

    // Add the following lines.
    PurchInvoiceLine@1013 : Record 39;
    DeductionFactor@1001 : Decimal;
    PrepmtVATPart@1006 : Decimal;
    PrepmtVATAmtReminder@1011 : Decimal;
    TotalRoundingAmount@1002 : ARRAY [2] OF Decimal;
    TotalPrepmtAmount@1003 : ARRAY [2] OF Decimal;
    BEGIN
    IF PrepmtPurchLine."Prepayment Line" THEN BEGIN
    PrepmtVATPart :=
    (PrepmtPurchLine."Amount Including VAT" - PrepmtPurchLine.Amount) / PrepmtPurchLine."Direct Unit Cost";

    WITH TempPrepmtDeductLCYPurchLine DO BEGIN
    RESET;
    SETRANGE("Attached to Line No.",PrepmtPurchLine."Line No.");
    IF FINDSET(TRUE) THEN
    REPEAT
    PurchLine := TempPrepmtDeductLCYPurchLine;
    PurchLine.FIND;
    IF "Document Type" = "Document Type"::Invoice THEN BEGIN
    PurchInvoiceLine := PurchLine;
    GetPurchOrderLine(PurchLine,PurchInvoiceLine);
    PurchLine."Qty. to Invoice" := PurchInvoiceLine."Qty. to Invoice";
    END;
    PurchLine."Prepmt Amt to Deduct" := CalcPrepmtAmtToDeduct(PurchLine);
    DeductionFactor :=
    PurchLine."Prepmt Amt to Deduct" /
    (PurchLine."Prepmt. Amt. Inv." - PurchLine."Prepmt Amt Deducted");

    "Prepmt. VAT Amount Inv. (LCY)" :=
    -CalcRoundedAmount(PurchLine."Prepmt Amt to Deduct" * PrepmtVATPart,PrepmtVATAmtReminder);
    IF ("Prepayment %" <> 100) OR IsFinalInvoice THEN
    CalcPrepmtRoundingAmounts(TempPrepmtDeductLCYPurchLine,PurchLine,DeductionFactor,TotalRoundingAmount);
    MODIFY;

    TotalPrepmtAmount[1] += "Prepmt. Amount Inv. (LCY)";
    TotalPrepmtAmount[2] += "Prepmt. VAT Amount Inv. (LCY)";
    UNTIL NEXT = 0;
    END;

    UpdatePrepmtPurchLineWithRound(PrepmtPurchLine,TotalRoundingAmount,TotalPrepmtAmount);
    END;
    END;

    LOCAL PROCEDURE CalcPrepmtAmtToDeduct@71(PurchLine@1000 : Record 39) : Decimal;
    BEGIN
    WITH PurchLine DO BEGIN
    "Qty. to Invoice" := GetQtyToInvoice(PurchLine);
    CalcPrepaymentToDeduct;
    EXIT("Prepmt Amt to Deduct");
    END;
    END;

    LOCAL PROCEDURE GetQtyToInvoice@94(PurchLine@1000 : Record 39) : Decimal;
    // End of the lines.

    VAR
    ...
  33. Change the code in the CalcPrepmtAmtToDeduct function in the Purch.-Post codeunit (90) as follows:
    Existing code

    ...
    AllowedQtyToInvoice := AllowedQtyToInvoice + "Qty. to Receive";

    // Delete the following lines.

    IF "Qty. to Invoice" > AllowedQtyToInvoice THEN BEGIN
    "Qty. to Invoice" := AllowedQtyToInvoice;
    CalcPrepaymentToDeduct;
    END;
    EXIT("Prepmt Amt to Deduct");
    END;
    // End of the lines.

    END;
    ...

    Replacement code

    ...
    AllowedQtyToInvoice := AllowedQtyToInvoice + "Qty. to Receive";

    // Add the following lines.
    IF "Qty. to Invoice" > AllowedQtyToInvoice THEN
    EXIT(AllowedQtyToInvoice);
    EXIT("Qty. to Invoice");
    END;
    END;

    LOCAL PROCEDURE GetLineDataFromOrder@95(VAR PurchLine@1000 : Record 39);
    VAR
    PurchRcptLine@1001 : Record 121;
    PurchOrderLine@1002 : Record 39;
    BEGIN
    WITH PurchLine DO BEGIN
    PurchRcptLine.GET("Receipt No.","Receipt Line No.");
    PurchOrderLine.GET("Document Type"::Order,PurchRcptLine."Order No.",PurchRcptLine."Order Line No.");

    Quantity := PurchOrderLine.Quantity;
    "Qty. Rcd. Not Invoiced" := PurchOrderLine."Qty. Rcd. Not Invoiced";
    "Quantity Invoiced" := PurchOrderLine."Quantity Invoiced";
    "Prepmt Amt Deducted" := PurchOrderLine."Prepmt Amt Deducted";
    "Prepmt. Amt. Inv." := PurchOrderLine."Prepmt. Amt. Inv.";
    "Line Discount Amount" := PurchOrderLine."Line Discount Amount";
    END;
    END;

    LOCAL PROCEDURE CalcPrepmtRoundingAmounts@58(VAR PrepmtPurchLineBuf@1000 : Record 39;PurchLine@1003 : Record 39;DeductionFactor@1001 : Decimal;VAR TotalRoundingAmount@1002 : ARRAY [2] OF Decimal);
    VAR
    RoundingAmount@1004 : ARRAY [2] OF Decimal;
    BEGIN
    WITH PrepmtPurchLineBuf DO BEGIN
    RoundingAmount[1] :=
    "Prepmt. Amount Inv. (LCY)" - ROUND(DeductionFactor * PurchLine."Prepmt. Amount Inv. (LCY)");
    "Prepmt. Amount Inv. (LCY)" := "Prepmt. Amount Inv. (LCY)" - RoundingAmount[1];
    TotalRoundingAmount[1] += RoundingAmount[1];

    RoundingAmount[2] :=
    "Prepmt. VAT Amount Inv. (LCY)" - ROUND(DeductionFactor * PurchLine."Prepmt. VAT Amount Inv. (LCY)");
    "Prepmt. VAT Amount Inv. (LCY)" := "Prepmt. VAT Amount Inv. (LCY)" - RoundingAmount[2];
    TotalRoundingAmount[2] += RoundingAmount[2];
    END;
    END;

    LOCAL PROCEDURE UpdatePrepmtPurchLineWithRound@89(VAR PrepmtPurchLine@1002 : Record 39;TotalRoundingAmount@1001 : ARRAY [2] OF Decimal;TotalPrepmtAmount@1000 : ARRAY [2] OF Decimal);
    VAR
    NewAmountIncludingVAT@1003 : Decimal;
    Prepmt100PctVATRoundingAmt@1004 : Decimal;
    BEGIN
    WITH PrepmtPurchLine DO BEGIN
    IF ABS(TotalRoundingAmount[1]) <= GLSetup."Amount Rounding Precision" THEN BEGIN
    IF "Prepayment %" = 100 THEN
    Prepmt100PctVATRoundingAmt := TotalRoundingAmount[1];
    TotalRoundingAmount[1] := 0;
    END;
    "Prepmt. Amount Inv. (LCY)" := -TotalRoundingAmount[1];
    Amount := -(TotalPrepmtAmount[1] + TotalRoundingAmount[1]);

    IF ABS(TotalRoundingAmount[2]) <= GLSetup."Amount Rounding Precision" THEN BEGIN
    IF ("Prepayment %" = 100) AND ("Prepmt. Amount Inv. (LCY)" = 0) THEN
    Prepmt100PctVATRoundingAmt += TotalRoundingAmount[2];
    TotalRoundingAmount[2] := 0;
    END;
    "Prepmt. VAT Amount Inv. (LCY)" := -(TotalRoundingAmount[2] + Prepmt100PctVATRoundingAmt);
    NewAmountIncludingVAT := Amount - (TotalPrepmtAmount[2] + TotalRoundingAmount[2]);
    Increment(
    TotalPurchLineLCY."Amount Including VAT",-("Amount Including VAT" - NewAmountIncludingVAT + Prepmt100PctVATRoundingAmt));
    IF "Currency Code" = '' THEN
    TotalPurchLine."Amount Including VAT" := TotalPurchLineLCY."Amount Including VAT";
    "Amount Including VAT" := NewAmountIncludingVAT;
    END;
    END;

    LOCAL PROCEDURE CalcRoundedAmount@91(Amount@1000 : Decimal;VAR Reminder@1001 : Decimal) : Decimal;
    VAR
    AmountRnded@1002 : Decimal;
    BEGIN
    Amount := Amount + Reminder;
    AmountRnded := ROUND(Amount,GLSetup."Amount Rounding Precision");
    Reminder := Amount - AmountRnded;
    EXIT(AmountRnded);
    // End of the lines.

    END;
    ...
  34. Add the AdjustFinalInvWith100PctPrepmt function and the GetPrepmtDiffToLineAmount function in the Purch.-Post codeunit (90), and then specify the code as follows:

         LOCAL PROCEDURE AdjustFinalInvWith100PctPrepmt@97(VAR TempPurchLine@1000 : TEMPORARY Record 39);
    VAR
    DiffToLineDiscAmt@1001 : Decimal;
    BEGIN
    WITH TempPrepmtDeductLCYPurchLine DO BEGIN
    RESET;
    SETRANGE("Prepayment %",100);
    IF FINDSET(TRUE) THEN
    REPEAT
    IF IsFinalInvoice THEN BEGIN
    DiffToLineDiscAmt := "Prepmt Amt to Deduct" - "Line Amount";
    IF "Document Type" = "Document Type"::Order THEN
    DiffToLineDiscAmt := DiffToLineDiscAmt * Quantity / "Qty. to Invoice";
    IF DiffToLineDiscAmt <> 0 THEN BEGIN
    TempPurchLine.GET("Document Type","Document No.","Line No.");
    TempPurchLine."Line Discount Amount" -= DiffToLineDiscAmt;
    TempPurchLine.MODIFY;

    "Line Discount Amount" := TempPurchLine."Line Discount Amount";
    MODIFY;
    END;
    END;
    UNTIL NEXT = 0;
    RESET;
    END;
    END;

    LOCAL PROCEDURE GetPrepmtDiffToLineAmount@98(PurchLine@1000 : Record 39) : Decimal;
    BEGIN
    WITH TempPrepmtDeductLCYPurchLine DO
    IF (PurchLine."Prepayment %" = 100) THEN
    IF GET(PurchLine."Document Type",PurchLine."Document No.",PurchLine."Line No.") THEN
    EXIT("Prepmt Amt to Deduct" - "Line Amount");
    EXIT(0);
    END;
  35. Change the code in the TestGetRcptPPmtAmtToDeduct function in the Purch.-Post codeunit (90) as follows:
    Existing code

    ...
    TempTotalPurchLine."Prepmt Amt to Deduct" := TempTotalPurchLine."Prepmt Amt to Deduct" + PurchLine2."Prepmt Amt to Deduct";
    TempTotalPurchLine.MODIFY;
    ...

    Replacement code

    ...
    TempTotalPurchLine."Prepmt Amt to Deduct" := TempTotalPurchLine."Prepmt Amt to Deduct" + PurchLine2."Prepmt Amt to Deduct";

    // Add the following line.
    AdjustInvLineWith100PctPrepmt(PurchLine2,TempTotalPurchLine);

    TempTotalPurchLine.MODIFY;
    ...
  36. Change the code in the AdjustInvLineWith100PctPrepmt function in the Purch.-Post codeunit (90) as follows:
    Existing code

    ...
    PROCEDURE ArchiveUnpostedOrder@56();
    ...

    Replacement code

    ...
    // Add the following lines.
    LOCAL PROCEDURE AdjustInvLineWith100PctPrepmt@99(VAR PurchInvoiceLine@1000 : Record 39;VAR TempTotalPurchLine@1001 : TEMPORARY Record 39);
    VAR
    PurchOrderLine@1003 : Record 39;
    DiffAmtToDeduct@1002 : Decimal;
    BEGIN
    IF PurchInvoiceLine."Prepayment %" = 100 THEN BEGIN
    PurchOrderLine := TempTotalPurchLine;
    PurchOrderLine.FIND;
    IF TempTotalPurchLine."Qty. to Invoice" = PurchOrderLine.Quantity - PurchOrderLine."Quantity Invoiced" THEN BEGIN
    DiffAmtToDeduct :=
    PurchOrderLine."Prepmt. Amt. Inv." - PurchOrderLine."Prepmt Amt Deducted" - TempTotalPurchLine."Prepmt Amt to Deduct";
    IF DiffAmtToDeduct <> 0 THEN BEGIN
    PurchInvoiceLine."Prepmt Amt to Deduct" := PurchInvoiceLine."Prepmt Amt to Deduct" + DiffAmtToDeduct;
    PurchInvoiceLine."Line Amount" := PurchInvoiceLine."Prepmt Amt to Deduct";
    PurchInvoiceLine."Line Discount Amount" := PurchInvoiceLine."Line Discount Amount" - DiffAmtToDeduct;
    PurchInvoiceLine.MODIFY;
    TempTotalPurchLine."Prepmt Amt to Deduct" := TempTotalPurchLine."Prepmt Amt to Deduct" + DiffAmtToDeduct;
    END;
    END;
    END;
    END;

    // End of the lines.

    PROCEDURE ArchiveUnpostedOrder@56();
    ...
  37. Change the code in the InsertCorrInvLineBuffer function in the Sales-Post Prepayments codeunit (442) as follows:
    Existing code

    ...
    // Delete the following line.
    NewPrepmtInvLineBuf.FillAdjInvLineBuf(

    PrepmtInvLineBuf,
    ...

    Replacement code

    ...
    // Add the following line.
    NewPrepmtInvLineBuf.FillAdjInvLineBuffer(

    PrepmtInvLineBuf,
  38. Change the code in the InsertCorrInvLineBuffer function in the Sales-Post Prepayments codeunit (442) as follows:
    Existing code

    ...
    // Delete the following lines.
    NewPrepmtInvLineBuf.FillAdjInvLineBuf(
    PrepmtInvLineBuf,
    GetCorrBalAccNo(SalesHeader,VATBaseAdjustment),
    -VATBaseAdjustment);
    // End of the lines.
    ...

    Replacement code

    ...
    // Add the following lines.
    NewPrepmtInvLineBuf.FillAdjInvLineBuffer(
    PrepmtInvLineBuf,
    GetCorrBalAccNo(SalesHeader,VATBaseAdjustment > 0),
    -VATBaseAdjustment);
    // End of the lines.
    ...
  39. Change the code in the GetCorrBalAccNo function in the Sales-Post Prepayments codeunit (442) as follows:
    Existing code

    ...
    // Delete the following line.
    PROCEDURE GetCorrBalAccNo@48(SalesHeader@1000 : Record 36;CorrAmount@1001 : Decimal) : Code[20];

    VAR
    ...

    Replacement code

    ...
    // Add the following lines.
    PROCEDURE GetCorrBalAccNo@48(SalesHeader@1000 : Record 36;PositiveAmount@1001 : Boolean) : Code[20];

    VAR
    ...
  40. Change the code in the GetCorrBalAccNo function in the Sales-Post Prepayments codeunit (442) as follows:
    Existing code

    ...
    ELSE

    // Delete the following lines.
    BalAccNo := GetGainLossGLAcc(SalesHeader."Currency Code",CorrAmount);
    EXIT(BalAccNo);
    END;

    LOCAL PROCEDURE GetInvRoundingAccNo@49(CustomerPostingGroup@1000 : Code[10]) : Code[20];
    // End of the lines.

    VAR
    ...

    Replacement code

    ...
    ELSE

    // Add the following lines.
    BalAccNo := GetGainLossGLAcc(SalesHeader."Currency Code",PositiveAmount);
    EXIT(BalAccNo);
    END;

    PROCEDURE GetInvRoundingAccNo@49(CustomerPostingGroup@1000 : Code[10]) : Code[20];
    // End of the lines.

    VAR
    ...
  41. Change the code in the GetGainLossGLAcc function in the Sales-Post Prepayments codeunit (442) as follows:
    Existing code

    ...
    // Delete the following lines.
    LOCAL PROCEDURE GetGainLossGLAcc@50(CurrencyCode@1000 : Code[10];Amount@1002 : Decimal) : Code[20];
    VAR
    Currency@1001 : Record 4;
    BEGIN
    Currency.GET(CurrencyCode);
    IF Amount > 0 THEN BEGIN
    Currency.TESTFIELD("Realized Gains Acc.");
    EXIT(Currency."Realized Gains Acc.");
    END ELSE BEGIN
    Currency.TESTFIELD("Realized Losses Acc.");
    EXIT(Currency."Realized Losses Acc.");
    END;
    // End of the lines.

    END;
    ...

    Replacement code

    ...
    // Add the following lines.
    LOCAL PROCEDURE GetGainLossGLAcc@50(CurrencyCode@1000 : Code[10];PositiveAmount@1002 : Boolean) : Code[20];
    VAR
    Currency@1001 : Record 4;
    BEGIN
    Currency.GET(CurrencyCode);
    IF PositiveAmount THEN BEGIN
    Currency.TESTFIELD("Realized Gains Acc.");
    EXIT(Currency."Realized Gains Acc.");
    END;
    Currency.TESTFIELD("Realized Losses Acc.");
    EXIT(Currency."Realized Losses Acc.");
    // End of the lines.

    END;
    ...
  42. Change the code in the InsertCorrInvLineBuffer function in the Purchase-Post Prepayments codeunit (444) as follows:
    Existing code 1

    ...
    // Delete the following line.
    NewPrepmtInvLineBuf.FillAdjInvLineBuf(

    PrepmtInvLineBuf,
    ...

    Replacement code 1

    ...
    // Add the following line.
    NewPrepmtInvLineBuf.FillAdjInvLineBuffer(

    PrepmtInvLineBuf,
    ...

    Existing code 2

    ...
    // Delete the following lines.
    NewPrepmtInvLineBuf.FillAdjInvLineBuf(
    PrepmtInvLineBuf,
    GetCorrBalAccNo(PurchHeader,VATBaseAdjustment),
    -VATBaseAdjustment);
    ...

    Replacement code 2

    ...
    // Add the following lines.
    NewPrepmtInvLineBuf.FillAdjInvLineBuffer(
    PrepmtInvLineBuf,
    GetCorrBalAccNo(PurchHeader,VATBaseAdjustment > 0),
    -VATBaseAdjustment);
    // End of the lines.
    ...
  43. Change the code in the GetCorrBalAccNo function in the Purchase-Post Prepayments codeunit (444) as follows:
    Existing code 1

    ...
    // Delete the following line.
    PROCEDURE GetCorrBalAccNo@48(PurchHeader@1000 : Record 38;CorrAmount@1001 : Decimal) : Code[20];

    VAR
    ...

    Replacement code 1

    ...
    // Add the following line.
    PROCEDURE GetCorrBalAccNo@48(PurchHeader@1000 : Record 38;PositiveAmount@1001 : Boolean) : Code[20];

    VAR
    ...

    Existing code 2

    ...
    ELSE

    // Delete the following lines.
    BalAccNo := GetGainLossGLAcc(PurchHeader."Currency Code",CorrAmount);
    EXIT(BalAccNo);
    END;

    LOCAL PROCEDURE GetInvRoundingAccNo@49(VendorPostingGroup@1000 : Code[10]) : Code[20];
    // End of the lines.

    VAR
    ...

    Replacement code 2

    ...
    // Add the following lines.
    BalAccNo := GetGainLossGLAcc(PurchHeader."Currency Code",PositiveAmount);
    EXIT(BalAccNo);
    END;

    PROCEDURE GetInvRoundingAccNo@49(VendorPostingGroup@1000 : Code[10]) : Code[20];
    // End of the lines.

    VAR
    ...
  44. Change the code in the GetGainLossGLAcc function in the Purchase-Post Prepayments codeunit (444) as follows:
    Existing code

    ...
    // Delete the following lines.
    LOCAL PROCEDURE GetGainLossGLAcc@50(CurrencyCode@1000 : Code[10];Amount@1002 : Decimal) : Code[20];
    VAR
    Currency@1001 : Record 4;
    BEGIN
    Currency.GET(CurrencyCode);
    IF Amount > 0 THEN BEGIN
    Currency.TESTFIELD("Realized Gains Acc.");
    EXIT(Currency."Realized Gains Acc.");
    END ELSE BEGIN
    Currency.TESTFIELD("Realized Losses Acc.");
    EXIT(Currency."Realized Losses Acc.");
    END;
    // End of the lines.

    END;
    ...

    Replacement code

    ...
    // Add the following lines.
    LOCAL PROCEDURE GetGainLossGLAcc@50(CurrencyCode@1000 : Code[10];PositiveAmount@1002 : Boolean) : Code[20];
    VAR
    Currency@1001 : Record 4;
    BEGIN
    Currency.GET(CurrencyCode);
    IF PositiveAmount THEN BEGIN
    Currency.TESTFIELD("Realized Gains Acc.");
    EXIT(Currency."Realized Gains Acc.");
    END;
    Currency.TESTFIELD("Realized Losses Acc.");
    EXIT(Currency."Realized Losses Acc.");
    // End of the lines.

    END;

    ...

Prerequisites

You must have one of the following products installed to apply this hotfix:

  • Microsoft Dynamics NAV 2009 R2

  • Microsoft Dynamics NAV 2009 Service Pack 1

Additionally, you must have the following hotfixes installed to apply this hotfix:

2548003 "Prepmt. Line Amount cannot be 0. in Sales Line Document Type='Order',Document No.='[number]',Line No.='[line number]'" error message when you ship and invoice a sales order that has no prepayment in Microsoft Dynamics NAV 2009

2499988 The job number is not included in general ledger entries when you post a final invoice for a purchase order in Microsoft Dynamics NAV 2009

2558516 The "Prepayment Amt Excl. VAT" field is calculated incorrectly after you change the "Prepayment %" value in an order in Microsoft Dynamics NAV 2009

2558599 The "Prepayment Amt Excl. VAT" field is calculated incorrectly after you change the "Prepayment %" value in an order even though you apply hotfix 2558516 in Microsoft Dynamics NAV 2009

2558617 Incorrect general ledger entries are created after you copy an order that uses foreign currency and prepayment to another order by running the Copy Document function in Microsoft Dynamics NAV 2009

2620733 The "Prepmt. Amount Inv. (LCY)" value is incorrect after you post a prepayment invoice in Microsoft Dynamics NAV 2009

2627706 "The transaction cannot be completed because it will cause inconsistencies in the G/L Entry table" error message when you post a prepayment invoice in Microsoft Dynamics NAV 2009

979057 The "Prepmt. Line Amount Excl.VAT" field in a sales order line is rounded incorrectly in Microsoft Dynamics NAV 2009

2499978 The prepayment amount in an invoice is incorrect when you post a prepayment invoice for a sales order in Microsoft Dynamics NAV 2009

2159928 The created general ledger entries are incorrect when you post a sales order in Microsoft Dynamics NAV 2009 Service Pack 1

Removal information

You cannot remove this hotfix.

Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×