using PX.Data;
using PX.Objects.GL;
using System.Collections;
using ARCashSale = PX.Objects.AR.Standalone.ARCashSale;
namespace PX.Objects.AR
{
public class ARCashSaleEntry_Extension : PXGraphExtension<ARCashSaleEntry>
{
#region Event Handlers
public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
[PXOverride]
public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
// Get reference to current cash sale if required
ARCashSale cashSale = Base.Document.Current;
// Declare event handler so we can remove the named delegate
PXGraph.InstanceCreatedDelegate<JournalEntry> instanceCreatedHandler = null;
// Handler definition used to intercept Journal Entry Graph
instanceCreatedHandler = delegate (JournalEntry oldJournalEntry)
{
// Remove event handler
PXGraph.InstanceCreated.RemoveHandler<JournalEntry>(instanceCreatedHandler);
// Add hook to intercept Batch persisted event
oldJournalEntry.RowPersisted.AddHandler<Batch>(delegate (PXCache sender, PXRowPersistedEventArgs e)
{
// Get reference to old batch
Batch oldBatch = oldJournalEntry.BatchModule.Current;
// After oldBatch is inserted
if (oldBatch != null && e.Operation == PXDBOperation.Insert && e.TranStatus == PXTranStatus.Completed)
{
// Create new Journal Entry Graph
JournalEntry newJournalEntry = PXGraph.CreateInstance<JournalEntry>();
// Create new batch
Batch newBatch = new Batch();
// Set new batch properties here and insert it
newJournalEntry.BatchModule.Insert(newBatch);
// Iterate on old tran from old batch
foreach (GLTran oldTran in oldJournalEntry.GLTranModuleBatNbr.Select())
{
// Create new tran
GLTran newTran = new GLTran();
// Set new tran properties here and insert it
newJournalEntry.GLTranModuleBatNbr.Insert(newTran);
}
// Save new journal
newJournalEntry.Save.Press();
}
});
};
// Add hook to intercept Journal Entry Graph
PXGraph.InstanceCreated.AddHandler<JournalEntry>(instanceCreatedHandler);
// Call base method to release document
// Your hook will be called after this action in the context of a PXLongOperation
return baseMethod(adapter);
}
#endregion
}
}
1 回答
我为CashSale制作了这个例子 . 我相信它足够通用,你也可以将它应用到其他场景中 .
在ARCashSaleEntry上创建图表扩展并覆盖Release操作:
这是图扩展的代码,解释在代码注释中: