...
IF SalesHeader."Prepayment Type" = SalesHeader."Prepayment Type"::Advance THEN BEGIN
VATPostingSetup.GET("VAT Bus. Posting Group","VAT Prod. Posting Group");
// Delete the following lines.
AbsoluteAdvCorrection :=
VATPostingSetup."Adv. Invoice Correction Type" = VATPostingSetup."Adv. Invoice Correction Type"::Absolute;
IF AbsoluteAdvCorrection THEN BEGIN
PrepmtPct := "Prepayment %";
"Prepayment %" := 100;
END;
END;
IF SalesHeader."Prices Including VAT" THEN
"Prepmt Amt to Deduct" :=
ROUND(
ROUND(
ROUND(
ROUND("Unit Price" * "Qty. to Invoice",Currency."Amount Rounding Precision") *
(1 - ("Line Discount %" / 100)),Currency."Amount Rounding Precision") *
("Prepayment %" / 100) / (1 + ("VAT %" / 100)),Currency."Amount Rounding Precision") *
(1 + ("VAT %" / 100)),Currency."Amount Rounding Precision")
ELSE
"Prepmt Amt to Deduct" :=
ROUND(
ROUND(
ROUND("Unit Price" * "Qty. to Invoice",Currency."Amount Rounding Precision") *
(1 - ("Line Discount %" / 100)),Currency."Amount Rounding Precision") *
"Prepayment %" / 100 ,Currency."Amount Rounding Precision");
IF AbsoluteAdvCorrection THEN BEGIN
"Prepayment %" := PrepmtPct;
IF "Prepmt Amt to Deduct" > ("Prepmt. Amt. Inv." - "Prepmt Amt Deducted") THEN
"Prepmt Amt to Deduct" := "Prepmt. Amt. Inv." - "Prepmt Amt Deducted";
END;
// End of the lines.
END ELSE
"Prepmt Amt to Deduct" := 0
...
...
IF SalesHeader."Prepayment Type" = SalesHeader."Prepayment Type"::Advance THEN BEGIN
VATPostingSetup.GET("VAT Bus. Posting Group","VAT Prod. Posting Group");
// Add the following lines.
CASE VATPostingSetup."Adv. Invoice Correction Type" OF
VATPostingSetup."Adv. Invoice Correction Type"::Percentage:
"Prepmt Amt to Deduct" :=
ROUND("Qty. to Invoice" / (Quantity - "Quantity Invoiced") *
("Prepmt. Amt. Inv." - "Prepmt Amt Deducted"),Currency."Amount Rounding Precision");
VATPostingSetup."Adv. Invoice Correction Type"::Absolute:
BEGIN
"Prepmt Amt to Deduct" := PrepmtAmtToDeduct(SalesHeader."Prices Including VAT",100);
IF "Prepmt Amt to Deduct" > ("Prepmt. Amt. Inv." - "Prepmt Amt Deducted") THEN
"Prepmt Amt to Deduct" := "Prepmt. Amt. Inv." - "Prepmt Amt Deducted";
END;
VATPostingSetup."Adv. Invoice Correction Type"::"Fully Invoiced":
IF "Qty. to Invoice" = Quantity - "Quantity Invoiced" THEN
"Prepmt Amt to Deduct" := "Prepmt. Amt. Inv." - "Prepmt Amt Deducted"
ELSE
"Prepmt Amt to Deduct" := 0;
END;
END ELSE
"Prepmt Amt to Deduct" := PrepmtAmtToDeduct(SalesHeader."Prices Including VAT","Prepayment %");
// End of the lines.
END ELSE
"Prepmt Amt to Deduct" := 0
...