...
SalesLine.MODIFY;
// Delete the following lines.
IF i < 3 THEN BEGIN
FixedAmt := 0;
VariableAmt := 0;
AdjustedAmt := 0;
DiffAdjustmentAmt := 0;
FixedAmt := SalesLine."Unit Price Incl. of Tax" * SalesLine.Quantity;
VariableAmt := SalesLine.Quantity;
StrOrderLineDetails.RESET;
StrOrderLineDetails.SETCURRENTKEY(Type,"Document Type","Document No.","Structure Code","Item No.","Line No.");
StrOrderLineDetails.SETRANGE(Type,StrOrderLineDetails.Type::Sale);
StrOrderLineDetails.SETRANGE("Document Type",SalesLine."Document Type");
StrOrderLineDetails.SETRANGE("Document No.",SalesLine."Document No.");
StrOrderLineDetails.SETRANGE("Structure Code",SalesLine."PIT Structure");
StrOrderLineDetails.SETRANGE("Item No.",SalesLine."No.");
StrOrderLineDetails.SETRANGE("Line No.",SalesLine."Line No.");
StrOrderLineDetails.SETRANGE("Include PIT Calculation",TRUE);
IF StrOrderLineDetails.FIND('-') THEN
REPEAT
FixedAmt -= StrOrderLineDetails.Amount;
AdjustedAmt := AdjustedAmt + StrOrderLineDetails.Amount;
UNTIL StrOrderLineDetails.NEXT = 0;
SalesLine."Unit Price" := 0;
IF VariableAmt <> 0 THEN BEGIN
SalesLine."Unit Price" := ROUND((FixedAmt / VariableAmt),GetRoundingPrecisionUnitPrice);
IF SalesLine."Unit Price" < 0 THEN
SalesLine.FIELDERROR("Unit Price");
IF (i = 2) AND (FixedAmt <> 0) AND (SalesLine.Quantity <> 0) THEN BEGIN
AdjustedAmt := AdjustedAmt + (SalesLine."Unit Price" * SalesLine.Quantity);
FixedAmt := SalesLine."Unit Price Incl. of Tax" * SalesLine.Quantity;
DiffAdjustmentAmt := ((FixedAmt - AdjustedAmt)/SalesLine.Quantity) *
(SalesLine."Unit Price" * SalesLine.Quantity) / (FixedAmt );
SalesLine."Unit Price" := ROUND(SalesLine."Unit Price" - DiffAdjustmentAmt,GetRoundingPrecisionUnitPrice);
IF SalesLine."Unit Price" < 0 THEN
SalesLine.FIELDERROR("Unit Price");
END;
SalesLine.ValidateUnitPrice;
SalesLine.ChkQtyUpdatioAfterDDPLA;
SalesLine.MODIFY;
IF SalesHeader."Calc. Inv. Discount (%)" THEN
CalcInvDis.CalculateWithSalesHeader(SalesHeader,SalesLine);
SalesLine.GET(SalesLine."Document Type",SalesLine."Document No.",SalesLine."Line No.");
END;
END;
// End of the lines.
...