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()));
        }