Purchase order invoice cost

I am invoicing purchase orders using the standard PurchFormLetter functionality below.

PurchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.update(PurchTable, InvoiceId, InvoiceDate, PurchUpdate::ReceiveNow);

Before this, I set the quantity to be invoiced using the code below. My issue is that on some invoices the cost of the item on the invoice differs from the PO. For example, I have a po line where the quatity is 1 and the each cost is $500, but the invoice is for $350. I need to be able to post the invoice for just the 1 each at $350. What field(s) do I need to populate to do this or does it require another method?

PurchLine PLine;

PLine = PurchLin;e::find(NxtILine.PurchId, NxtILine.POLineNumber, true);
if (PLine)
PLine.PurchReceivedNow = NxtILine.QtyMatched;



Store the previous price in a variable before posting , now post with new price and now assign back the price stored in variable.