public static void main(Args _args)
{
PurchPurchaseOrderHeaderV2Entity purchPurchaseOrderHeaderV2Entity;
PurchPurchaseOrderLineV2Entity purchPurchaseOrderLineV2Entity;
PurchFormLetter purchFormLetter;
PurchFormletterParmData purchFormLetterParmData;
PurchParmUpdate purchParmUpdate;
PurchParmTable purchParmTable;
NumberSeq numberSeq;
MarkupTrans markupTrans;
PurchLine purchLine;
SourceDocumentLine sourcedoucumentline;
PurchParmLine purchParmLine;
PurchTable purchTable;
PurchId purchId;
Num packingSlipId;
numberSeq = NumberSeq::newGetNum(PurchParameters::numRefPurchId());
numberSeq.used();
purchPurchaseOrderHeaderV2Entity.initValue();
purchPurchaseOrderHeaderV2Entity.PurchaseOrderNumber = numberSeq.num();
purchPurchaseOrderHeaderV2Entity.PurchaseOrderName = "custom Order";
purchPurchaseOrderHeaderV2Entity.OrderVendorAccountNumber = "1001";
purchPurchaseOrderHeaderV2Entity.insert();
purchPurchaseOrderLineV2Entity.PurchaseOrderNumber = purchPurchaseOrderHeaderV2Entity.PurchaseOrderNumber;
purchPurchaseOrderLineV2Entity.ItemNumber = '1000';
purchPurchaseOrderLineV2Entity.PurchasePrice = 10;
purchPurchaseOrderLineV2Entity.PurchasePriceQuantity = 2;
purchPurchaseOrderLineV2Entity.OrderedPurchaseQuantity = 10;
purchPurchaseOrderLineV2Entity.ReceivingSiteId = '1';
purchPurchaseOrderLineV2Entity.ReceivingWarehouseId = '11';
purchPurchaseOrderLineV2Entity.insert();
purchId = purchPurchaseOrderLineV2Entity.PurchaseOrderNumber;
packingSlipId = "MA"+ purchId;
purchTable = PurchTable::find(purchId);
select purchLine
where purchLine.RecId == purchPurchaseOrderLineV2Entity.RecId;
//creating a maintain charges record for line
markupTrans.initFromMarkupTable(MarkupTable::find(MarkupModuleType::Vend, "FREIGHT"));
markupTrans.initFromPurchLine(purchLine);
markupTrans.LineNum = MarkupTrans::lastLineNum(markupTrans.TransTableId, markupTrans.TransRecId)+1;
markupTrans.modifiedField(fieldNum(markupTrans ,Value ));
markupTrans.MarkupCode = "FREIGHT";
markupTrans.Txt = "Freight";
markupTrans.MarkupCategory = MarkupCategory::Fixed;
markupTrans.Value = 200;
markupTrans.MCROriginalMiscChargeValue = 200;
markupTrans.CurrencyCode = "USD";
markupTrans.ModuleType = MarkupModuleType::Vend;
markupTrans.ModuleCategory = HeadingLine::Line;
markupTrans.TransDate = today();
markupTrans.insert();
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(purchPurchaseOrderHeaderV2Entity, strFmt("Inv_%1", purchPurchaseOrderHeaderV2Entity.PurchaseOrderNumber));
ttsBegin;
// Create PurchParamUpdate table
purchFormLetterParmData = PurchFormletterParmData::newData(
DocumentStatus::PackingSlip,
VersioningUpdateType::Initial);
purchFormLetterParmData.parmOnlyCreateParmUpdate(true);
purchFormLetterParmData.createData(false);
purchParmUpdate = purchFormLetterParmData.parmParmUpdate();
//Set PurchParmTable table
purchParmTable.clear();
purchParmTable.TransDate = SystemDateGet();
purchParmTable.Ordering = DocumentStatus::PackingSlip;
purchParmTable.ParmJobStatus = ParmJobStatus::Waiting;
purchParmTable.Num = packingSlipId;
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.ParmId = purchParmUpdate.ParmId;
purchParmTable.insert();
// Set PurchParmLine table
while select purchLine
where purchLine.PurchId == purchTable.purchId
{
purchParmLine.InitFromPurchLine(purchLine);
purchParmLine.ReceiveNow = 5;//PurchLine.PurchQty;
purchParmLine.ParmId = purchParmTable.ParmId;
purchParmLine.TableRefId = purchParmTable.TableRefId;
purchParmLine.setQty(DocumentStatus::PackingSlip, false, true);
purchParmLine.setLineAmount();
purchParmLine.insert();
}
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
purchFormLetter.transDate(systemDateGet());
purchFormLetter.proforma(false);
purchFormLetter.specQty(PurchUpdate::All);
purchFormLetter.purchTable(purchTable);
// 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.parmParmTableNum(purchParmTable.ParmId);
purchFormLetter.parmId(purchParmTable.ParmId);
purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate());
purchFormLetter.run();
ttsCommit;
//posting of invoice
purchFormLetter = purchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.update(purchTable, "Inv_"+purchTable.PurchId,systemdateget(),PurchUpdate::PackingSlip); // Transaction date
info(purchTable.PurchId);
}
...............................