...
IF (ServContractLine."Contract Expiration Date" < WDate) AND
(ServContractLine."Contract Expiration Date" <> 0D)
THEN BEGIN
Days := DATE2DMY(ServContractLine."Contract Expiration Date",1);
// Delete the following lines.
NoOfPayments := NoOfPayments - 1;
END;
// End of the lines.
WDate := InvTo;
IF (WDate > ServContractLine."Contract Expiration Date") AND
(ServContractLine."Contract Expiration Date" <> 0D)
THEN
WDate := ServContractLine."Contract Expiration Date";
DueDate := WDate;
InvAmountReal := InvAmountReal + CalcContractLineAmount(ServContractLine."Line Amount",InvFrom,WDate);
InvUnitPriceReal := InvUnitPriceReal + CalcContractLineAmount(ServContractLine."Line Value",InvFrom,WDate);
InvCostAmtReal := InvCostAmtReal + CalcContractLineAmount(ServContractLine."Line Cost",InvFrom,WDate);
InvDiscountAmtReal := InvDiscountAmtReal + CalcContractLineAmount(ServContractLine."Line Discount Amount",InvFrom,WDate);
IF DueDate <> CALCDATE('<CM>',DueDate) THEN
DueDate := CALCDATE('<-CM-1D>',DueDate);
NonDistrAmount := -CalcContractLineAmount(ServContractLine."Line Amount",InvFrom,DueDate);
NonDistrUnitPrice := -CalcContractLineAmount(ServContractLine."Line Value",InvFrom,DueDate);
NonDistrCostAmt := CalcContractLineAmount(ServContractLine."Line Cost",InvFrom,DueDate);
NonDistrDiscountAmt := CalcContractLineAmount(ServContractLine."Line Discount Amount",InvFrom,DueDate);
ServLedgEntry."Service Item No. (Serviced)" := ServContractLine."Service Item No.";
ServLedgEntry."Item No. (Serviced)" := ServContractLine."Item No.";
ServLedgEntry."Serial No. (Serviced)" := ServContractLine."Serial No.";
DueDate := ServContractHeader."Next Invoice Date";
IF AddingNewLines THEN
DueDate := InvFrom;
// Delete the following line.
FOR Index := 1 TO NoOfPayments DO BEGIN
ServLedgEntry."Amount (LCY)" :=
ROUND(NonDistrAmount / (NoOfPayments + 1 - Index),Currency."Amount Rounding Precision");
ServLedgEntry."Unit Price" :=
...
...
IF (ServContractLine."Contract Expiration Date" < WDate) AND
(ServContractLine."Contract Expiration Date" <> 0D)
THEN BEGIN
Days := DATE2DMY(ServContractLine."Contract Expiration Date",1);
// Add the following lines.
CountofEntryLoop := NoOfPayments - 1;
END ELSE
CountofEntryLoop := NoOfPayments;
// End of the lines.
WDate := InvTo;
IF (WDate > ServContractLine."Contract Expiration Date") AND
(ServContractLine."Contract Expiration Date" <> 0D)
THEN
WDate := ServContractLine."Contract Expiration Date";
DueDate := WDate;
InvAmountReal := InvAmountReal + CalcContractLineAmount(ServContractLine."Line Amount",InvFrom,WDate);
InvUnitPriceReal := InvUnitPriceReal + CalcContractLineAmount(ServContractLine."Line Value",InvFrom,WDate);
InvCostAmtReal := InvCostAmtReal + CalcContractLineAmount(ServContractLine."Line Cost",InvFrom,WDate);
InvDiscountAmtReal := InvDiscountAmtReal + CalcContractLineAmount(ServContractLine."Line Discount Amount",InvFrom,WDate);
IF DueDate <> CALCDATE('<CM>',DueDate) THEN
DueDate := CALCDATE('<-CM-1D>',DueDate);
NonDistrAmount := -CalcContractLineAmount(ServContractLine."Line Amount",InvFrom,DueDate);
NonDistrUnitPrice := -CalcContractLineAmount(ServContractLine."Line Value",InvFrom,DueDate);
NonDistrCostAmt := CalcContractLineAmount(ServContractLine."Line Cost",InvFrom,DueDate);
NonDistrDiscountAmt := CalcContractLineAmount(ServContractLine."Line Discount Amount",InvFrom,DueDate);
ServLedgEntry."Service Item No. (Serviced)" := ServContractLine."Service Item No.";
ServLedgEntry."Item No. (Serviced)" := ServContractLine."Item No.";
ServLedgEntry."Serial No. (Serviced)" := ServContractLine."Serial No.";
DueDate := ServContractHeader."Next Invoice Date";
IF AddingNewLines THEN
DueDate := InvFrom;
// Add the following line.
FOR Index := 1 TO CountofEntryLoop DO BEGIN
ServLedgEntry."Amount (LCY)" :=
ROUND(NonDistrAmount / (NoOfPayments + 1 - Index),Currency."Amount Rounding Precision");
ServLedgEntry."Unit Price" :=
...