protected virtual void EPExpenseClaimDetails_RowPersisted(PXCache cache, PXRowPersistedEventArgs e) { EPExpenseClaimDetails row = (EPExpenseClaimDetails)e.Row; if (!string.IsNullOrEmpty(row.RefNbr) && e.TranStatus == PXTranStatus.Completed) { ExpenseClaimEntry expenseClaimEntry = CreateInstance <ExpenseClaimEntry>(); expenseClaimEntry.ExpenseClaim.Current = expenseClaimEntry.ExpenseClaim.Search <EPExpenseClaim.refNbr>(row.RefNbr); if (expenseClaimEntry.ExpenseClaim.Current != null) { expenseClaimEntry.currencyinfo.Current = expenseClaimEntry.currencyinfo.Search <EPExpenseClaim.curyInfoID>(expenseClaimEntry.ExpenseClaim.Current.CuryInfoID); expenseClaimEntry.SubmitDetail(row); expenseClaimEntry.Actions.PressSave(); Cancel.Press(); } } }
private static void ClaimDetail(List <EPExpenseClaimDetails> details) { PXSetup <EPSetup> epsetup = new PXSetup <EPSetup>(PXGraph.CreateInstance(typeof(ExpenseClaimDetailEntry))); bool enabledApprovalReceipt = PXAccess.FeatureInstalled <FeaturesSet.approvalWorkflow>() && epsetup.Current.ClaimDetailsAssignmentMapID != null; bool isError = false; bool notAllApproved = false; bool emptyClaim = true; var List = details.Where(item => string.IsNullOrEmpty(item.RefNbr)).OrderBy(detail => detail.ClaimDetailID).GroupBy( item => new { item.EmployeeID, item.BranchID, item.CustomerID, item.CustomerLocationID } , (key, item) => new { employee = key.EmployeeID, branch = key.BranchID, customer = key.CustomerID, customerLocation = key.CustomerLocationID, details = item } ); List <EPExpenseClaim> result = new List <EPExpenseClaim>(); foreach (var item in List) { isError = false; notAllApproved = false; emptyClaim = true; using (PXTransactionScope ts = new PXTransactionScope()) { ExpenseClaimEntry expenseClaimEntry = CreateInstance <ExpenseClaimEntry>(); EPExpenseClaim expenseClaim = (EPExpenseClaim)expenseClaimEntry.ExpenseClaim.Cache.CreateInstance(); expenseClaim.EmployeeID = item.employee; expenseClaim.BranchID = item.branch; expenseClaim.CustomerID = item.customer; expenseClaim.DocDesc = EP.Messages.SubmittedReceipt; expenseClaim = expenseClaimEntry.ExpenseClaim.Update(expenseClaim); expenseClaim.CustomerLocationID = item.customerLocation; foreach (EPExpenseClaimDetails detail in item.details) { PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(detail); if (detail.Approved ?? false) { try { expenseClaimEntry.SubmitDetail(detail); PXProcessing <EPExpenseClaimDetails> .SetProcessed(); emptyClaim = false; } catch (Exception ex) { PXProcessing <EPExpenseClaimDetails> .SetError(ex); isError = true; } } else { PXProcessing.SetError(enabledApprovalReceipt ? Messages.ReceiptNotApproved : Messages.ReceiptTakenOffHold); notAllApproved = true; } } if (!emptyClaim) { try { expenseClaimEntry.Actions.PressSave(); result.Add(expenseClaim); } catch (Exception ex) { foreach (EPExpenseClaimDetails detail in item.details) { PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(detail); PXProcessing <EPExpenseClaimDetails> .SetError(ex); } isError = true; } } if (!isError) { ts.Complete(); } } } if (!isError && !notAllApproved) { if (result.Count == 1) { ExpenseClaimEntry expenseClaimEntry = CreateInstance <ExpenseClaimEntry>(); PXRedirectHelper.TryRedirect(expenseClaimEntry, result[0], PXRedirectHelper.WindowMode.InlineWindow); } } else { PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(null); throw new PXException(Messages.ErrorProcessingReceipts); } }