public void Can_set_monthBalance()
        {
            var ledgerAccountBalance = new LedgerAccountBalance
            {
                LedgerAccountId  = 1,
                BeginningBalance = 0,
                Balance3         = 1000
            };

            ledgerAccountBalance.SetMonthBalance(0, 3000);
            Assert.Equal(3000, ledgerAccountBalance.GetMonthBalance(0));
        }
Beispiel #2
0
        private LedgerAccountBalance GetPeriodLedgerAccountBalance(int ledgerAccountId, int year, int month,
                                                                   out bool isCreate)
        {
            isCreate = false;
            LedgerAccountBalance accountBalance;

            // If closing month is January, create a new account balance for this year
            if (month == 1)
            {
                isCreate       = true;
                accountBalance = new LedgerAccountBalance {
                    LedgerAccountId = ledgerAccountId, Year = year
                };

                var previousYearAccountBalance =
                    _repository.GetOne <LedgerAccountBalance>(
                        b => b.LedgerAccountId == ledgerAccountId && b.Year == year - 1);

                // Set the beginning balance to previous year's ending balance
                if (previousYearAccountBalance != null)
                {
                    accountBalance.SetMonthBalance(0, previousYearAccountBalance.Balance12);
                }

                return(accountBalance);
            }

            accountBalance =
                _repository.GetOne <LedgerAccountBalance>(b => b.LedgerAccountId == ledgerAccountId && b.Year == year);

            // Create account balance if it does not exist in the database yet
            if (accountBalance == null)
            {
                isCreate       = true;
                accountBalance = new LedgerAccountBalance {
                    LedgerAccountId = ledgerAccountId, Year = year
                };
            }

            return(accountBalance);
        }