Purchase Order through Code

I have to create Purchase order through code.and i have to post it.am trying this in job.but i dont know hw to initialize the purch id…Can any one say…?

Thanks in advance,

Saju.K

use this code

static void createPurchOrder(Args _args)////Kranthi

{

AxPurchLine axPurchLine = new axPurchLine();

AxPurchTable axPurchTable = new axPurchTable();

;

axPurchTable.parmPurchId();

axPurchTable.parmOrderAccount(‘1001’);

axPurchTable.save();

axPurchLine.parmPurchId(axPurchTable.parmPurchId());

axPurchLine.parmItemId(‘PolyEthylene’);

axPurchLine.axInventDim().parmInventSiteId(“Unit1”);

axPurchLine.axInventDim().parmInventLocationId(“RM”);

axPurchLine.parmPurchQty(1000);

axPurchLine.parmPurchPrice(20);

axPurchLine.save();

}

Thanks Kranthi your code is working fine.

i have written below code its not working could u tell what wrong i have done here…?

static void UB_PO_Posting(Args _args)
{
Args parameters = new Args();
MenuFunction purchmenu;
PurchTable _purchTable;
PurchLine _purchLine;
InventTable _inventTable;
InventDim _inventDim;
Numberseq Numseq;
PurchId PurchId;
;
Numseq = Numberseq::newGetNum(NumberSequenceReference::find(typeid2extendedtypeid(typeid(purchid))));
ttsbegin;
_purchTable.PurchId = Numseq.num();
_purchTable.OrderAccount = ‘1001’;
_purchTable.InvoiceAccount = ‘1001’;
_purchTable.PurchaseType = PurchaseType::Purch;
_purchTable.PurchStatus = PurchStatus::Backorder;
_purchTable.CurrencyCode = ‘USD’;
_purchTable.insert();

if(_purchTable)
{
_purchLine.ItemId = ‘1000’;
_purchLine.PurchId = _purchTable.PurchId;
_purchLine.PurchQty = 20;
_purchLine.CurrencyCode = ‘USD’;
_purchLine.PurchStatus = PurchStatus::Backorder;
_purchLine.PurchaseType = PurchaseType::Purch;
_purchLine.PurchPrice = 2000;
_purchLine.LineAmount = _purchLine.PurchQty * _purchLine.PurchPrice;

Numseq = Numberseq::newGetNum(NumberSequenceReference::find(typeid2extendedtypeid(typeid(InventDimId))));

_inventDim.inventDimId = Numseq.num();
_purchLine.InventDimId = _inventDim.inventDimId;
_inventDim.InventSiteId = ‘3’;
_inventDim.InventLocationId = ‘28’;
_inventDim.insert();
_purchLine.insert();
}
ttscommit;
purchmenu = new MenuFunction(menuitemdisplaystr(PurchTable),MenuItemType::Display);
purchmenu.run(parameters);

}

I have added some line and commented some line of code

static void UB_PO_Posting(Args _args)

{

Args parameters = new Args();

MenuFunction purchmenu;

PurchTable _purchTable;

PurchLine _purchLine;

InventTable _inventTable;

InventDim _inventDim;

Numberseq Numseq;

PurchId PurchId;

;

Numseq = Numberseq::newGetNum(NumberSequenceReference::find(typeid2extendedtypeid(typeid(purchid))));

ttsbegin;

_purchTable.PurchId = Numseq.num();

_purchTable.OrderAccount = ‘1001’;

_purchTable.InvoiceAccount = ‘1001’;

_purchTable.PurchaseType = PurchaseType::Purch;

_purchTable.PurchStatus = PurchStatus::Backorder;

//_purchTable.CurrencyCode = ‘USD’;

_purchTable.initFromVendTable(VendTable::find(_purchTable.InvoiceAccount));//// added by kranthi

_purchTable.insert();

if(_purchTable)

{

_purchLine.initValue();//// added by kranthi

_purchLine.ItemId = ‘1000’;

_purchLine.initFromInventTable(InventTable::find(_purchLine.ItemId));//// added by kranthi

_purchLine.PurchId = _purchTable.PurchId;

_purchLine.PurchQty = 20;

_purchLine.CurrencyCode = ‘USD’;

_purchLine.PurchStatus = PurchStatus::Backorder;

_purchLine.PurchaseType = PurchaseType::Purch;

_purchLine.PurchPrice = 2000;

_purchLine.LineAmount = _purchLine.PurchQty * _purchLine.PurchPrice;

_purchLine.AssessableValue_IN = _purchLine.LineAmount;//// added by kranthi

_purchLine.RemainPurchPhysical = _purchLine.PurchQty;//// added by kranthi

_purchLine.RemainPurchFinancial = 0;//// added by kranthi

_purchLine.RemainInventPhysical = _purchLine.QtyOrdered;//// added by kranthi

_purchLine.LineNum = PurchLine::lastLineNum(_purchTable.PurchId) + 1.0;//// added by kranthi

// Numseq = Numberseq::newGetNum(NumberSequenceReference::find(typeid2extendedtypeid(typeid(InventDimId))));

// _inventDim.inventDimId = Numseq.num();

//_purchLine.InventDimId = _inventDim.inventDimId;

_inventDim.InventSiteId = ‘1’;

_inventDim.InventLocationId = ‘11’;

_purchLine.InventDimId = InventDim::findOrCreate(_inventDim).inventDimId;//// added by kranthi

_purchLine.insert();

}

ttscommit;

purchmenu = new MenuFunction(menuitemdisplaystr(PurchTable),MenuItemType::Display);

purchmenu.run(parameters);

}

