Trying to find out which PO line can cover the SO lines.
For example I have multiply sales order lines for the same item and I got 2 purchase orders incoming so I need to find out which of the purchase order have enough qty to cover the outstanding qty on sales order.
ItemNo | SO No. | Outstanding Qty | PO No's. |
70916 | 158473 | 1 | 13897,13896 |
70916 | 158474 | 1 | 13897,13896 |
70916 | 158475 | 2 | 13897,13896 |
One of the PO's have 2 items of 70916 incoming, the other have 4 items incoming. So the first PO can cover the first 2 sales order lines and the second PO can cover the third SO.
I needs to be in order so that the PO with the earliest expected receipt date will be servering the first SO that it can cover.
This is my code as of now - in a codeunit.
count := 0; PurchaseOrderLine.SETRANGE("Document Type",PurchaseOrderLine."Document Type"::Order); PurchaseOrderLine.SETRANGE(Type,PurchaseOrderLine.Type::Item); PurchaseOrderLine.FIND('-'); REPEAT Item.SETRANGE("No.",PurchaseOrderLine."No."); Item.SETFILTER(Inventory,'<=0'); IF Item.FIND('-') THEN BEGIN REPEAT SalesOrderLine.SETRANGE("No.",Item."No."); SalesOrderLine.SETRANGE("Document Type",SalesOrderLine."Document Type"::Order); SalesOrderLine.SETRANGE(Type,SalesOrderLine.Type::Item); IF SalesOrderLine.FIND('-') THEN BEGIN REPEAT // OutstandingQtySO := SalesOrderLine."Outstanding Quantity"; RemainingQty := (PurchaseOrderLine."Outstanding Quantity" - PurchaseOrderLine."Qty. to Receive"); IF OutstandingQtySO <= RemainingQty THEN BEGIN OutstandingQtySO += SalesOrderLine."Outstanding Quantity"; RemainingQty := RemainingQty - OutstandingQtySO; DocNoPO += PurchaseOrderLine."Document No." + ', '; count += 1; IF SalesOrderLine."Shipment Date" <= PurchaseOrderLine."Expected Receipt Date" THEN BEGIN //count += 1; //MESSAGE('Doc no. ' + SalesOrderLine."Document No." + ' Shipment Date is ' + FORMAT(SalesOrderLine."Shipment Date") + ' and Expected Receipt Date is ' + FORMAT(PurchaseOrderLine."Expected Receipt Date")); END; END ELSE BEGIN OutstandingQtySO := 0; END; // UNTIL SalesOrderLine.NEXT = 0; END; UNTIL Item.NEXT = 0; END; UNTIL PurchaseOrderLine.NEXT = 0; MESSAGE(DocNoPO); MESSAGE(FORMAT(count));
Globals.
Name DataType Subtype Length
PurchaseOrderLine Record Purchase Line
Item Record Item
SalesOrderLine Record Sales Line
SalesOrderHeader Record Sales Header
count Integer
OutstandingQtySO Integer
DocNoPO Text
RemainingQty Integer
*This post is locked for comments