合并多个采购订单并开具发票。 x++ 斧头 2012

问题描述 投票:0回答:2

我有一个集成项目,我需要在 x++ 中发布采购订单。 我已经让它通过查找采购订单来根据采购订单过帐发票。填充 vendInvoiceInfoTable、vendInvoiceInfoSubTable、vendInvoiceInfoLine 和 vendInvoiceInfoSubLine。

然后,当我想发布时,我会在完成后调用此代码,并且它发布得很好。

            purchFormLetterInvoice = PurchFormLetter_Invoice::newFromSavedInvoice(vendInvoiceInfoTable);
            purchFormLetterInvoice.showQueryForm(false);
            purchFormLetterInvoice.specQty(PurchUpdate::PackingSlip);
            purchFormLetterInvoice.update(vendInvoiceInfoTable, vendInvoiceInfoTable.Num, systemdateget());

现在的问题是我想在发票中添加多个采购订单。 我可以通过代码将行添加到供应商发票中,当我查看前端时,它在前端的采购订单和产品收据中显示为“多个”。 我还通过添加以下代码来添加参考表。 如果我有 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");
    }

然后会导致此错误:创建供应商发票后更正了采购订单或产品收据。必须重新创建所有会计分配,以反映采购订单或产品收据会计分配的任何更改。

即使我强制输入下一个“事件 ID”到 vendInvoiceInfoSubTable.SourceAccountingEvent,它也会在另一个方法中的单词后失败。我已经没有什么可以尝试的了。 但我相信一些链接或不同的发布方式可能是解决方案,但我不确定。任何帮助将不胜感激,谢谢。

奇怪的是,如果我运行代码而不发布并将其暂存在 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());
axapta microsoft-dynamics x++ purchase-order
2个回答
0
投票

vendInvoiceInfoSubTable.SourceAccountingEvent
的价值是多少?是
0
吗?

您没有提供足够的发布代码,但是当我看到

SourceAccountingEvent
时,我立即想到您可能在需要时没有使用源文档框架。

您可能需要使用如下所示的行:

SourceDocumentProcessorFacade::submitSourceDocumentLineImplementation(...);

曾经有一个关于源文档框架的很棒的博客,但消失了。您仍然可以在此处的回程机器上找到它:

https://web.archive.org/web/20150323025403/http://blogs.msdn.com/b/ax_gfm_framework_team_blog/archive/2012/04/26/extending-the-source-document-framework.aspx

如果您的问题与源文档框架无关,这个答案不会有太大帮助。


0
投票

您是否能够在自动化批量流程中实现多 PO 发票? 我使用同一段代码为多个采购订单创建发票并成功,但无法发布它。 如果你成功了,请分享技巧。 谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.