static void Job5(Args _args)
{
PurchTable purchTable;
PurchLine purchLine;
VendTable vendTable = VendTable::find(“1001”);
AxPurchTable axPurchTable;
AxPurchLine axPurchLine;
PurchFormLetter purchFormLetter;

//Create Purchase order
purchTable.initFromVendTable(vendTable);

axPurchTable = axPurchTable::newPurchTable(purchTable);
axPurchTable.parmPurchaseType(PurchaseType::Purch);
axPurchTable.parmDocumentStatus(DocumentStatus::PurchaseOrder);
axPurchTable.parmAccountingDate(systemDateGet());
//axPurchTable.parmDeliveryDate(016\2012);
axPurchTable.parmPurchStatus(PurchStatus::Backorder);
axPurchTable.parmInventSiteId(‘1′);
axPurchTable.parmInventLocationId(’11’);
axPurchTable.doSave();

//Create PurchLine for item 1000
purchLine.initFromPurchTable(purchTable);

axPurchLine = AxPurchLine::newPurchLine(purchLine);
axpurchLine.parmItemId(“1000”);
axPurchLine.parmPurchQty(10);
axPurchLine.parmPurchPrice(100);
axPurchLine.doSave();

purchLine.clear();
purchLine.initFromPurchTable(purchTable);
axPurchLine = AxPurchLine::newPurchLine(purchLine);
axpurchLine.parmItemId(“A0001”);
axPurchLine.parmPurchQty(10);
axPurchLine.parmPurchPrice(100);
axPurchLine.doSave();
//Posting PO Confirmation,I guess its mandatory
//You cannot do invoice without doing PO confirm
purchTable = axPurchTable.purchTable();
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(purchTable, strFmt(“PO_%1”, purchTable.PurchId));

//Posting PO Invoice
purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.update(purchTable, strFmt(“Inv_%1”, purchTable.PurchId));
}