Exemplo n.º 1
0
        public Task <IPostingJournalResult> ApplyPostingJournalAsync(IPostingJournal postingJournal, IPostingWarningCalculator postingWarningCalculator)
        {
            NullGuard.NotNull(postingJournal, nameof(postingJournal))
            .NotNull(postingWarningCalculator, nameof(postingWarningCalculator));

            return(ExecuteAsync(async() =>
            {
                IPostingLineCollection postingLineCollection = new PostingLineCollection();
                foreach (IGrouping <int, IPostingLine> group in postingJournal.PostingLineCollection.GroupBy(postingLine => postingLine.Accounting.Number))
                {
                    using PostingLineModelHandler postingLineModelHandler = new PostingLineModelHandler(DbContext, AccountingModelConverter.Create(), _eventPublisher, DateTime.MinValue, DateTime.Today, true, true, applyingPostingLines: true);

                    AccountingIdentificationState accountingIdentificationState = new AccountingIdentificationState(group.Key);

                    IPostingLine[] createdPostingLineCollection = (await postingLineModelHandler.CreateAsync(group.OrderBy(m => m.PostingDate).ThenBy(m => m.SortOrder), accountingIdentificationState, true)).ToArray();

                    IPostingLine[] updatedPostingLineCollection = (await postingLineModelHandler.UpdateAsync(createdPostingLineCollection.OrderBy(m => m.PostingDate.Date).ThenBy(m => m.SortOrder), accountingIdentificationState)).ToArray();
                    foreach (IPostingLine postingLine in updatedPostingLineCollection)
                    {
                        IPostingLine[] affectedPostingCollection = (await postingLineModelHandler.ReadAsync(m => m.AccountingIdentifier == accountingIdentificationState.AccountingIdentifier && (m.PostingDate == postingLine.PostingDate && m.PostingLineIdentifier > postingLine.SortOrder || m.PostingDate > postingLine.PostingDate), prepareReadState: accountingIdentificationState)).ToArray();
                        foreach (IPostingLine affectedPostingLine in affectedPostingCollection.Where(m => updatedPostingLineCollection.Contains(m) == false))
                        {
                            await postingLineModelHandler.UpdateAsync(affectedPostingLine, accountingIdentificationState);
                        }
                    }

                    postingLineCollection.Add(updatedPostingLineCollection);
                }

                return (IPostingJournalResult) new PostingJournalResult(postingLineCollection, postingWarningCalculator);
            },
                                MethodBase.GetCurrentMethod()));
        }
Exemplo n.º 2
0
        public Task <IPostingLineCollection> GetPostingLinesAsync(int accountingNumber, DateTime statusDate, int numberOfPostingLines)
        {
            return(ExecuteAsync(async() =>
            {
                using PostingLineModelHandler postingLineModelHandler = new PostingLineModelHandler(DbContext, AccountingModelConverter.Create(), _eventPublisher, DateTime.MinValue, statusDate, true, true, numberOfPostingLines);

                IPostingLineCollection postingLineCollection = new PostingLineCollection
                {
                    await postingLineModelHandler.ReadAsync(accountingNumber)
                };

                return postingLineCollection;
            },
                                MethodBase.GetCurrentMethod()));
        }
        public IPostingJournal ToDomain(IAccountingRepository accountingRepository)
        {
            NullGuard.NotNull(accountingRepository, nameof(accountingRepository));

            IAccounting accounting = GetAccountingAsync(accountingRepository).GetAwaiter().GetResult();

            IPostingLineCollection postingLineCollection = new PostingLineCollection
            {
                PostingLineCollection.AsParallel()
                .Select(applyPostingLineCommand => applyPostingLineCommand.ToDomain(accounting))
                .OrderBy(postingLine => postingLine.PostingDate)
                .ThenBy(postingLine => postingLine.SortOrder)
                .ToArray()
            };

            return(new PostingJournal(postingLineCollection));
        }
Exemplo n.º 4
0
        private async Task <IPostingJournal> BuildPostingJournalAsync(IAccountingRepository accountingRepository)
        {
            NullGuard.NotNull(accountingRepository, nameof(accountingRepository));

            IAccounting accounting = await accountingRepository.GetAccountingAsync(WithExistingAccountingNumber(), DateTime.Today);

            IAccount       primaryAccount       = accounting.AccountCollection.Single(account => string.CompareOrdinal(account.AccountNumber, WithExistingAccountNumberForAccount()) == 0);
            IBudgetAccount primaryBudgetAccount = accounting.BudgetAccountCollection.Single(budgetAccount => string.CompareOrdinal(budgetAccount.AccountNumber, WithExistingAccountNumberForBudgetAccount()) == 0);

            IPostingLineCollection postingLineCollection = new PostingLineCollection
            {
                new PostingLine(Guid.NewGuid(), DateTime.Today, null, primaryAccount, "Testing apply posting journal", primaryBudgetAccount, 25000M, 0M, null, 1),
                new PostingLine(Guid.NewGuid(), DateTime.Today, null, primaryAccount, "Testing apply posting journal", primaryBudgetAccount, 0M, 25000M, null, 2)
            };

            return(new PostingJournal(postingLineCollection));
        }