我正在使用此代码创建新发票。我从 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();
}
}
}