//Insert top part GrecPurchaseHeader.INIT; GrecPurchaseHeader.FINDLAST; "No." := GrecPurchaseHeader."No."; //GrecVendor.SETRANGE("No.",VendorCode); GrecVendor.SETRANGE("No.",'CE5036'); "Buy-from Vendor No." := GrecVendor."No."; "Buy-from Vendor Name" := GrecVendor.Name; "Buy-from Address" := GrecVendor.Address; "Buy-from Address 2" := GrecVendor."Address 2"; "Buy-from City" := GrecVendor.City; "Buy-from County" := GrecVendor.County; "Buy-from Post Code" := GrecVendor."Post Code"; "Vendor Invoice No." := InvoiceNo; "Posting Date" := InvoiceDate; //Select single Purchase header GrecPurchaseHeader.SETRANGE("No.","PO No."); //Select single Purchase receipt line GrecPurchRcptLine.SETFILTER("PO No.","PO No."); GrecPurchRcptLine.SETFILTER("No.","PN"); //Init process IF GrecPurchRcptLine.FIND('-') THEN BEGIN LcduGetReceipt.SetPurchHeader(GrecPurchaseHeader); LcduGetReceipt.CreateInvLines(GrecPurchRcptLine); END; //Select new lines GrecPurchaseLine.RESET; GrecPurchaseLine.SETFILTER("Document No.","PO No."); GrecPurchaseLine.SETFILTER("No.",PN); //Check quantity IF NOT (GrecPurchaseLine."Qty. to Invoice" >= QTY) THEN BEGIN MESSAGE('Not expecting that many! (Qty is too high)'); EXIT; END; //Check price //If it's expensive then it will do it by +-1%. Otherwise it will do it +-£3 IF "Unit Price" > 200 THEN BEGIN LdecCheckAmount := "Unit Price" / 100; IF NOT (GrecPurchaseLine."Unit Cost (LCY)" < "Unit Price" + LdecCheckAmount) OR (GrecPurchaseLine."Unit Cost (LCY)" > "Unit Price" - LdecCheckAmount) THEN MESSAGE('Error - Total price incorrect1'); END ELSE BEGIN; IF NOT (GrecPurchaseLine."Unit Cost (LCY)" < "Unit Price" + 3) OR (GrecPurchaseLine."Unit Cost (LCY)" > "Unit Price" - 3) THEN MESSAGE('Error - Total price incorrect2'); END; GrecPurchaseLine.Quantity := QTY; GrecPurchaseLine."Unit Cost (LCY)" := "Unit Price"; GrecPurchaseLine.MODIFY; MESSAGE('Ready to post');