Creation of Purchase Order through X++ code for Creating Multiple Item for single Vendor -
void clicked()
{
PurchTable purchTable;
PurchLine purchLine;
PurchaseRe _PurchaseRe,_purchRe;
VendTable vendTable;
AxPurchTable axPurchTable;
AxPurchLine axPurchLine;
AxInventDim axInventDim;
PurchFormLetter purchFormLetter;
InventDim inventDim,dim;
MenuFunction purchmenu;
Dialog dialog;
VendAccount _VendAccount;
DialogField dialogfieldVendAccount;
DialogGroup dialogGroup;
InventTable inventTable;
NumberSeq Numseq;
Args args = new Args();
;
dialog = new Dialog("VendAccount PO");
dialogGroup = dialog.addGroup("Purchase Order");
dialogFieldVendAccount = dialog.addField(extendedTypeStr(VendAccount));
if(dialog.run())
{
select _PurchaseRe where dialogFieldVendAccount.value();
_VendAccount = dialogFieldVendAccount.value();
ttsbegin;
Numseq = NumberSeq::newGetNum(PurchParameters::numRefPurchId());
Purchtable.initValue();
purchTable.PurchId = Numseq.num();
purchTable.OrderAccount = _VendAccount;
purchTable.PurchName = VendTable::find(_VendAccount).name();
purchTable.InvoiceAccount = _VendAccount;
purchTable.PurchaseType = PurchaseType::Purch;
purchTable.DocumentStatus = DocumentStatus::PurchaseOrder;
purchTable.AccountingDate = systemDateGet();
purchTable.PurchStatus = PurchStatus::Backorder;
Purchtable.initFromVendTable();
info(strFmt("%1",_VendAccount));
purchTable.Insert();
while select _purchRe where _purchRe.VendAccount == _VendAccount
{
purchLine.initFromPurchTable(purchTable);
purchLine.PurchId = purchTable.PurchId;
axPurchLine = AxPurchLine::newPurchLine(purchLine);
purchLine.ItemId = _purchRe.ItemId;
purchLine.DeliveryDate = _purchRe.DelvDate;
purchLine.QtyOrdered = _purchRe.Qty;
purchLine.PriceUnit = _purchRe.Price;
inventDim.clear();
inventDim.InventSiteId = "1";
inventDim.InventLocationId = "12";
inventDim = InventDim::findOrCreate(inventDim);
purchLine.InventDimId = inventDim.inventDimId;
purchLine.insert();
PurchLine.LineNumber = axPurchLine.parmLineNumber((purchLine.LineNumber)+10);
info(strFmt("%1 : %2 : %3 : %4 : %5",purchLine.PurchId,purchLine.ItemId,_purchRe.DelvDate,purchLine.QtyOrdered,purchLine.PriceUnit));
}
ttsCommit;
}
super();
}
void clicked()
{
PurchTable purchTable;
PurchLine purchLine;
PurchaseRe _PurchaseRe,_purchRe;
VendTable vendTable;
AxPurchTable axPurchTable;
AxPurchLine axPurchLine;
AxInventDim axInventDim;
PurchFormLetter purchFormLetter;
InventDim inventDim,dim;
MenuFunction purchmenu;
Dialog dialog;
VendAccount _VendAccount;
DialogField dialogfieldVendAccount;
DialogGroup dialogGroup;
InventTable inventTable;
NumberSeq Numseq;
Args args = new Args();
;
dialog = new Dialog("VendAccount PO");
dialogGroup = dialog.addGroup("Purchase Order");
dialogFieldVendAccount = dialog.addField(extendedTypeStr(VendAccount));
if(dialog.run())
{
select _PurchaseRe where dialogFieldVendAccount.value();
_VendAccount = dialogFieldVendAccount.value();
ttsbegin;
Numseq = NumberSeq::newGetNum(PurchParameters::numRefPurchId());
Purchtable.initValue();
purchTable.PurchId = Numseq.num();
purchTable.OrderAccount = _VendAccount;
purchTable.PurchName = VendTable::find(_VendAccount).name();
purchTable.InvoiceAccount = _VendAccount;
purchTable.PurchaseType = PurchaseType::Purch;
purchTable.DocumentStatus = DocumentStatus::PurchaseOrder;
purchTable.AccountingDate = systemDateGet();
purchTable.PurchStatus = PurchStatus::Backorder;
Purchtable.initFromVendTable();
info(strFmt("%1",_VendAccount));
purchTable.Insert();
while select _purchRe where _purchRe.VendAccount == _VendAccount
{
purchLine.initFromPurchTable(purchTable);
purchLine.PurchId = purchTable.PurchId;
axPurchLine = AxPurchLine::newPurchLine(purchLine);
purchLine.ItemId = _purchRe.ItemId;
purchLine.DeliveryDate = _purchRe.DelvDate;
purchLine.QtyOrdered = _purchRe.Qty;
purchLine.PriceUnit = _purchRe.Price;
inventDim.clear();
inventDim.InventSiteId = "1";
inventDim.InventLocationId = "12";
inventDim = InventDim::findOrCreate(inventDim);
purchLine.InventDimId = inventDim.inventDimId;
purchLine.insert();
PurchLine.LineNumber = axPurchLine.parmLineNumber((purchLine.LineNumber)+10);
info(strFmt("%1 : %2 : %3 : %4 : %5",purchLine.PurchId,purchLine.ItemId,_purchRe.DelvDate,purchLine.QtyOrdered,purchLine.PriceUnit));
}
ttsCommit;
}
super();
}
No comments:
Post a Comment