Axapta 根据多个采购订单合并和开具发票。x++;ax 2012

Axapta 根据多个采购订单合并和开具发票。x++;ax 2012,axapta,microsoft-dynamics,x++,purchase-order,Axapta,Microsoft Dynamics,X++,Purchase Order,我有一个集成项目,我需要在x++中发布采购订单。我已经有它的工作,张贴发票对采购订单通过查找采购订单。填充vendInvoiceInfoTable、vendInvoiceInfoSubTable、vendInvoiceInfoLine和vendInvoiceInfoSubLine 然后,当我想发布时,我在完成后调用此代码,它发布的很好 purchFormLetterInvoice = PurchFormLetter_Invoice::newFromSavedInvoice

我有一个集成项目,我需要在x++中发布采购订单。我已经有它的工作,张贴发票对采购订单通过查找采购订单。填充vendInvoiceInfoTable、vendInvoiceInfoSubTable、vendInvoiceInfoLine和vendInvoiceInfoSubLine

然后,当我想发布时,我在完成后调用此代码,它发布的很好

            purchFormLetterInvoice = PurchFormLetter_Invoice::newFromSavedInvoice(vendInvoiceInfoTable);
            purchFormLetterInvoice.showQueryForm(false);
            purchFormLetterInvoice.specQty(PurchUpdate::PackingSlip);
            purchFormLetterInvoice.update(vendInvoiceInfoTable, vendInvoiceInfoTable.Num, systemdateget());
现在的问题是,我想将多个采购订单添加到发票中。我可以通过代码将行添加到vendorinvoice中,当我查看前端时,前端的采购订单和产品收据显示为“多行”。我还通过添加以下代码来添加参考表。我基本上添加了两次这个片段,如果我有两个采购订单,我只需替换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());

vendInvoiceInfoSubTable.SourceAccountingEvent
的值是多少?是不是
0

您没有提供足够的发布代码,但当我看到
SourceAccountingEvent
时,我立即认为您可能没有在需要时使用源文档框架

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

SourceDocumentProcessorFacade::submitSourceDocumentLineImplementation(…)

以前有一个关于源文档框架的博客,但现在不见了。您仍然可以在这里的wayback机器上找到它:


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

vendInvoiceInfoSubTable.SourceAccountingEvent的值是多少?是不是
0

您没有提供足够的发布代码,但当我看到
SourceAccountingEvent
时,我立即认为您可能没有在需要时使用源文档框架

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

SourceDocumentProcessorFacade::submitSourceDocumentLineImplementation(…)

以前有一个关于源文档框架的博客,但现在不见了。您仍然可以在这里的wayback机器上找到它:


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

是,当我调试时,额外PO的子表为0。第一个子表具有有效的源记帐事件,但第二个子表为0且失败。我不确定这到底是什么。我一直在研究SourceDocumentProcessorFacade::submitSourceDocumentLineImplementation(vendInvoiceInfoLine,1);似乎什么都不起作用,我仍然收到相同的错误,不确定我到底做了什么来修复。@Sirus-在那里放置一个断点(您可能需要关闭
CIL
),然后手动过帐发票。我没有你所有的代码,所以我没有一个完整的图片,但我认为你的问题与这个框架有关。您可能需要装箱单、子表等,如果没有真正调试,我不确定。如果你能以一种更具可重复性的工作方式发布你的所有代码,那就更容易理解了。网上应该有各种各样的发票过账代码。我用更多的代码编辑了我的初始过账。。。在线上没有太多的代码可以用于合并发票上的多个POS。使用这种方法有什么原因吗?您直接填充基础表,然后尝试将它们推到发票流程中,这意味着您必须确保所有内容都正确,才能成功过帐。您是否尝试过
TmpFrmVirtual
方法。是,当我调试时,附加PO的子表为0。第一个子表具有有效的源记帐事件,但第二个子表为0且失败。我不确定这到底是什么。我一直在研究SourceDocumentProcessorFacade::submitSourceDocumentLineImplementation(vendInvoiceInfoLine,1);似乎什么都不起作用,我仍然收到相同的错误,不确定我到底做了什么来修复。@Sirus-在那里放置一个断点(您可能需要关闭
CIL
),然后手动过帐发票。我没有你所有的代码,所以我没有一个完整的图片,但我认为你的问题与这个框架有关。您可能需要装箱单、子表等,如果没有真正调试,我不确定。如果你能以一种更具可重复性的工作方式发布你的所有代码,那就更容易理解了。网上应该有各种各样的发票过账代码。我用更多的代码编辑了我的初始过账。。。在线上没有太多的代码可以用于合并发票上的多个POS。使用这种方法有什么原因吗?您直接填充基础表,然后尝试将它们推到发票流程中,这意味着您必须确保所有内容都正确,才能成功过帐。您是否尝试过
TmpFrmVirtual
方法。