static void CreatePO(Args _args)
{ NumberSeq numberSeq; Purchtable Purchtable; PurchLine PurchLine; PurchParmTable purchParmTable; PurchFormLetter purchFormLetter; InventDimId _inventDimId; InventDim inventDim; DocumentDate docDate; PurchParmUpdate purchParmUpdate; PurchFormletterParmData purchFormLetterParmData; Date myDate; str test; container ledgerDimensions; DimensionDefault dimensionDefault; changeCompany("SomeCompany") //Inserts into specified company { //numRefPurchaseOrderId() ttsbegin; numberSeq = NumberSeq::newGetNum(purchParameters::numRefPurchId()); _inventDimId="InventDimID"; // Initialize Purchase order values Purchtable.initValue(); Purchtable.PurchId = numberSeq.num(); Purchtable.OrderAccount = 'OrderAccount'; Purchtable.initFromVendTable(); if (!Purchtable.validateWrite()) { throw Exception::Error; } Purchtable.insert(); // Initialize Purchase Line items PurchLine.clear(); PurchLine.initValue(purchTable.PurchaseType); PurchLine.initFromPurchTable(Purchtable); PurchLine.initFromInventTable(InventTable::find('SomeItem')); PurchLine.PurchId = Purchtable.PurchId; PurchLine.InventDimId="InventDimID"; PurchLine.PurchQty=1; PurchLine.PurchUnit="EA2D"; ledgerDimensions = ['ItemGroup', 'SUMP']; dimensionDefault=AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimensions); PurchLine.LedgerDimension=dimensionDefault; PurchLine.PriceUnit=1.0; PurchLine.PurchPrice=1; // purchLine.RemainPurchPhysical = purchLine.PurchQty; // purchLine.QtyOrdered = purchLine.calcQtyOrdered(); // purchLine.setPriceDisc(InventDim::find(purchLine.InventDimId)); // PurchLine.LineDisc=1; // PurchLine.LinePercent=1; // PurchLine.PurchMarkup=1; //PurchLine.LineAmount=PurchLine.calcLineAmount(); PurchLine.LineAmount=1; //PurchLine.LinePercent=1; PurchLine.createLine(true, true, false, true, true, false); ttscommit; test="11/30/2018"; myDate=str2Date(test,213); // Create PurchParamUpdate table purchFormLetterParmData = PurchFormletterParmData::newData( DocumentStatus::PurchaseOrder, VersioningUpdateType::Initial); purchFormLetterParmData.parmOnlyCreateParmUpdate(true); purchFormLetterParmData.createData(false); purchParmUpdate = purchFormLetterParmData.parmParmUpdate(); purchParmUpdate.SpecQty=PurchUpdate::All; // Set PurchParmTable table purchParmTable.clear(); purchParmTable.TransDate = SystemDateGet(); purchParmTable.DocumentDate = myDate; purchParmTable.Ordering = DocumentStatus::PurchaseOrder; purchParmTable.ParmJobStatus = ParmJobStatus::Waiting; 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.Description="test"; purchParmTable.Num=purchTable.PurchId; //if (purchParmTable.validateWrite()) purchParmTable.insert(); // else //throw Exception::Error; // Create PurchParamUpdate table purchFormletter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder); // to post invoice change to DocumentStatus::invoice purchFormLetter.transDate(systemDateGet()); purchFormLetter.proforma(false); purchFormLetter.specQty(PurchUpdate::All); purchFormLetter.purchTable(purchTable); purchFormLetter.parmParmTableNum(purchParmTable.ParmId); purchFormLetter.parmId(purchParmTable.ParmId); purchFormLetter.purchParmUpdate(purchParmUpdate); purchFormLetter.run(); purchFormLetterParmData = PurchFormletterParmData::newData( DocumentStatus::Invoice, VersioningUpdateType::Initial); purchFormLetterParmData.parmOnlyCreateParmUpdate(true); purchFormLetterParmData.createData(false); purchParmUpdate = purchFormLetterParmData.parmParmUpdate(); purchParmUpdate.SpecQty=PurchUpdate::All; purchParmTable.clear(); purchParmTable.TransDate = SystemDateGet(); purchParmTable.DocumentDate = myDate; purchParmTable.Ordering = DocumentStatus::Invoice; purchParmTable.ParmJobStatus = ParmJobStatus::Waiting; 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.Description="test"; purchParmTable.Num=purchTable.PurchId; // purchParmTable.Description="test"; //if (purchParmTable.validateWrite()) purchParmTable.insert(); purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice); purchFormLetter.transDate(systemDateGet()); purchFormLetter.proforma(false); purchFormLetter.specQty(PurchUpdate::All); purchFormLetter.purchTable(purchTable); purchFormLetter.parmParmTableNum(purchParmTable.ParmId); purchFormLetter.parmId(purchParmTable.ParmId); purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate()); // purchFormLetter.reArrangeNow(true); purchFormLetter.run(); if (PurchTable::find(purchTable.PurchId).DocumentStatus == DocumentStatus::Invoice) { info(strfmt("Posted invoiced journal for purchase order %1",purchTable.PurchId)); } } }标签:PurchLine,purchParmTable,create,PO,purchParmUpdate,purchFormLetter,Post,PurchId, From: https://www.cnblogs.com/lingdanglfw/p/17250221.html