SalesLine2.SETRANGE("Document Type",SalesHeader."Document Type");
SalesLine2.SETRANGE("Document No.",SalesHeader."No.");
SalesLine2.SETFILTER(Quantity,'>0');
SalesLine2.SETFILTER("Qty. to Invoice",'>0');
SalesLine2.SETFILTER("Shipment No.",'<>%1','');
SalesLine2.SETFILTER("Prepmt Amt to Deduct",'<>0');
IF SalesLine2.ISEMPTY THEN
EXIT;
SalesLine2.SETRANGE("Prepmt Amt to Deduct");
IF SalesLine2.FINDSET THEN
REPEAT
IF SalesShptLine.GET(SalesLine2."Shipment No.",SalesLine2."Shipment Line No.") THEN BEGIN
TempSalesLine3 := SalesLine2;
TempSalesLine3.INSERT;
TempSalesShptLine := SalesShptLine;
IF TempSalesShptLine.INSERT THEN;
IF NOT TempTotalSalesLine.GET(SalesLine2."Document Type"::Order,SalesShptLine."Order No.",SalesShptLine."Order Line No.")
THEN BEGIN
TempTotalSalesLine.INIT;
TempTotalSalesLine."Document Type" := SalesLine2."Document Type"::Order;
TempTotalSalesLine."Document No." := SalesShptLine."Order No.";
TempTotalSalesLine."Line No." := SalesShptLine."Order Line No.";
TempTotalSalesLine.INSERT;
END;
TempTotalSalesLine."Qty. to Invoice" := TempTotalSalesLine."Qty. to Invoice" + SalesLine2."Qty. to Invoice";
TempTotalSalesLine."Prepmt Amt to Deduct" := TempTotalSalesLine."Prepmt Amt to Deduct" + SalesLine2."Prepmt Amt to Deduct";
TempTotalSalesLine.MODIFY;
END;
UNTIL SalesLine2.NEXT = 0;
IF TempSalesLine3.FINDSET THEN
REPEAT
IF TempSalesShptLine.GET(TempSalesLine3."Shipment No.",TempSalesLine3."Shipment Line No.") THEN BEGIN
IF SalesLine2.GET(TempSalesLine3."Document Type"::Order,TempSalesShptLine."Order No.",TempSalesShptLine."Order Line No.") THEN
IF TempTotalSalesLine.GET(TempSalesLine3."Document Type"::Order,TempSalesShptLine."Order No.",
TempSalesShptLine."Order Line No.")
THEN BEGIN
MaxAmtToDeduct := SalesLine2."Prepmt. Amt. Inv." - SalesLine2."Prepmt Amt Deducted";
IF TempTotalSalesLine."Prepmt Amt to Deduct" > MaxAmtToDeduct THEN
ERROR(STRSUBSTNO(Text050,SalesLine2.FIELDCAPTION("Prepmt Amt to Deduct"),MaxAmtToDeduct));
IF (TempTotalSalesLine."Qty. to Invoice" = SalesLine2.Quantity - SalesLine2."Quantity Invoiced") AND
(TempTotalSalesLine."Prepmt Amt to Deduct" <> MaxAmtToDeduct)
THEN
ERROR(STRSUBSTNO(Text051,SalesLine2.FIELDCAPTION("Prepmt Amt to Deduct"),MaxAmtToDeduct));
END;
END;
UNTIL TempSalesLine3.NEXT = 0;