public Closing CloseObject(Closing closing, IAccountService _accountService, IGeneralLedgerJournalService _generalLedgerJournalService, IValidCombService _validCombService) { if (_validator.ValidCloseObject(closing, this)) { // Count ValidComb for each leaf account IList <Account> leafAccounts = _accountService.GetLeafObjects(); foreach (var leaf in leafAccounts) { DateTime EndDate = closing.EndDatePeriod.AddDays(1); IList <GeneralLedgerJournal> ledgers = _generalLedgerJournalService.GetQueryable() .Where(x => x.AccountId == leaf.Id && x.TransactionDate >= closing.BeginningPeriod && x.TransactionDate < EndDate) .ToList(); decimal totalAmountInLedgers = 0; foreach (var ledger in ledgers) { Account account = _accountService.GetObjectById(ledger.AccountId); if ((ledger.Status == Constant.GeneralLedgerStatus.Debit && (account.Group == Constant.AccountGroup.Asset || account.Group == Constant.AccountGroup.Expense)) || (ledger.Status == Constant.GeneralLedgerStatus.Credit && (account.Group == Constant.AccountGroup.Liability || account.Group == Constant.AccountGroup.Equity || account.Group == Constant.AccountGroup.Revenue))) { totalAmountInLedgers += ledger.Amount; } else { totalAmountInLedgers -= ledger.Amount; } } ValidComb validComb = _validCombService.FindOrCreateObjectByAccountAndClosing(leaf.Id, closing.Id); validComb.Amount = totalAmountInLedgers; _validCombService.UpdateObject(validComb, _accountService, this); } var groupNodeAccounts = _accountService.GetQueryable().Where(x => !x.IsLeaf).OrderByDescending(x => x.Level); foreach (var groupNode in groupNodeAccounts) { FillValidComb(groupNode, closing, _accountService, _validCombService); } _repository.CloseObject(closing); } return(closing); }
public Closing OpenObject(Closing closing, IAccountService _accountService, IValidCombService _validCombService) { if (_validator.ValidOpenObject(closing)) { IList <Account> allAccounts = _accountService.GetAll(); foreach (var account in allAccounts) { ValidComb validComb = _validCombService.FindOrCreateObjectByAccountAndClosing(account.Id, closing.Id); validComb.Amount = 0; _validCombService.UpdateObject(validComb, _accountService, this); } } return(_repository.OpenObject(closing)); }