2

我正在使用此代码创建新发票。我从 SOInvoiceEntry 进行定制。我调试并得到一个错误 Revision ID is not empty。当我为 customerID 设置值时,我客人说此代码无法获取客户财务信息的信息。这是我的代码。谢谢你的支持。

public PXAction<ARInvoice> preparePayment;

    [PXUIField(DisplayName = "Pay Invoice", Enabled = true)]
    [PXButton()]
    public IEnumerable PreparePayment(PXAdapter adapter)
    {
        List<ARRegister> doclist = new List<ARRegister>();
        SOOrderShipment soOrderShipment =
                     PXSelect
                         <SOOrderShipment,
                             Where<SOOrderShipment.invoiceNbr, Equal<Required<SOOrderShipment.invoiceNbr>>>
                             >.Select(new PXGraph(), Base.Document.Current.RefNbr);

        if (soOrderShipment != null)
        {
            SOOrder soOrder = PXSelect<SOOrder, Where<SOOrder.orderNbr,
                Equal<Required<SOOrder.orderNbr>>,
                And<SOOrder.orderType, Equal<Required<SOOrder.orderType>>>>>.Select(
                    new PXGraph(), soOrderShipment.OrderNbr, soOrderShipment.OrderType);
            SOOrderExt soExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(soOrder);
            if (soExt.CustomerID != soExt.UsrARCustomer)
            {
                ARInvoiceEntry arInvoiceGraph = PXGraph.CreateInstance<ARInvoiceEntry>();
                ARInvoice invoice = (ARInvoice)arInvoiceGraph.Caches[typeof(ARInvoice)].CreateInstance();
                invoice = (ARInvoice) arInvoiceGraph.Caches[typeof (ARInvoice)].Insert(invoice);
                arInvoiceGraph.Caches[typeof(ARInvoice)].SetValue<ARInvoice.customerID>(invoice,soExt.UsrARCustomer);

                invoice.DocType = ARInvoiceType.DebitMemo;
                invoice.CustomerID = soExt.UsrARCustomer;
                //invoice.CustomerID = Base.Document.Current.CustomerID;
                Location location =
                    PXSelect<Location, Where<Location.bAccountID, Equal<Required<Location.bAccountID>>>>.Select(
                        arInvoiceGraph, soExt.UsrARCustomer);
                if(location!=null)
                       arInvoiceGraph.Caches[typeof(ARInvoice)].SetValue<ARInvoice.customerLocationID>(invoice, location.LocationID);
                arInvoiceGraph.Caches[typeof(ARInvoice)].SetValueExt<ARInvoice.docDate>(invoice, DateTime.Now);
                arInvoiceGraph.Caches[typeof(ARInvoice)].SetValue<ARInvoice.projectID>(invoice,location.CDefProjectID);

                ARInvoice oldInvoice = (ARInvoice)arInvoiceGraph.Caches[typeof(ARInvoice)].CreateCopy(invoice);

                invoice.CuryOrigDocAmt = 0;
                arInvoiceGraph.Caches[typeof(ARInvoice)].RaiseRowUpdated(invoice, oldInvoice);
                arInvoiceGraph.Caches[typeof(ARInvoice)].SetValue<ARInvoice.curyOrigDocAmt>(invoice, invoice.CuryDocBal);
                invoice.RefNoteID = 1;

                arInvoiceGraph.Caches[typeof(ARInvoice)].SetValueExt<ARInvoice.hold>(invoice, false);

                doclist.Add((ARInvoice)arInvoiceGraph.Caches[typeof(ARInvoice)].Current);
                arInvoiceGraph.Save.Press();

            }


        }

}

4

4 回答 4

0

我很怀疑

arInvoiceGraph.Transactions.Current = arTranUpdated;

根据 T200 手册: 您可以在以下情况下设置 Current 属性: • 能够通过图形处理多条数据记录(参见示例 9.2:实施收据下达操作)。• 当您从另一个页面重定向到页面时,能够打开显示指定数据记录的页面(请参见示例 3.4:将重定向链接添加到网格)。

我不确定,在您的情况下,您会执行第 1 点或第 2 点。

于 2015-04-02T08:29:45.920 回答
0

就我protected virtual void ARInvoice_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)在基本图中查看内部而言,我在那里看到了一些错误消息,上面写着"may not be empty". 没有任何与 RevisionID 相关的代码。ARInvoice但是在 DAC 类的字段中有一个具有 RevisionID 的代码BillAddressID, BillContactID。根据这个事实,我建议您检查是否为 ARAddress 输入了正确的 ID,ARInvoice并检查 db 表 ARAddress 是否在列 RevisionID 中有值。这是必需的,因为 ARAddress 类中的 RevisionID 以下列方式声明:

    [PXDBInt]
    [PXDefault]
    public virtual int? RevisionID
    {
      get
      {
        return this._RevisionID;
      }
      set
      {
        this._RevisionID = value;
      }
    }
于 2015-03-31T10:20:58.037 回答
0
 arInvoiceGraph.Caches[typeof(ARInvoice)].SetValue<ARInvoice.customerID>(invoice,soExt.UsrARCustomer);

尝试这个

invoice.Customer = soExt.UsrARCustomer;
invoice = arInvoiceGraph.Caches[typeof(ARInvoice)].Update(invoice);
于 2015-03-31T10:52:11.337 回答
0

