18 August 2014

AX 2012 Purchase order / sales order creation and invoicing through X++ / auto Purchase order posing

static void POAutoConfirmAndInvoice(Args _args)
{
PurchTable purchTable;
PurchLine purchLine;
VendTable vendTable = VendTable::find("US_TX_007");
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.parmDeliveryDate(str2date("08/18/2014",213));
axPurchTable.parmAccountingDate(str2date("08/18/2014",213));
axPurchTable.parmPurchStatus(PurchStatus::Backorder);

axPurchTable.doSave();


purchLine.initFromPurchTable(purchTable);

axPurchLine = AxPurchLine::newPurchLine(purchLine);
axpurchLine.parmItemId("D0003");
axpurchLine.parmInventDimId('000458');
axPurchLine.parmPurchQty(10);
axPurchLine.parmPurchPrice(100);
axPurchLine.doSave();

//PO confirmation
purchTable = axPurchTable.purchTable();
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(purchTable, strFmt("Inv_%1", purchTable.PurchId));

// PO invoicing
purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.update(purchTable, strFmt("Inv_%1", purchTable.PurchId));
info(strFmt("purchase order %1 invoiced",purchTable.PurchId));

}
===============================================================================

static void SOAutoConfirmAndInvoice(Args _args)
{
SalesTable salesTable;
SalesLine salesLine;
CustTable custTable= CustTable::find("US-004");
AxSalesTable axsalesTable;
AxSalesLine axSalesLine;
SalesFormLetter salesFormLetter;
;

//Create Sales order

salesTable.initFromCustTable();

axsalesTable = AxSalesTable::newSalesTable(salesTable);
axsalesTable.parmCustAccount("US-004");
axsalesTable.parmSalesType(SalesType::Sales);

axsalesTable.parmDocumentStatus(DocumentStatus::Confirmation);

axsalesTable.parmDeliveryDate(str2Date("08/18/2014",213));
axsalesTable.parmSalesStatus(SalesStatus::Backorder);

axsalesTable.doSave();

salesLine.initFromSalesTable(salesTable);

axSalesLine = AxSalesLine::newSalesLine(salesLine);
axSalesLine.parmItemId("D0003");
axSalesLine.parmInventDimId("000458");
axSalesLine.parmCurrencyCode("USD");
axSalesLine.parmSalesQty(2);
axSalesLine.parmSalesPrice(20.00);
axSalesLine.doSave();



//SO confirmation
salesTable = axSalesTable.salesTable(salesTable);
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
salesFormLetter.update(salesTable);

// SO invoicing
salesFormLetter = salesFormLetter::construct(DocumentStatus::Invoice);
salesFormLetter.update(salesTable);

}

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...