How to invoice Purchase order partially through X++ in Ax2012

Hi All,

Hope you are doing well…

Can any one suggest me how to achieve this programitically…

Scenario :

Record in PurchTable:(singe line of 10 Quantity which is received)

Item Quantity

ItemA 10

Here i need to invoice PO partially Quantity of 5 two times…i.e i need invoice PO two times,in each time 5 quantity

this is the piece of code which you need to invoke…

PurchTable purchTable;

PurchLine purchLine;

PurchFormLetter PurchFormLetter;

;

PurchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);

ttsBegin;

purchTable = purchTable::find(‘PO-001356’);

while select forupdate purchLine

where purchLine.purchId == purchTable.PurchId

{

purchLine.PurchReceivedNow = 1;

purchLine.modifiedField(fieldnum(purchLine,PurchReceivedNow));

purchLine.update();

}

PurchFormLetter.update(purchTable,‘invoiceNum’,systemDateGet(),PurchUpdate::ReceiveNow);

ttsCommit;