Process Sales Order中如何判断流程是否完成
How to determine process is complete or not in Process Sales Order
我在分发模块 (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);
}
}
感谢您的支持。
西蒙,
您可以在 foreach 循环中检查 Released 标志。
foreach (var inv in invList)
{
if (inv.Released == true)
{
//your custom code here
}
}
我已经通过下面的代码找到了解决方案。感谢大家的支持。
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
}
}
我在分发模块 (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);
}
}
感谢您的支持。
西蒙, 您可以在 foreach 循环中检查 Released 标志。
foreach (var inv in invList)
{
if (inv.Released == true)
{
//your custom code here
}
}
我已经通过下面的代码找到了解决方案。感谢大家的支持。
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
}
}