我为分配模块中的发票创建扩展(SO303000)。我需要在根据当前发票发布时自动创建付款。通过使用以下代码
,我已成功使用单一发票 public PXAction<ARInvoice> release;
[PXUIField(DisplayName = "Release", Visible = false)]
[PXButton()]
public IEnumerable Release(PXAdapter adapter)
{
Base.Release(adapter);
PXLongOperation.WaitCompletion(Base.UID);
ARPaymentEntry arPaymentEntry = PXGraph.CreateInstance<ARPaymentEntry>();
ARPayment payment = arPaymentEntry.Document.Insert();
payment.CustomerID = Base.Document.Current.CustomerID;
payment.CustomerLocationID = Base.Document.Current.CustomerLocationID;
payment.PaymentMethodID = "TM";
Branch branch = PXSelect<Branch>.Select(new PXGraph());
CashAccount ca =
PXSelect<CashAccount, Where<CashAccount.branchID, Equal<Required<CashAccount.branchID>>>>
.Select
(new PXGraph(),
branch.BranchID).FirstTableItems.FirstOrDefault();
if (ca != null)
{
payment.CashAccountID = ca.CashAccountID;
}
else
{
throw new PXException("Cannot find the Cash Account.");
}
payment.ExtRefNbr = "Auto";
payment.Hold = false;
payment.CuryOrigDocAmt = Base.Document.Current.CuryLineTotal;
arPaymentEntry.Document.Current = payment;
arPaymentEntry.Document.Cache.Update(arPaymentEntry.Document.Current);
ARAdjust arAdjust = new ARAdjust();
arAdjust.AdjdRefNbr = Base.Document.Current.RefNbr;
arAdjust.AdjgRefNbr = arPaymentEntry.Document.Current.RefNbr;
arAdjust.AdjgDocType = arPaymentEntry.Document.Current.DocType;
arAdjust.AdjdDocType = Base.Document.Current.DocType;
arAdjust.CustomerID = Base.Document.Current.CustomerID;
arAdjust.AdjdBranchID = branch.BranchID;
arAdjust.AdjgBranchID = branch.BranchID;
arAdjust.AdjdDocDate = Base.Document.Current.DocDate;
arAdjust.AdjdFinPeriodID = Base.Document.Current.FinPeriodID;
arAdjust.Released = false;
arAdjust.Voided = false;
arPaymentEntry.Adjustments.Insert(arAdjust);
ARAdjust arAdjusted = (ARAdjust) arPaymentEntry.Adjustments.Update(arAdjust);
arPaymentEntry.Adjustments.Current = arAdjusted;
var arAdapter =
new PXAdapter(new DummyView(arPaymentEntry, arPaymentEntry.Document.View.BqlSelect,
new List<object> {arPaymentEntry.Document.Current}))
{
};
arPaymentEntry.Save.Press();
arPaymentEntry.Release(arAdapter);
}
。但在流程发票和付款屏幕(SO505000)。我必须将我的代码更改为,因为当在页面SO505000中进行处理时,它们会将列表传递给适配器,因此我需要使用循环。我想使用PXLongOperation.WaitCompletion来确定发布的发票。
public PXAction<ARInvoice> release;
[PXUIField(DisplayName = "Release", Visible = false)]
[PXButton()]
public IEnumerable Release(PXAdapter adapter)
{
var list = Base.Release(adapter);
var invList = adapter.Get<ARInvoice>();
foreach (var inv in invList)
{
ARPaymentEntry arPaymentEntry = PXGraph.CreateInstance<ARPaymentEntry>();
ARPayment payment = arPaymentEntry.Document.Insert();
payment.CustomerID = inv.CustomerID;
payment.CustomerLocationID = inv.CustomerLocationID;
payment.PaymentMethodID = "TM";
Branch branch = PXSelect<Branch>.Select(new PXGraph());
CashAccount ca =
PXSelect
<CashAccount, Where<CashAccount.branchID, Equal<Required<CashAccount.branchID>>>>
.Select
(new PXGraph(),
branch.BranchID).FirstTableItems.FirstOrDefault();
if (ca != null)
{
payment.CashAccountID = ca.CashAccountID;
}
else
{
throw new PXException("Cannot find the Cash Account.");
}
payment.ExtRefNbr = "Auto";
payment.Hold = false;
payment.CuryOrigDocAmt = inv.CuryLineTotal;
arPaymentEntry.Document.Current = payment;
arPaymentEntry.Document.Cache.Update(arPaymentEntry.Document.Current);
//arPaymentEntry.Save.Press();
ARAdjust arAdjust = new ARAdjust();
arAdjust.AdjdRefNbr = inv.RefNbr;
arAdjust.AdjgRefNbr = inv.RefNbr;
arAdjust.AdjgDocType = inv.DocType;
arAdjust.AdjdDocType = inv.DocType;
arAdjust.CustomerID = inv.CustomerID;
arAdjust.AdjdBranchID = branch.BranchID;
arAdjust.AdjgBranchID = branch.BranchID;
arAdjust.AdjdDocDate = inv.DocDate;
arAdjust.AdjdFinPeriodID = inv.FinPeriodID;
arAdjust.Released = false;
arAdjust.Voided = false;
arPaymentEntry.Adjustments.Insert(arAdjust);
ARAdjust arAdjusted = (ARAdjust) arPaymentEntry.Adjustments.Update(arAdjust);
arPaymentEntry.Adjustments.Current = arAdjusted;
var arAdapter =
new PXAdapter(new DummyView(arPaymentEntry, arPaymentEntry.Document.View.BqlSelect,
new List<object> {arPaymentEntry.Document.Current}))
{
};
arPaymentEntry.Save.Press();
arPaymentEntry.Release(arAdapter);
}
}
感谢您的支持。
答案 0 :(得分:0)
西蒙 你可以在foreach循环中检查释放的标志。
foreach (var inv in invList)
{
if (inv.Released == true)
{
//your custom code here
}
}
答案 1 :(得分:0)
我通过以下代码找到了解决方案。感谢您的支持。
public IEnumerable Release(PXAdapter adapter)
{
var refNbrList = new Dictionary<string, string>();
var invList = adapter.Get<ARInvoice>();
foreach (var inv in invList)
{
PXDatabase.Execute("pp_DMS_SO_Invoice_InsertSettleDate",
new PXSPInParameter("@CompanyID", PXContext.GetSlot<int?>("singleCompanyID")),
new PXSPInParameter("@InvoiceType", inv.DocType),
new PXSPInParameter("@InvoiceNBR", inv.RefNbr));
ARInvoiceEntry invoiceEntry = PXGraph.CreateInstance<ARInvoiceEntry>();
invoiceEntry.Document.Current = inv;
invoiceEntry.Document.Cache.Update(invoiceEntry.Document.Current);
var arInvoiceAdapter =
new PXAdapter(new DummyView(invoiceEntry, invoiceEntry.Document.View.BqlSelect,
new List<object> { invoiceEntry.Document.Current }))
{ };
invoiceEntry.Release(arInvoiceAdapter);
PXLongOperation.WaitCompletion(invoiceEntry.UID);
// create payment here
}
}