protected virtual IEnumerable viewArticle(PXAdapter adapter) { if (BudgetArticles.Current != null) { GLBudgetEntry graph = PXGraph.CreateInstance <GLBudgetEntry>(); graph.Filter.Current.BranchID = BudgetArticles.Current.BranchID; graph.Filter.Current.LedgerID = BudgetArticles.Current.LedgerID; graph.Filter.Current.FinYear = BudgetArticles.Current.FinYear; throw new PXRedirectRequiredException(graph, "View Budget"); } return(adapter.Get()); }
private static ProcessingResult ValidateFinPeriods(GLBudgetEntry graph, IEnumerable <GLBudgetLineDetail> records) { ProcessingResult generalResult = new ProcessingResult(); var recordsByPeriod = records.GroupBy(record => record.FinPeriodID); foreach (var recordsByPeriodGroup in recordsByPeriod) { string finPeriodID = recordsByPeriodGroup.Key; int?[] orgnizationIDs = recordsByPeriodGroup.GroupBy(t => PXAccess.GetParentOrganizationID(t.BranchID)) .Select(g => g.Key) .ToArray(); ICollection <OrganizationFinPeriod> finPeriods = PXSelect <OrganizationFinPeriod, Where <OrganizationFinPeriod.organizationID, In <Required <OrganizationFinPeriod.organizationID> >, And <OrganizationFinPeriod.finPeriodID, Equal <Required <OrganizationFinPeriod.finPeriodID> > > > > .Select(graph, orgnizationIDs, finPeriodID) .RowCast <OrganizationFinPeriod>() .ToArray(); if (finPeriods.Count != orgnizationIDs.Length) { string[] organizationCDs = orgnizationIDs.Except(finPeriods.Select(period => period.OrganizationID)) .Select(PXAccess.GetOrganizationCD) .ToArray(); generalResult.AddErrorMessage(Messages.FinPeriodDoesNotExistForCompanies, FinPeriodIDFormattingAttribute.FormatForError(finPeriodID), organizationCDs.JoinIntoStringForMessageNoQuotes(20)); } foreach (OrganizationFinPeriod finPeriod in finPeriods) { ProcessingResult result = new ProcessingResult(); if (finPeriod.Status == FinPeriod.status.Locked) { result.AddErrorMessage(Messages.FinPeriodIsLockedInCompany, FinPeriodIDFormattingAttribute.FormatForError(finPeriod.FinPeriodID), PXAccess.GetOrganizationCD(finPeriod.OrganizationID)); } generalResult.Aggregate(result); if (generalResult.Messages.Count > 20) { return(generalResult); } } } return(generalResult); }
protected virtual IEnumerable editDetail(PXAdapter adapter) { if (BudgetArticles.Current != null) { GLBudgetEntry graph = PXGraph.CreateInstance <GLBudgetEntry>(); graph.Filter.Current.BranchID = BudgetArticles.Current.BranchID; graph.Filter.Current.LedgerID = BudgetArticles.Current.LedgerID; graph.Filter.Current.FinYear = BudgetArticles.Current.FinYear; throw new PXRedirectRequiredException(graph, true, "View Budget") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } return(adapter.Get()); }
public static void Approve(List <GLBudgetLine> list) { bool anyFailed = false; GLBudgetEntry graph = PXGraph.CreateInstance <GLBudgetEntry>(); graph.Views.Caches.Add(typeof(AccountHistory)); for (int i = 0; i < list.Count; i++) { try { GLBudgetLine article = list[i]; Ledger ledger = PXSelect <Ledger, Where <Ledger.ledgerID, Equal <Required <Ledger.ledgerID> > > > .Select(graph, article.LedgerID); if (article.AllocatedAmount != article.Amount) { PXProcessing <GLBudgetLine> .SetError(i, Messages.BudgetArticleIsNotAllocatedProperly); anyFailed = true; continue; } Account acct = PXSelect <Account, Where <Account.accountID, Equal <Required <Account.accountID> > > > .Select(graph, article.AccountID); foreach (GLBudgetLineDetail alloc in PXSelect <GLBudgetLineDetail, Where <GLBudgetLineDetail.ledgerID, Equal <Required <GLBudgetLineDetail.ledgerID> >, And <GLBudgetLineDetail.branchID, Equal <Required <GLBudgetLineDetail.branchID> >, And <GLBudgetLineDetail.finYear, Equal <Required <GLBudgetLineDetail.finYear> >, And <GLBudgetLineDetail.accountID, Equal <Required <GLBudgetLineDetail.accountID> >, And <GLBudgetLineDetail.subID, Equal <Required <GLBudgetLineDetail.subID> > > > > > > > .Select(graph, article.LedgerID, article.BranchID, article.FinYear, article.AccountID, article.SubID)) { decimal delta = (decimal)((alloc.Amount ?? 0m) - (alloc.ReleasedAmount ?? 0m)); if (delta != 0m) { AccountHistory accthist = new AccountHistory { BranchID = alloc.BranchID, AccountID = alloc.AccountID, FinPeriodID = alloc.FinPeriodID, LedgerID = alloc.LedgerID, SubID = alloc.SubID, CuryID = null, BalanceType = ledger.BalanceType }; accthist = (AccountHistory)graph.Caches[typeof(AccountHistory)].Insert(accthist); if (accthist == null) { PXProcessing <GLBudgetLine> .SetError(i, Messages.BudgetApproveUnexpectedError); anyFailed = true; } else { accthist.YtdBalance += delta; accthist.CuryFinYtdBalance = accthist.YtdBalance; accthist.TranYtdBalance += delta; accthist.CuryTranYtdBalance = accthist.TranYtdBalance; if (acct.Type == AccountType.Asset || acct.Type == AccountType.Expense) { accthist.FinPtdDebit += delta; accthist.CuryFinPtdDebit = accthist.FinPtdDebit; accthist.TranPtdDebit += delta; accthist.CuryTranPtdDebit = accthist.TranPtdDebit; //accthist.FinPtdCredit += 0; accthist.CuryFinPtdCredit = accthist.FinPtdCredit; //accthist.TranPtdCredit += 0; accthist.CuryTranPtdCredit = accthist.TranPtdCredit; } else { accthist.FinPtdCredit += delta; accthist.CuryFinPtdCredit = accthist.FinPtdCredit; accthist.TranPtdCredit += delta; accthist.CuryTranPtdCredit = accthist.TranPtdCredit; //accthist.FinPtdDebit += 0; accthist.CuryFinPtdDebit = accthist.FinPtdDebit; //accthist.TranPtdDebit += 0; accthist.CuryTranPtdDebit = accthist.TranPtdDebit; } } } alloc.ReleasedAmount = alloc.Amount; graph.Caches[typeof(GLBudgetLineDetail)].Update(alloc); } article.ReleasedAmount = article.Amount; article.Released = true; graph.Caches[typeof(GLBudgetLine)].Update(article); PXProcessing <GLBudgetLine> .SetInfo(i, ActionsMessages.RecordProcessed); } catch (Exception e) { PXProcessing <GLBudgetLine> .SetError(i, e.Message); throw; } } graph.Save.Press(); if (anyFailed) { throw new PXException(Messages.BudgetItemsApprovalFailure); } }
public static void Approve(List <GLBudgetLine> list) { bool anyFailed = false; bool lineFailed = false; GLBudgetEntry graph = PXGraph.CreateInstance <GLBudgetEntry>(); graph.Views.Caches.Add(typeof(AccountHistory)); PXCache <AccountHistory> cacheAccountHistory = graph.Caches <AccountHistory>(); PXCache <GLBudgetLine> cacheGLBudgetLine = graph.Caches <GLBudgetLine>(); PXCache <GLBudgetLineDetail> cacheGLBudgetLineDetail = graph.Caches <GLBudgetLineDetail>(); for (int i = 0; i < list.Count; i++) { try { lineFailed = false; GLBudgetLine article = list[i]; Ledger ledger = PXSelect <Ledger, Where <Ledger.ledgerID, Equal <Required <Ledger.ledgerID> > > > .Select(graph, article.LedgerID); if (article.AllocatedAmount != article.Amount) { PXProcessing <GLBudgetLine> .SetError(i, Messages.BudgetArticleIsNotAllocatedProperly); anyFailed = true; continue; } Account acct = PXSelect <Account, Where <Account.accountID, Equal <Required <Account.accountID> > > > .Select(graph, article.AccountID); PXResultset <GLBudgetLineDetail> allocations = PXSelect < GLBudgetLineDetail, Where <GLBudgetLineDetail.ledgerID, Equal <Required <GLBudgetLineDetail.ledgerID> >, And <GLBudgetLineDetail.branchID, Equal <Required <GLBudgetLineDetail.branchID> >, And <GLBudgetLineDetail.finYear, Equal <Required <GLBudgetLineDetail.finYear> >, And <GLBudgetLineDetail.groupID, Equal <Required <GLBudgetLineDetail.groupID> > > > > > > .Select(graph, article.LedgerID, article.BranchID, article.FinYear, article.GroupID); ProcessingResult validateFinPeriodsResult = ValidateFinPeriods(graph, allocations.Select(record => (GLBudgetLineDetail)record)); if (!validateFinPeriodsResult.IsSuccess) { PXProcessing <GLBudgetLine> .SetError(i, validateFinPeriodsResult.GetGeneralMessage()); anyFailed = true; continue; } List <AccountHistory> listHistory = new List <AccountHistory>(); foreach (GLBudgetLineDetail alloc in allocations) { decimal delta = (decimal)((alloc.Amount ?? 0m) - (alloc.ReleasedAmount ?? 0m)); if (delta != 0m) { AccountHistory accthist = new AccountHistory { BranchID = alloc.BranchID, AccountID = alloc.AccountID, FinPeriodID = alloc.FinPeriodID, LedgerID = alloc.LedgerID, SubID = alloc.SubID, CuryID = null, BalanceType = ledger.BalanceType }; accthist = (AccountHistory)cacheAccountHistory.Insert(accthist); if (accthist == null) { PXProcessing <GLBudgetLine> .SetError(i, Messages.BudgetApproveUnexpectedError); lineFailed = true; break; } else { accthist.YtdBalance += delta; accthist.CuryFinYtdBalance = accthist.YtdBalance; accthist.TranYtdBalance += delta; accthist.CuryTranYtdBalance = accthist.TranYtdBalance; if (acct.Type == AccountType.Asset || acct.Type == AccountType.Expense) { accthist.FinPtdDebit += delta; accthist.CuryFinPtdDebit = accthist.FinPtdDebit; accthist.TranPtdDebit += delta; accthist.CuryTranPtdDebit = accthist.TranPtdDebit; //accthist.FinPtdCredit += 0; accthist.CuryFinPtdCredit = accthist.FinPtdCredit; //accthist.TranPtdCredit += 0; accthist.CuryTranPtdCredit = accthist.TranPtdCredit; } else { accthist.FinPtdCredit += delta; accthist.CuryFinPtdCredit = accthist.FinPtdCredit; accthist.TranPtdCredit += delta; accthist.CuryTranPtdCredit = accthist.TranPtdCredit; //accthist.FinPtdDebit += 0; accthist.CuryFinPtdDebit = accthist.FinPtdDebit; //accthist.TranPtdDebit += 0; accthist.CuryTranPtdDebit = accthist.TranPtdDebit; } listHistory.Add(accthist); } } } anyFailed = (anyFailed || lineFailed); if (lineFailed) { foreach (AccountHistory accthist in listHistory) { cacheAccountHistory.Remove(accthist); } continue; } foreach (GLBudgetLineDetail alloc in allocations) { alloc.ReleasedAmount = alloc.Amount; cacheGLBudgetLineDetail.Update(alloc); } article.ReleasedAmount = article.Amount; article.Released = true; article.WasReleased = true; cacheGLBudgetLine.Update(article); PXProcessing <GLBudgetLine> .SetInfo(i, ActionsMessages.RecordProcessed); } catch (Exception e) { PXProcessing <GLBudgetLine> .SetError(i, e.Message); throw; } } graph.Save.Press(); if (anyFailed) { throw new PXException(Messages.BudgetItemsApprovalFailure); } }