Exemplo n.º 1
0
        public GeneralLedgerEntry GetClosingEntry(AccountIsDeactivated accountIsDeactivated,
                                                  EquityAccount retainedEarningsAccount, LocalDateTime closedOn,
                                                  GeneralLedgerEntryIdentifier closingGeneralLedgerEntryIdentifier)
        {
            var entry = new GeneralLedgerEntry(closingGeneralLedgerEntryIdentifier,
                                               new GeneralLedgerEntryNumber("jec", int.Parse(_accountingPeriod.ToString())), _accountingPeriod,
                                               closedOn);

            foreach (var account in _current.Where(x => x.Balance != Money.Zero)
                     .OrderBy(x => x.AccountNumber.ToInt32()))
            {
                switch (account)
                {
                case IncomeAccount: {
                    if (account.Balance > Money.Zero)
                    {
                        entry.ApplyDebit(new(account.AccountNumber, account.Balance), IgnoreInactiveAccount);
                    }
                    else
                    {
                        entry.ApplyCredit(new(account.AccountNumber, -account.Balance), IgnoreInactiveAccount);
                    }

                    continue;
                }

                case ExpenseAccount:
                    if (account.Balance > Money.Zero)
                    {
                        entry.ApplyCredit(new(account.AccountNumber, account.Balance), IgnoreInactiveAccount);
                    }
                    else
                    {
                        entry.ApplyDebit(new(account.AccountNumber, -account.Balance), IgnoreInactiveAccount);
                    }

                    continue;

                default:
                    continue;
                }
            }

            var retainedEarnings = entry.Debits.Select(x => x.Amount).Sum() -
                                   entry.Credits.Select(x => x.Amount).Sum();

            if (retainedEarnings < Money.Zero)
            {
                entry.ApplyDebit(new(retainedEarningsAccount.AccountNumber, -retainedEarnings), accountIsDeactivated);
            }
            else if (retainedEarnings > Money.Zero)
            {
                entry.ApplyCredit(new(retainedEarningsAccount.AccountNumber, retainedEarnings), accountIsDeactivated);
            }

            entry.Post();

            return(entry);
        }
Exemplo n.º 2
0
            public GeneralLedgerEntry GetClosingEntry(ChartOfAccounts chartOfAccounts,
                                                      AccountNumber retainedEarningsAccountNumber, DateTimeOffset closedOn,
                                                      GeneralLedgerEntryIdentifier closingGeneralLedgerEntryIdentifier)
            {
                var entry = new GeneralLedgerEntry(closingGeneralLedgerEntryIdentifier,
                                                   new GeneralLedgerEntryNumber("jec", int.Parse(_period.ToString())), _period, closedOn);

                foreach (var(accountNumber, amount) in _income)
                {
                    if (amount == Money.Zero)
                    {
                        continue;
                    }

                    if (amount > Money.Zero)
                    {
                        entry.ApplyCredit(new Credit(accountNumber, amount), chartOfAccounts);
                    }
                    else
                    {
                        entry.ApplyDebit(new Debit(accountNumber, -amount), chartOfAccounts);
                    }
                }

                foreach (var(accountNumber, amount) in _expenses)
                {
                    if (amount == Money.Zero)
                    {
                        continue;
                    }

                    if (amount < Money.Zero)
                    {
                        entry.ApplyCredit(new Credit(accountNumber, amount), chartOfAccounts);
                    }
                    else
                    {
                        entry.ApplyDebit(new Debit(accountNumber, -amount), chartOfAccounts);
                    }
                }

                var retainedEarnings = entry.Debits.Select(x => x.Amount).Sum() -
                                       entry.Credits.Select(x => x.Amount).Sum();

                if (retainedEarnings < Money.Zero)
                {
                    entry.ApplyDebit(new Debit(retainedEarningsAccountNumber, -retainedEarnings), chartOfAccounts);
                }
                else if (retainedEarnings > Money.Zero)
                {
                    entry.ApplyCredit(new Credit(retainedEarningsAccountNumber, retainedEarnings), chartOfAccounts);
                }

                entry.Post();

                return(entry);
            }