このコードを使用して新しい請求書を作成しています。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();
}
}
}