按代码创建发票

时间:2015-03-31 08:56:25

标签: c# cloud erp acumatica

我正在使用此代码创建新的发票。我从SOInvoiceEntry进行自定义。我调试并收到错误修订ID不为空。我在访客时说,当我为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 个答案:

答案 0 :(得分:0)

据我在基础图中查看protected virtual void ARInvoice_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)内部,我看到一些错误消息,其中显示"may not be empty"。没有任何与RevisionID相关的代码。但是有一个代码在DAC类ARInvoice中有RevisionID,字段为BillAddressID, BillContactID。根据这些事实,我建议您检查是否在ARInvoice中为ARAddress添加了正确的ID,并检查db table ARAddress中的值是否在列RevisionID中有值。这是必需的,因为类ARAddress中的RevisionID以下列方式声明:

    [PXDBInt]
    [PXDefault]
    public virtual int? RevisionID
    {
      get
      {
        return this._RevisionID;
      }
      set
      {
        this._RevisionID = value;
      }
    }

答案 1 :(得分:0)

 arInvoiceGraph.Caches[typeof(ARInvoice)].SetValue<ARInvoice.customerID>(invoice,soExt.UsrARCustomer);

试试这个

invoice.Customer = soExt.UsrARCustomer;
invoice = arInvoiceGraph.Caches[typeof(ARInvoice)].Update(invoice);

答案 2 :(得分: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() 

答案 3 :(得分:0)

我怀疑

arInvoiceGraph.Transactions.Current = arTranUpdated;

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

我不确定,在你的情况下,你会指出1或2点。