private GeneralLedger() { _untransferredEntryIdentifiers = new List <GeneralLedgerEntryIdentifier>(); _entryIdentifiers = new List <GeneralLedgerEntryIdentifier>(); _trialBalance = TrialBalance.None; _closingOn = default; _profitAndLoss = null !; Register <GeneralLedgerOpened>(e => _period = Period.Open(e.OpenedOn)); Register <AccountingPeriodClosing>(e => { _periodClosing = true; _period = Period.Parse(e.Period); _profitAndLoss = new ProfitAndLoss(_period); _entryIdentifiers.AddRange(Array.ConvertAll(e.GeneralLedgerEntryIds, identifier => new GeneralLedgerEntryIdentifier(identifier))); _untransferredEntryIdentifiers.AddRange(_entryIdentifiers); _closingOn = e.ClosingOn; _closingGeneralLedgerEntryIdentifier = new GeneralLedgerEntryIdentifier(e.ClosingGeneralLedgerEntryId); }); Register <AccountingPeriodClosed>(e => { _untransferredEntryIdentifiers.Clear(); _entryIdentifiers.Clear(); foreach (var(accountNumber, amount) in e.Balance) { _trialBalance.Apply(new AccountNumber(accountNumber), new Money(amount)); } _period = Period.Parse(e.Period).Next(); _periodClosing = false; }); }
public AccountingPeriodClosingProcess( ChartOfAccounts chartOfAccounts, AccountingPeriod accountingPeriod, LocalDateTime closingOn, GeneralLedgerEntryIdentifier[] generalLedgerEntryIdentifiers, GeneralLedgerEntryIdentifier closingGeneralLedgerEntryIdentifier, EquityAccount retainedEarningsAccount, AccountIsDeactivated accountIsDeactivated) { _accountingPeriod = accountingPeriod; _closingOn = closingOn; _closingGeneralLedgerEntryIdentifier = closingGeneralLedgerEntryIdentifier; _retainedEarningsAccount = retainedEarningsAccount; _accountIsDeactivated = accountIsDeactivated; _generalLedgerEntryIdentifiers = new HashSet <GeneralLedgerEntryIdentifier>(generalLedgerEntryIdentifiers); TrialBalance = new TrialBalance(chartOfAccounts); ProfitAndLoss = new ProfitAndLoss(accountingPeriod, chartOfAccounts); }