PROCEDURE CheckSalesHeader@7(SalesHeader@1000 : Record 36;ShowError@1001 : Boolean) : Boolean;
VAR
SalesLine@1002 : Record 37;
SalesLine2@1003 : Record 37;
SalesOrder@1004 : Form 42;
CurrItemNo@1005 : Code[20];
QtyOutstandingBase@1006 : Decimal;
RecordNo@1007 : Integer;
TotalNoOfRecords@1008 : Integer;
BEGIN
WITH SalesHeader DO BEGIN
IF NOT ("Shipping Advice" = "Shipping Advice"::Complete) THEN
EXIT(FALSE);
SalesLine.SETCURRENTKEY("Document Type",Type,"No.");
SalesLine.SETRANGE("Document Type","Document Type");
SalesLine.SETRANGE("Document No.","No.");
SalesLine.SETRANGE(Type,SalesLine.Type::Item);
IF SalesLine.FINDSET THEN BEGIN
SalesLine2.COPYFILTERS(SalesLine);
SalesLine2.SETCURRENTKEY("Document Type","Document No.","Location Code");
SalesLine2.SETFILTER("Location Code",'<> %1',SalesLine."Location Code");
IF NOT SalesLine2.ISEMPTY THEN BEGIN
IF ShowError THEN
ERROR(Text001,FIELDCAPTION("Shipping Advice"),"Shipping Advice",
SalesOrder.CAPTION,"No.",SalesLine.Type);
EXIT(TRUE);
END;
CurrItemNo := SalesLine."No.";
TotalNoOfRecords := SalesLine.COUNT;
REPEAT
RecordNo = 1;
IF SalesLine."No." = CurrItemNo THEN
QtyOutstandingBase = SalesLine."Outstanding Qty. (Base)"
ELSE BEGIN
IF CheckAvailability(CurrItemNo,QtyOutstandingBase,SalesLine."Location Code",
SalesOrder.CAPTION,DATABASE::"Sales Line","Document Type","No.",ShowError) THEN
EXIT(TRUE);
CurrItemNo := SalesLine."No.";
QtyOutstandingBase := SalesLine."Outstanding Qty. (Base)";
END;
IF RecordNo = TotalNoOfRecords THEN BEGIN // last record
IF CheckAvailability(CurrItemNo,QtyOutstandingBase,SalesLine."Location Code",
SalesOrder.CAPTION,DATABASE::"Sales Line","Document Type","No.",ShowError) THEN
EXIT(TRUE);
END;
UNTIL SalesLine.NEXT = 0; // sorted by item
END;
END;
END;
PROCEDURE CheckTransferHeader@8(TransferHeader@1000 : Record 5740;ShowError@1001 : Boolean) : Boolean;
VAR
TransferLine@1002 : Record 5741;
TransferOrder@1003 : Form 5740;
CurrItemNo@1004 : Code[20];
QtyOutstandingBase@1005 : Decimal;
RecordNo@1006 : Integer;
TotalNoOfRecords@1007 : Integer;
BEGIN
WITH TransferHeader DO BEGIN
IF NOT ("Shipping Advice" = "Shipping Advice"::Complete) THEN
EXIT(FALSE);
TransferLine.SETCURRENTKEY("Item No.");
TransferLine.SETRANGE("Document No.","No.");
IF TransferLine.FINDSET THEN BEGIN
CurrItemNo := TransferLine."Item No.";
TotalNoOfRecords := TransferLine.COUNT;
REPEAT
RecordNo = 1;
IF TransferLine."Item No." = CurrItemNo THEN
QtyOutstandingBase = TransferLine."Outstanding Qty. (Base)"
ELSE BEGIN
IF CheckAvailability(CurrItemNo,QtyOutstandingBase,TransferLine."Transfer-from Code",
TransferOrder.CAPTION,DATABASE::"Transfer Line",0,"No.",ShowError) THEN // outbound
EXIT(TRUE);
CurrItemNo := TransferLine."Item No.";
QtyOutstandingBase := TransferLine."Outstanding Qty. (Base)";
END;
IF RecordNo = TotalNoOfRecords THEN BEGIN // last record
IF CheckAvailability(CurrItemNo,QtyOutstandingBase,TransferLine."Transfer-from Code",
TransferOrder.CAPTION,DATABASE::"Transfer Line",0,"No.",ShowError) THEN // outbound
EXIT(TRUE);
END;
UNTIL TransferLine.NEXT = 0; // sorted by item
END;
END;
END;
PROCEDURE CheckAvailability@9(ItemNo@1000 : Code[20];QtyBaseNeeded@1001 : Decimal;LocationCode@1002 : Code[10];FormCaption@1003 : Text[1024];SourceType@1004 : Integer;SourceSubType@1005 : Integer;SourceID@1006 : Code[20];ShowError@1007 : Boolean) : Boolean;
VAR
Item@1008 : Record 27;
ReservEntry@1009 : Record 337;
ReservEntry2@1010 : Record 337;
QtyReservedForOrder@1011 : Decimal;
BEGIN
WITH Item DO BEGIN
GET(ItemNo);
SETRANGE("Location Filter",LocationCode);
CALCFIELDS(Inventory,"Reserved Qty. on Inventory");
// find qty reserved for this order
ReservEntry.SETCURRENTKEY("Source ID","Source Ref. No.","Source Type","Source Subtype");
ReservEntry.SETRANGE("Item No.",ItemNo);
ReservEntry.SETRANGE("Location Code",LocationCode);
ReservEntry.SETRANGE("Reservation Status",ReservEntry."Reservation Status"::Reservation);
ReservEntry.SETRANGE("Source Type",SourceType);
ReservEntry.SETRANGE("Source Subtype",SourceSubType);
ReservEntry.SETRANGE("Source ID",SourceID);
IF ReservEntry.FINDSET THEN
REPEAT
ReservEntry2.GET(ReservEntry."Entry No.",NOT ReservEntry.Positive);
QtyReservedForOrder = ReservEntry2."Quantity (Base)";
UNTIL ReservEntry.NEXT = 0;
IF Inventory - ("Reserved Qty. on Inventory" - QtyReservedForOrder) < QtyBaseNeeded THEN BEGIN
IF ShowError THEN
ERROR(Text002,ItemNo,LocationCode,FormCaption,SourceID);
EXIT(TRUE);
END;
END;
END;