我找到了通过像这样的更改代码保存文档数据的解决方案

 public IEnumerable PreparePayment(PXAdapter adapter)
    {
        List<ARRegister> doclist = new List<ARRegister>();
        SOOrderShipment soOrderShipment =
                     PXSelect
                         <SOOrderShipment,
                             Where<SOOrderShipment.invoiceNbr, Equal<Required<SOOrderShipment.invoiceNbr>>>
                             >.Select(new PXGraph(), Base.Document.Current.RefNbr);

        if (soOrderShipment != null)
        {
            SOOrder soOrder = PXSelect<SOOrder, Where<SOOrder.orderNbr,
                Equal<Required<SOOrder.orderNbr>>,
                And<SOOrder.orderType, Equal<Required<SOOrder.orderType>>>>>.Select(
                    new PXGraph(), soOrderShipment.OrderNbr, soOrderShipment.OrderType);
            SOOrderExt soExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(soOrder);
            if (soExt.CustomerID != soExt.UsrARCustomer)
            {
                BAccount bAccount = PXSelect<BAccount, Where<BAccount.bAccountID,Equal<Required<BAccount.bAccountID>>>>.Select(new PXGraph(),soExt.UsrARCustomer);
                ARInvoiceEntry arInvoiceGraph = PXGraph.CreateInstance<ARInvoiceEntry>();
                ARInvoice invoice = (ARInvoice)arInvoiceGraph.Caches[typeof(ARInvoice)].CreateInstance();
                invoice = (ARInvoice) arInvoiceGraph.Caches[typeof (ARInvoice)].Insert(invoice);
                // Using SetValueExt by Passing AcctCD
arInvoiceGraph.Caches[typeof(ARInvoice)].SetValueExt<ARInvoice.customerID>(invoice,bAccount.AcctCD);
                invoice.CustomerID = soExt.UsrARCustomer;
                arInvoiceGraph.Caches[typeof(ARInvoice)].SetValue<ARInvoice.docDesc>(invoice, "N/A");
                invoice.DocType = ARInvoiceType.DebitMemo;

                Location location =
                    PXSelect<Location, Where<Location.bAccountID, Equal<Required<Location.bAccountID>>>>.Select(
                        arInvoiceGraph, soExt.UsrARCustomer);
                if(location!=null)
                       arInvoiceGraph.Caches[typeof(ARInvoice)].SetValue<ARInvoice.customerLocationID>(invoice, location.LocationID);

                arInvoiceGraph.Caches[typeof(ARInvoice)].Update(invoice);
                ARInvoice oldInvoice = (ARInvoice)arInvoiceGraph.Caches[typeof(ARInvoice)].CreateCopy(invoice);

                invoice.CuryOrigDocAmt = Base.Document.Current.CuryOrigDocAmt;
                arInvoiceGraph.Caches[typeof(ARInvoice)].RaiseRowUpdated(invoice, oldInvoice);
                arInvoiceGraph.Caches[typeof(ARInvoice)].SetValue<ARInvoice.curyOrigDocAmt>(invoice, invoice.CuryDocBal);
                arInvoiceGraph.Caches[typeof(ARInvoice)].SetValueExt<ARInvoice.hold>(invoice, false);
                arInvoiceGraph.Caches[typeof(ARInvoice)].Update(invoice);
                doclist.Add((ARInvoice)arInvoiceGraph.Caches[typeof(ARInvoice)].Current);
       // Insert transaction data
                ARTran arTran = new ARTran();
                arTran.TranDesc = "Total Value";
                arTran.Qty = 1;
                arTran.UnitPrice = Base.Document.Current.CuryDocBal;
                arTran.CuryLineAmt = Base.Document.Current.CuryDocBal;
                arInvoiceGraph.Transactions.Insert(arTran);
                ARTran arTranUpdated = (ARTran) arInvoiceGraph.Transactions.Update(arTran);
                arInvoiceGraph.Transactions.Current = arTranUpdated;
                arInvoiceGraph.Transactions.Cache.Update(arInvoiceGraph.Transactions.Current);
                arInvoiceGraph.Save.Press();

            }


        }

虽然保存了文档数据,但没有保存交易数据。我已经尝试过这段代码来创建它,但我得到了错误。你对此有什么建议吗?感谢您的支持

 AR Error #113: Cannot save notes.

   at PX.Objects.AR.InvoiceNbrAttribute.RowPersisted(PXCache sender, PXRowPersistedEventArgs e)
   at PX.Objects.AR.ARInvoiceNbrAttribute.RowPersisted(PXCache sender, PXRowPersistedEventArgs e)
   at PX.Data.PXCache.OnRowPersisted(Object item, PXDBOperation operation, PXTranStatus tranStatus, Exception exception)
   at PX.Data.PXTableAttribute.PersistInserted(PXCache sender, Object row)
   at PX.Data.PXCache`1.PersistInserted(Object row)
   at PX.Data.PXCache`1.Persist(PXDBOperation operation)
   at PX.Data.PXGraph.Persist(Type cacheType, PXDBOperation operation)
   at PX.Data.PXGraph.Persist()
   at PX.Objects.AR.ARInvoiceEntry.Persist()
   at PX.Data.PXSave`1.d__0.MoveNext()
   at PX.Data.PXAction`1.d__c.MoveNext()
   at PX.Data.PXAction`1.d__c.MoveNext()
   at PX.Data.PXAction`1.Press() 
于 2015-04-01T10:15:17.323 回答