Example #1
0
        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;
            });
        }
Example #2
0
        public void TransferEntry(GeneralLedgerEntry generalLedgerEntry)
        {
            generalLedgerEntry.MustBeInBalance();
            generalLedgerEntry.MustBePosted();

            ProfitAndLoss.Transfer(generalLedgerEntry);
            TrialBalance.Transfer(generalLedgerEntry);
            TrialBalance.MustBeInBalance();
            _generalLedgerEntryIdentifiers.Remove(generalLedgerEntry.Identifier);
        }
Example #3
0
        public GeneralLedgerEntry Complete()
        {
            if (_generalLedgerEntryIdentifiers.Count > 0)
            {
                throw new PeriodContainsUntransferredEntriesException(_accountingPeriod,
                                                                      _generalLedgerEntryIdentifiers.ToArray());
            }

            TrialBalance.MustBeInBalance();

            return(ProfitAndLoss.GetClosingEntry(_accountIsDeactivated, _retainedEarningsAccount,
                                                 _closingOn, _closingGeneralLedgerEntryIdentifier));
        }
Example #4
0
 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);
 }