public static void Run(PMAllocator graph, PMProject item, DateTime?date, DateTime?fromDate, DateTime?toDate) { PXSelectBase <PMTask> select = new PXSelect <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.allocationID, IsNotNull, And <PMTask.isActive, Equal <True> > > > >(graph); List <PMTask> tasks = new List <PMTask>(); foreach (PMTask pmTask in select.Select(item.ContractID)) { tasks.Add(pmTask); } graph.Clear(); graph.FilterStartDate = fromDate; graph.FilterEndDate = toDate; graph.PostingDate = date; graph.Execute(tasks); if (graph.Document.Current != null) { graph.Actions.PressSave(); PMSetup setup = PXSelect <PMSetup> .Select(graph); PMRegister doc = graph.Caches[typeof(PMRegister)].Current as PMRegister; if (doc != null && setup.AutoReleaseAllocation == true) { RegisterRelease.Release(doc); } } else { throw new PXSetPropertyException(Warnings.NothingToAllocate, PXErrorLevel.RowWarning); } }
protected virtual void AutoAllocateTasks(List <PMTask> tasks) { PMSetup setup = PXSelect <PMSetup> .Select(Base); bool autoreleaseAllocation = setup.AutoReleaseAllocation == true; PMAllocator allocator = PXGraph.CreateInstance <PMAllocator>(); allocator.Clear(); allocator.TimeStamp = Base.TimeStamp; allocator.Execute(tasks); allocator.Actions.PressSave(); if (allocator.Document.Current != null && autoreleaseAllocation) { List <PMRegister> list = new List <PMRegister>(); list.Add(allocator.Document.Current); List <ProcessInfo <Batch> > batchList; bool releaseSuccess = RegisterRelease.ReleaseWithoutPost(list, false, out batchList); if (!releaseSuccess) { throw new PXException(PM.Messages.AutoReleaseFailed); } foreach (var item in batchList) { Base.created.AddRange(item.Batches); } } }
public static void Run(PMAllocator graph, PMTask item, DateTime?date, DateTime?fromDate, DateTime?toDate) { graph.Clear(); graph.FilterStartDate = fromDate; graph.FilterEndDate = toDate; graph.Execute(item); if (graph.Document.Current != null) { graph.Actions.PressSave(); PMSetup setup = PXSelect <PMSetup> .Select(graph); PMRegister doc = graph.Caches[typeof(PMRegister)].Current as PMRegister; if (doc != null && setup.AutoReleaseAllocation == true) { RegisterRelease.Release(doc); } } else { throw new PXSetPropertyException(Warnings.NothingToAllocate, PXErrorLevel.RowWarning); } }
public static bool ReleaseWithoutPost(List <PMRegister> list, bool isMassProcess, out List <ProcessInfo <Batch> > infoList) { bool failed = false; infoList = new List <ProcessInfo <Batch> >(); if (!list.Any()) { return(!failed); } RegisterReleaseProcess rg = PXGraph.CreateInstance <RegisterReleaseProcess>(); JournalEntry je = PXGraph.CreateInstance <JournalEntry>(); PMAllocator allocator = PXGraph.CreateInstance <PMAllocator>(); //Task may be IsActive=False - it may be completed. User cannot create transactions with this //TaskID. But the system has to process the given task - hence override the FieldVerification in the Selector. je.FieldVerifying.AddHandler <GLTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); je.FieldVerifying.AddHandler <GLTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); for (int i = 0; i < list.Count; i++) { ProcessInfo <Batch> info = new ProcessInfo <Batch>(i); infoList.Add(info); PMRegister doc = list[i]; try { List <PMTask> allocTasks; info.Batches.AddRange(rg.Release(je, doc, out allocTasks)); allocator.Clear(); allocator.TimeStamp = je.TimeStamp; if (allocTasks.Count > 0) { allocator.Execute(allocTasks); allocator.Actions.PressSave(); } if (allocator.Document.Current != null && rg.AutoReleaseAllocation) { List <PMTask> allocTasks2; info.Batches.AddRange(rg.Release(je, allocator.Document.Current, out allocTasks2)); } if (isMassProcess) { PXProcessing <PMRegister> .SetInfo(i, ActionsMessages.RecordProcessed); } } catch (Exception e) { if (isMassProcess) { PXProcessing <PMRegister> .SetError(i, e is PXOuterException?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message); failed = true; } else { throw new PXMassProcessException(i, e); } } } return(!failed); }