The posting of product
receipt/packing slip for purchase order is primarily done by using the class:
PurchFormLetter. The functions of PurchFormLetter class of 2009 AX are done by
the code of two classes in 2012 : One is PurchFormLetter and the other: purchFormLetterParmData.
The class
purchFormLetterParmData is responsible for creation of data which would be used
by PurchFormLetter.
We could use the
PurchFormLetter update method for posting packing slip in most cases, a typical
code snippet will look like:
static void Dev_CreatePO_and_Invoice(Args _args)
{
NumberSeq numberSeq;
Purchtable Purchtable;
PurchLine PurchLine;
PurchFormLetter purchFormLetter;
;
ttsbegin;
numberSeq = NumberSeq::newGetNumFromCode(purchParameters::numRefPurchaseOrderId().NumberSequence,true);
// Initialize Purchase order values
Purchtable.initValue();
Purchtable.PurchId = numberSeq.num();
Purchtable.OrderAccount = '3000';
Purchtable.initFromVendTable();
if (!Purchtable.validateWrite())
{
throw Exception::Error;
}
Purchtable.insert();
// Initialize Purchase Line items
PurchLine.PurchId = Purchtable.PurchId;
PurchLine.ItemId = 'B-R14';
PurchLine.createLine(true, true, true, true, true, false);
ttscommit;
purchFormLetter = purchFormLetter::construct(DocumentStatus::PackingSlip);
purchFormLetter.update(purchtable, // Purchase record Buffer
"PO_"+purchTable.PurchId, // Invoice Number
systemdateget()); // Transaction date
if (PurchTable::find(purchTable.PurchId).DocumentStatus == DocumentStatus:: PackingSlip)
{
info(strfmt("Posted invoiced journal for purchase order %1",purchTable.PurchId));
}
}
{
NumberSeq numberSeq;
Purchtable Purchtable;
PurchLine PurchLine;
PurchFormLetter purchFormLetter;
;
ttsbegin;
numberSeq = NumberSeq::newGetNumFromCode(purchParameters::numRefPurchaseOrderId().NumberSequence,true);
// Initialize Purchase order values
Purchtable.initValue();
Purchtable.PurchId = numberSeq.num();
Purchtable.OrderAccount = '3000';
Purchtable.initFromVendTable();
if (!Purchtable.validateWrite())
{
throw Exception::Error;
}
Purchtable.insert();
// Initialize Purchase Line items
PurchLine.PurchId = Purchtable.PurchId;
PurchLine.ItemId = 'B-R14';
PurchLine.createLine(true, true, true, true, true, false);
ttscommit;
purchFormLetter = purchFormLetter::construct(DocumentStatus::PackingSlip);
purchFormLetter.update(purchtable, // Purchase record Buffer
"PO_"+purchTable.PurchId, // Invoice Number
systemdateget()); // Transaction date
if (PurchTable::find(purchTable.PurchId).DocumentStatus == DocumentStatus:: PackingSlip)
{
info(strfmt("Posted invoiced journal for purchase order %1",purchTable.PurchId));
}
}
However in case you would be using run, the code structure
would look similar to the one in the PurchFormLetter.update method. To create
parmData we would use
purchFormLetterParmData =
PurchFormletterParmData::newData(DocumentStatus::PackingSlip,VersioningUpdateType::Initial);
purchFormLetterParmData.createData_IN(CustomsImportOrderType_IN::PurchaseOrder,false);
The piece of code would look like:
//create
our purchParmTable record to post against
purchFormLetter =
PurchFormLetter::construct(DocumentStatus::PackingSlip);
//insert data into table PurchParamUpdate
purchFormLetterParmData
=
PurchFormletterParmData::newData(DocumentStatus::PackingSlip,VersioningUpdateType::Initial);
purchFormLetterParmData.createData_IN(CustomsImportOrderType_IN::PurchaseOrder,false);
purchParmTable.clear();
purchParmTable.TransDate
= SystemDateGet();
purchParmTable.Ordering
= DocumentStatus::PackingSlip;
purchParmTable.ParmJobStatus
= ParmJobStatus::Waiting;
purchParmTable.Num = strfmt('%1',
ILSGatewayQueue.RecId);
purchParmUpdate
= purchFormLetterParmData.parmParmUpdate();
purchParmTable.ParmId
= purchParmUpdate.ParmId;
// fill in fields from PurchTable
purchParmTable.PurchId
= purchTable.PurchId;
purchParmTable.PurchName
= purchTable.PurchName;
purchParmTable.DeliveryName=
purchTable.DeliveryName;
purchParmTable.DeliveryPostalAddress = purchTable.DeliveryPostalAddress;
purchParmTable.OrderAccount
= purchTable.OrderAccount;
purchParmTable.CurrencyCode
= purchTable.CurrencyCode;
purchParmTable.InvoiceAccount
= purchTable.InvoiceAccount;
purchParmTable.insert();
// here we would
insert lines into purchParmLine add some logic etc
purchFormLetter.transDate(systemDateGet());
purchFormLetter.proforma(false);
purchFormLetter.specQty(PurchUpdate::All);
purchFormLetter.purchTable(purchTable);
purchFormLetter.parmParmTableNum(purchParmTable.ParmId);// this is the ID we hard code as the product receipt ID,
if we do the posting via UI,
// user would have the option to manually
enter this value
purchFormLetter.parmId(purchParmTable.ParmId);
purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate());
purchFormLetter.run();
No comments:
Post a Comment