I'm trying to Restrict the updating Receipt after payment on posted Purchase Order

if the Invoice is already paid or Partially paid For the Purchase order,again same PO should not allow to post to receive.for this requirement I wrote below code

IF PurchaseHeader.Receive THEN BEGIN
PurInvHdrRec.SETRANGE(“Order No.”, PurchaseHeader.“No.”);
IF PurInvHdrRec.FINDSET THEN BEGIN
LineAmt := 0;
RemAmt := 0;
REPEAT
;
LineAmt += PurInvHdrRec.Amount;
RemAmt += PurInvHdrRec.“Remaining Amount”;
UNTIL (PurInvHdrRec.NEXT = 0);

PurInvHdrRec.“Buy-from Vendor Name”, PurInvHdrRec.“Posting Description”);
IF LineAmt <> RemAmt THEN
ERROR(‘You cannot receive more Items in this Purchase Order’);
END;
END;

now my issue is the amount and remaining amount showing 0 for brief clarification pls find the attachment .and kindly help me out

From I what I understand you are trying to accomplish, I don’t think you need all that code, you just need the below.

IF PurchaseHeader.Receive THEN BEGIN
purchinvhdrrec.reset;
PurInvHdrRec.SETRANGE(“Order No.”, PurchaseHeader.“No.”);
IF PurInvHdrRec.FINDSET THEN
error(‘Purchase order %1 is either paid partial or paid in full.’,purchaseheader.“no.”);
end;

Thank you For Your Kind Response ,But the problem is the Amount Field & Remaining Amount Field Show in 0 in purchInv header Table(122).plz find my attachment for the table Capture.