public IEnumerable filteredItems() { bool found = false; foreach (EPTimeCardRow item in FilteredItems.Cache.Inserted) { found = true; yield return(item); } if (found) { yield break; } PXSelectBase <EPTimeCardRow> select = new PXSelectJoin <EPTimeCardRow, LeftJoin <EPEmployee, On <EPEmployee.bAccountID, Equal <EPTimeCard.employeeID> >, LeftJoin <EPApproval, On <EPApproval.refNoteID, Equal <EPTimeCardRow.noteID> >, LeftJoin <EPEmployeeEx, On <EPEmployeeEx.userID, Equal <EPApproval.approvedByID> > > > >, Where <EPTimeCardRow.isApproved, Equal <True>, And2 <Where <EPTimeCardRow.isReleased, NotEqual <True>, Or <EPTimeCardRow.isReleased, IsNull> >, And2 <Where <EPTimeCardRow.isHold, NotEqual <True>, Or <EPTimeCardRow.isHold, IsNull> >, And <Where <EPTimeCardRow.isRejected, NotEqual <True>, Or <EPTimeCardRow.isRejected, IsNull> > > > > >, OrderBy <Asc <EPTimeCardRow.timeCardCD, Desc <EPTimeCardRow.approveDate> > > >(this); List <string> timeCards = new List <string>(); foreach (PXResult <EPTimeCardRow, EPEmployee, EPApproval, EPEmployeeEx> res in select.Select()) { EPTimeCardRow rec = (EPTimeCardRow)res; if (!timeCards.Contains(rec.TimeCardCD)) { timeCards.Add(rec.TimeCardCD); EPEmployee employee = (EPEmployee)res[1]; EPApproval approval = (EPApproval)res; EPEmployeeEx approver = (EPEmployeeEx)res[3]; rec.EmployeeCD = employee.AcctCD; rec.EmployeeName = employee.AcctName; rec.ApproveDate = approval.ApproveDate; rec.ApprovedBy = approver.AcctCD; RecalculateTotals(rec); FilteredItems.Cache.SetStatus(rec, PXEntryStatus.Inserted); yield return(rec); } } FilteredItems.Cache.IsDirty = false; }
protected static void Approve(List <EPOwned> items, bool approve) { EntityHelper helper = new EntityHelper(new PXGraph()); var graphs = new Dictionary <Type, PXGraph>(); bool errorOccured = false; foreach (EPOwned item in items) { try { PXProcessing <EPApproval> .SetCurrentItem(item); if (item.RefNoteID == null) { throw new PXException(Messages.ApprovalRefNoteIDNull); } object row = helper.GetEntityRow(item.RefNoteID.Value, true); if (row == null) { throw new PXException(Messages.ApprovalRecordNotFound); } Type cahceType = row.GetType(); Type graphType = helper.GetPrimaryGraphType(row, false); PXGraph graph; if (!graphs.TryGetValue(graphType, out graph)) { graphs.Add(graphType, graph = PXGraph.CreateInstance(graphType)); } EPApproval approval = PXSelectReadonly <EPApproval, Where <EPApproval.approvalID, Equal <Current <EPOwned.approvalID> > > > .SelectSingleBound(graph, new object[] { item }); if (approval.Status == EPApprovalStatus.Pending) { graph.Clear(); graph.Caches[cahceType].Current = row; graph.Caches[cahceType].SetStatus(row, PXEntryStatus.Notchanged); PXAutomation.GetView(graph); string approved = typeof(EPExpenseClaim.approved).Name; if (graph.AutomationView != null) { PXAutomation.GetStep(graph, new object[] { graph.Views[graph.AutomationView].Cache.Current }, BqlCommand.CreateInstance( typeof(Select <>), graph.Views[graph.AutomationView].Cache.GetItemType()) ); } string actionName = approve ? nameof(Approve) : nameof(Reject); if (graph.Actions.Contains(actionName)) { graph.Actions[actionName].Press(); } else if (graph.AutomationView != null) { PXView view = graph.Views[graph.AutomationView]; BqlCommand select = view.BqlSelect; PXAdapter adapter = new PXAdapter(new PXView.Dummy(graph, select, new List <object> { row })); adapter.Menu = actionName; if (graph.Actions.Contains("Action")) { if (!CheckRights(graphType, cahceType)) { throw new PXException(Messages.DontHaveAppoveRights); } foreach (var i in graph.Actions["Action"].Press(adapter)) { ; } } else { throw new PXException(PXMessages.LocalizeFormatNoPrefixNLA(Messages.AutomationNotConfigured, graph)); } //PXAutomation.ApplyAction(graph, graph.Actions["Action"], "Approve", row, out rollback); } else if (graph.Caches[cahceType].Fields.Contains(approved)) { object upd = graph.Caches[cahceType].CreateCopy(row); graph.Caches[cahceType].SetValue(upd, approved, true); graph.Caches[cahceType].Update(upd); } graph.Persist(); } PXProcessing <EPApproval> .SetInfo(ActionsMessages.RecordProcessed); } catch (Exception ex) { errorOccured = true; PXProcessing <EPApproval> .SetError(ex); } } if (errorOccured) { throw new PXOperationCompletedWithErrorException(ErrorMessages.SeveralItemsFailed); } }