Thank you Kranthi its working fine…

Could you give explanation about code what you have added over there…?

And please give explanation about your old code ( AXPurchTable class)…

Hi saju - Verify the post if it is solved - so that it will be reference to others - even the older posts

anyway,

FindOrCreate method in the InventDim - will search for whether there is any InventDimId created with the given inventory dimensions

if exists it take the InventDimId otherwise it will creates a new InventDimId.

PurchTable.initFromVendTable - it is used to fill the vendor default information into the purchTable(see that method for more clarification)

the same is in the case of PurchLine.initFromInventTable

RemainPurchPhysical - is the qty to be received

if you are giving any value to the RemainPurchPhysical the status of purchaseOrder will be cancelled.

Hi Kranthi,
                           Same purchase order am posting through code.

PurchFormLetter_PurchOrder     Purchaseorder = new PurchFormLetter_PurchOrder();
;
ttsbegin;
PO creation;
PL creation
ttscommit;

Purchaseorder .run(); // Posting through code.

its not posting this error is comming

                                                        Function PurchTotals::newPurchParmTable has been incorrectly called.

            static PurchTotals newPurchParmTable(
            PurchParmTable    _purchParmTable,
            PurchUpdate       _specQty,
            AccountOrder      _sumBy,
            ParmId            _parmId,
            PurchId           _sumPurchId,
            DocumentStatus    _documentStatus = DocumentStatus::None)
{
    ;
    if(_parmId == '')
        throw error(Error::wrongUseOfFunction(funcname()));
    else
        return PurchTotals_ParmTransEdit::construct(_purchParmTable, _specQty, _sumBy, _parmId, _sumPurchId, _documentStatus);
}

if i posting from the form its working fine....................

use purchFormLetter Class

purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);//// stage of Purchase Order (Receipts List/Packing Slip/Invoice)

purchFormLetter.transDate(systemdateget());

purchFormLetter.update(purchTable,“1”, systemdateget() , PurchUpdate::All ,

AccountOrder::None, false, false);///// 1 is the invoice number.

hi Kranthi

i nead approve po and pr from code you have code that do this

thanks itzik

Hi Kranti,

I want to add two sales lines with respect to Sales Order. So what are the additions in Saju.k code.

Thanks and Regards

Ankit Tuli

ankitmv@gmail.com

Dear Kranthi,

Please share the code for invoice PO Also.

Hi Kranthi i wrote your code AxPurchLine axPurchLine = new axPurchLine(); AxPurchTable axPurchTable = new axPurchTable(); ; axPurchTable.parmPurchId(); axPurchTable.parmOrderAccount(‘1001’); axPurchTable.save(); axPurchLine.parmPurchId(axPurchTable.parmPurchId()); axPurchLine.parmItemId(‘PolyEthylene’); axPurchLine.axInventDim().parmInventSiteId(“Unit1”); axPurchLine.axInventDim().parmInventLocationId(“RM”); axPurchLine.parmPurchQty(1000); axPurchLine.parmPurchPrice(20); axPurchLine.save(); but compilation time it is fine but when i run the job getting an error like “: PurchTable (table) has no valid runable code in method ‘createMarkupTrans’.”