我有一个集成项目,我需要在 x++ 中发布采购订单。我已经让它通过查找采购订单针对采购订单发布发票。填充 vendInvoiceInfoTable、vendInvoiceInfoSubTable、vendInvoiceInfoLine 和 vendInvoiceInfoSubLine。
然后,当我想发布时,我会在完成后调用此代码,并且发布得很好。
purchFormLetterInvoice = PurchFormLetter_Invoice::newFromSavedInvoice(vendInvoiceInfoTable);
purchFormLetterInvoice.showQueryForm(false);
purchFormLetterInvoice.specQty(PurchUpdate::PackingSlip);
purchFormLetterInvoice.update(vendInvoiceInfoTable, vendInvoiceInfoTable.Num, systemdateget());
现在的问题是我想在发票中添加多个采购订单。我可以通过代码将这些行添加到 vendorinvoice 中,当我查看前端时,它在前端显示为采购订单和产品收据的“多个”。我还通过添加以下代码来添加参考表。如果我有 2 个采购订单,我基本上会添加两次此代码段,我只是替换 OriginPurchID。
vendInvoiceInfoSubTable.clear();
vendInvoiceInfoSubTable.initValue();
vendInvoiceInfoSubTable.defaultRow();
vendInvoiceInfoSubTable.OrigPurchId = "PO-XXX";
vendInvoiceInfoSubTable.TableRefId = vendInvoiceInfoTable.TableRefId;
vendInvoiceInfoSubTable.PurchName = purchTable.PurchName;
vendInvoiceInfoSubTable.insert();
问题是当我调用下面的代码发布时,它在下面的发布代码期间遇到错误。
if (vendInvoiceInfoSubTable.SourceAccountingEvent != localAccountingEvent.RecId)
{
vendInvoiceInfoTable.ErrorInvalidDistribution = NoYes::Yes;
throw error("@SYS326999");
}
然后它会导致此错误:在创建供应商发票后更正了采购订单或产品收据。必须重新创建所有会计分配以反映对采购订单或产品收据的会计分配的任何更改。
即使我强制向 vendInvoiceInfoSubTable.SourceAccountingEvent 输入下一个“事件 ID”,它也会在另一种方法中的单词之后失败。我已经没有东西可以尝试了。但我相信一些链接或不同的发布方式可能是解决方案,但我不确定。任何帮助将不胜感激。
同样奇怪的是,如果我在不发布的情况下运行代码并将其暂存于 AX 中。我去采购订单并尝试发布..它给了我同样的错误..但是如果我第二次再试一次..它实际上发布并得到了那个奇怪的错误。
这是删除私人信息时的大部分代码..
purchTable = purchTable::find(poNum);
vendInvoiceInfoTable.clear();
vendInvoiceInfoTable.initValue();
vendInvoiceInfoTable.initFromPurchTable(purchTable);
vendInvoiceInfoTable.OrderAccount= purchtable.OrderAccount;
vendInvoiceInfoTable.InvoiceAccount= purchTable.InvoiceAccount;
vendInvoiceInfoTable.Approved = NoYes::Yes;
vendInvoiceInfoTable.DocumentOrigin = DocumentOrigin::Manual;
vendInvoiceInfoTable.CurrencyCode = purchTable.CurrencyCode;
vendInvoiceInfoTable.DocumentDate=invoiceDate;
vendInvoiceInfoTable.Description=invoiceHeader.get_Description();
vendInvoiceInfoTable.DeliveryName = purchTable.DeliveryName;
vendInvoiceInfoTable.PurchName = purchTable.PurchName;
vendInvoiceInfoTable.BatchAdministration = NoYes::Yes;
vendInvoiceInfoTable.ParmJobStatus = ParmJobStatus::Waiting;
vendInvoiceInfoTable.FixedDueDate = purchTable.FixedDueDate;
vendInvoiceInfoTable.LastMatchVariance = LastMatchVarianceOptions::OK;
vendInvoiceInfoTable.TransDate = systemDateGet();
vendInvoiceInfoTable.VendInvoiceSaveStatus = VendInvoiceSaveStatus::Pending;
vendInvoiceInfoTable.Num=InvoiceNum;
vendInvoiceInfoTable.InventSiteId=purchtable.InventSiteId;
vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,RemittanceLocation),null,purchTable);
vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,FixedDueDate),null,purchTable);
vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,ExchRate),null,purchTable);
vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,TransDate),null,purchTable);
vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,PaymMode),null,purchTable);
vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,PaymSpec),null,purchTable);
vendInvoiceInfoTable.insert();
if(vendInvoiceInfoTable)
{
vendInvoiceInfoSubTable.clear();
vendInvoiceInfoSubTable.initValue();
vendInvoiceInfoSubTable.defaultRow();
vendInvoiceInfoSubTable.ParmId = vendInvoiceInfoTable.ParmId;
vendInvoiceInfoSubTable.OrigPurchId = "po-number1";
vendInvoiceInfoSubTable.TableRefId = vendInvoiceInfoTable.TableRefId;
vendInvoiceInfoSubTable.PurchName = purchTable.PurchName;
vendInvoiceInfoSubTable.insert();
vendInvoiceInfoSubTable.clear();
vendInvoiceInfoSubTable.initValue();
vendInvoiceInfoSubTable.defaultRow();
vendInvoiceInfoSubTable.ParmId = vendInvoiceInfoTable.ParmId;
vendInvoiceInfoSubTable.OrigPurchId = "po-number2";
vendInvoiceInfoSubTable.TableRefId = vendInvoiceInfoTable.TableRefId;
vendInvoiceInfoSubTable.PurchName = purchTable.PurchName;
vendInvoiceInfoSubTable.insert();
//vendInvoiceInfoTable.selectForUpdate(true);
// vendInvoiceInfoTable.SourceDocumentHeader = 0;
// vendInvoiceInfoTable.SourceDocumentLine = 0;
// vendInvoiceInfoTable.doUpdate();
// sourceDocumentProcessorFacade::submitSourceDocumentImplementation(vendInvoiceInfoTable,1);
}
//next part will loop through and create all the lines
while(enumerator.MoveNext())
{
vendInvoiceInfoLine.clear();
vendInvoiceInfoLine.initValue();
vendInvoiceInfoLine.initFromPurchLine(purchLine);
vendInvoiceInfoLine.DeliveryName = vendInvoiceInfoTable.DeliveryName;
vendInvoiceInfoLine.ParmId = vendInvoiceInfoTable.ParmId;
vendInvoiceInfoLine.TableRefId = vendInvoiceInfoTable.TableRefId;
vendInvoiceInfoLine.currencyCode = vendInvoiceInfoTable.CurrencyCode;
vendInvoiceInfoLine.InvoiceAccount = vendInvoiceInfoTable.InvoiceAccount;
vendInvoiceInfoLine.InventDimId = purchLine.InventDimId;
vendInvoiceInfoLine.OrderAccount = vendInvoiceInfoTable.OrderAccount;
vendInvoiceInfoLine.InventTransId = purchLine.InventTransId;
vendInvoiceInfoLine.PurchPrice=purchLine.PurchPrice;
vendInvoiceInfoLine.InventNow = calculatedQty;
vendInvoiceInfoLine.ReceiveNow = calculatedQty;
vendInvoiceInfoLine.RemainBefore = calculatedQty;
vendInvoiceInfoLine.RemainBeforeInvent = calculatedQty;
vendInvoiceInfoLine.DefaultDimension = purchLine.DefaultDimension;
vendInvoiceInfoLine.LineAmount = amt;
vendInvoiceInfoLine.insert();
while select * from vendPackingSlipTrans
where vendPackingSlipTrans.OrigPurchid==purchLine.PurchId
&& vendPackingSlipTrans.InventTransId==purchLine.InventTransId
{
vendInvoiceInfoSubLine.clear();
vendInvoiceInfoSubLine.initValue();
vendInvoiceInfoSubLine.defaultRow();
vendInvoiceInfoSubLine.ParmId = vendInvoiceInfoTable.ParmId;
vendInvoiceInfoSubLine.LineRefRecId = vendInvoiceInfoLine.RecId;
vendInvoiceInfoSubLine.ReceiveNow = vendPackingSlipTrans.Qty;
vendInvoiceInfoSubLine.InventNow = vendPackingSlipTrans.Qty;
vendInvoiceInfoSubLine.JournalRefRecId = vendPackingSlipTrans.RecId;
vendInvoiceInfoSubLine.JournalRefTableId = vendPackingSlipTrans.TableId;
vendInvoiceInfoSubLine.DocumentId = vendPackingSlipTrans.PackingSlipId;
vendInvoiceInfoSubLine.insert();
}
}
purchFormLetterInvoice = PurchFormLetter_Invoice::newFromSavedInvoice(vendInvoiceInfoTable);
purchFormLetterInvoice.showQueryForm(false);
purchFormLetterInvoice.specQty(PurchUpdate::PackingSlip);
purchFormLetterInvoice.update(vendInvoiceInfoTable, vendInvoiceInfoTable.Num, systemdateget());