コード例 #1
0
ファイル: ProfitAndLoss.cs プロジェクト: dmmusil/Transacto
        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);
        }
コード例 #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);
            }
コード例 #3
0
        public void TransferEntry(GeneralLedgerEntry generalLedgerEntry)
        {
            generalLedgerEntry.MustBeInBalance();
            generalLedgerEntry.MustBePosted();

            ProfitAndLoss.Transfer(generalLedgerEntry);
            TrialBalance.Transfer(generalLedgerEntry);
            TrialBalance.MustBeInBalance();
            _generalLedgerEntryIdentifiers.Remove(generalLedgerEntry.Identifier);
        }
コード例 #4
0
ファイル: ProfitAndLoss.cs プロジェクト: dmmusil/Transacto
        public void Transfer(GeneralLedgerEntry generalLedgerEntry)
        {
            foreach (var credit in generalLedgerEntry.Credits)
            {
                _current.AddOrUpdate(credit.AccountNumber, () => _chartOfAccounts[credit.AccountNumber],
                                     account => account.Credit(credit.Amount));
            }

            foreach (var debit in generalLedgerEntry.Debits)
            {
                _current.AddOrUpdate(debit.AccountNumber, () => _chartOfAccounts[debit.AccountNumber],
                                     account => account.Debit(debit.Amount));
            }
        }
コード例 #5
0
        public void TransferEntry(GeneralLedgerEntry generalLedgerEntry)
        {
            if (!_periodClosing)
            {
                throw new PeriodClosingInProcessException(_period);
            }

            generalLedgerEntry.MustBeInBalance();
            generalLedgerEntry.MustBePosted();

            _trialBalance.Transfer(generalLedgerEntry);
            _profitAndLoss.Transfer(generalLedgerEntry);
            _untransferredEntryIdentifiers.Remove(generalLedgerEntry.Identifier);
        }
コード例 #6
0
ファイル: JournalEntry.cs プロジェクト: sbochoa/Transacto
        public void Apply(GeneralLedgerEntry generalLedgerEntry, ChartOfAccounts chartOfAccounts)
        {
            foreach (var credit in Credits)
            {
                generalLedgerEntry.ApplyCredit(
                    new Credit(new AccountNumber(credit.AccountNumber), new Money(credit.Amount)), chartOfAccounts);
            }

            foreach (var debit in Debits)
            {
                generalLedgerEntry.ApplyDebit(
                    new Debit(new AccountNumber(debit.AccountNumber), new Money(debit.Amount)), chartOfAccounts);
            }
        }
コード例 #7
0
            public void Transfer(GeneralLedgerEntry generalLedgerEntry)
            {
                foreach (var debit in generalLedgerEntry.Debits)
                {
                    _inner[debit.AccountNumber] = _inner.TryGetValue(debit.AccountNumber, out var amount)
                                                ? amount + debit.Amount
                                                : debit.Amount;
                }

                foreach (var credit in generalLedgerEntry.Credits)
                {
                    _inner[credit.AccountNumber] = _inner.TryGetValue(credit.AccountNumber, out var amount)
                                                ? amount - credit.Amount
                                                : -credit.Amount;
                }
            }
コード例 #8
0
            public void Transfer(GeneralLedgerEntry generalLedgerEntry)
            {
                foreach (var credit in generalLedgerEntry.Credits)
                {
                    var accountType = AccountType.OfAccountNumber(credit.AccountNumber);
                    if (accountType is AccountType.ExpenseAccount)
                    {
                        _expenses[credit.AccountNumber] = _expenses.TryGetValue(credit.AccountNumber, out var amount)
                                                        ? amount + credit.Amount
                                                        : credit.Amount;
                    }
                    else if (accountType is AccountType.IncomeAccount)
                    {
                        _income[credit.AccountNumber] = _income.TryGetValue(credit.AccountNumber, out var amount)
                                                        ? amount - credit.Amount
                                                        : -credit.Amount;
                    }
                }

                foreach (var debit in generalLedgerEntry.Debits)
                {
                    var accountType = AccountType.OfAccountNumber(debit.AccountNumber);
                    if (accountType is AccountType.ExpenseAccount)
                    {
                        _expenses[debit.AccountNumber] = _expenses.TryGetValue(debit.AccountNumber, out var amount)
                                                        ? amount - debit.Amount
                                                        : -debit.Amount;
                    }
                    else if (accountType is AccountType.IncomeAccount)
                    {
                        _income[debit.AccountNumber] = _income.TryGetValue(debit.AccountNumber, out var amount)
                                                        ? amount + debit.Amount
                                                        : debit.Amount;
                    }
                }
            }