Sunday, 8 March 2015

Create Purchase Order through code

static void purchorder(Args _args)
{

    PurchTable      purchTable;
    PurchLine       purchLine;
    VendTable       vendTable = VendTable::find("3008");
    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(01\06\2012);
    axPurchTable.parmPurchStatus(PurchStatus::Backorder);
    axPurchTable.doSave();

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

    axPurchLine = AxPurchLine::newPurchLine(purchLine);
    axpurchLine.parmItemId("1000");
    axPurchLine.parmPurchQty(10);
    axPurchLine.parmPurchPrice(1900);
    axPurchLine.doSave();
    info(strFmt("%1",purchTable.PurchId));

    //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("inv_%1", purchtable.purchid));
//
    //posting po invoice
    //purchformletter = purchformletter::construct(documentstatus::invoice);
    //purchformletter.update(purchtable, strfmt("inv_%1", purchtable.purchid));

No comments:

Post a Comment