public async ValueTask Handle(AccountingPeriodClosing @event, CancellationToken cancellationToken)
        {
            var generalLedgerEntryIdentifiers =
                Array.ConvertAll(@event.GeneralLedgerEntryIds, id => new GeneralLedgerEntryIdentifier(id));

            var chartOfAccounts = await _chartOfAccounts.Get(cancellationToken);

            var accountingPeriodClosingProcess = new AccountingPeriodClosingProcess(
                chartOfAccounts, AccountingPeriod.Parse(@event.Period), Time.Parse.LocalDateTime(@event.ClosingOn),
                generalLedgerEntryIdentifiers, new GeneralLedgerEntryIdentifier(@event.ClosingGeneralLedgerEntryId),
                (EquityAccount)chartOfAccounts[new AccountNumber(@event.RetainedEarningsAccountNumber)],
                _accountIsDeactivated);

            foreach (var id in @event.GeneralLedgerEntryIds)
            {
                var generalLedgerEntry =
                    await _generalLedgerEntries.Get(new GeneralLedgerEntryIdentifier(id), cancellationToken);

                accountingPeriodClosingProcess.TransferEntry(generalLedgerEntry);
            }

            var generalLedger = await _generalLedger.Get(cancellationToken);

            generalLedger.CompleteClosingPeriod(generalLedgerEntryIdentifiers,
                                                accountingPeriodClosingProcess.Complete(), accountingPeriodClosingProcess.TrialBalance);
        }
Exemplo n.º 2
0
        public async ValueTask Handle(BeginClosingAccountingPeriod command,
                                      CancellationToken cancellationToken = default)
        {
            var generalLedger = await _generalLedger.Get(cancellationToken);

            var chartOfAccounts = await _chartOfAccounts.Get(cancellationToken);

            generalLedger.BeginClosingPeriod(
                (EquityAccount)chartOfAccounts[new AccountNumber(command.RetainedEarningsAccountNumber)],
                new GeneralLedgerEntryIdentifier(command.ClosingGeneralLedgerEntryId),
                command.GeneralLedgerEntryIds.Select(id => new GeneralLedgerEntryIdentifier(id)).ToArray(),
                LocalDateTime.FromDateTime(command.ClosingOn.DateTime));
        }
Exemplo n.º 3
0
        public async ValueTask Handle(AccountingPeriodClosing @event, CancellationToken cancellationToken)
        {
            var retainedEarningsAccountNumber = new AccountNumber(@event.RetainedEarningsAccountNumber);

            AccountType.OfAccountNumber(retainedEarningsAccountNumber).MustBe(AccountType.Equity);
            var generalLedger = await _generalLedger.Get(cancellationToken);

            foreach (var id in @event.GeneralLedgerEntryIds)
            {
                var generalLedgerEntry =
                    await _generalLedgerEntries.Get(new GeneralLedgerEntryIdentifier(id), cancellationToken);

                generalLedger.TransferEntry(generalLedgerEntry);
            }

            var chartOfAccounts = await _chartOfAccounts.Get(cancellationToken);

            generalLedger.CompleteClosingPeriod(chartOfAccounts, retainedEarningsAccountNumber);
        }
        public async ValueTask Handle(PostGeneralLedgerEntry command, CancellationToken cancellationToken = default)
        {
            if (command.BusinessTransaction == null)
            {
                throw new InvalidOperationException();
            }

            var generalLedger = await _generalLedger.Get(cancellationToken);

            var chartOfAccounts = await _chartOfAccounts.Get(cancellationToken);

            var entry = generalLedger.Create(new GeneralLedgerEntryIdentifier(command.GeneralLedgerEntryId),
                                             command.BusinessTransaction.ReferenceNumber, command.CreatedOn);

            command.BusinessTransaction.Apply(entry, chartOfAccounts);

            entry.Post();

            _generalLedgerEntries.Add(entry);
        }
Exemplo n.º 5
0
        public async ValueTask Handle(RenameAccount command, CancellationToken cancellationToken = default)
        {
            var chart = await _chartOfAccounts.Get(cancellationToken);

            chart.RenameAccount(new AccountNumber(command.AccountNumber), new AccountName(command.NewAccountName !));
        }