public void ConstructWithGuidShouldSetId()
        {
            Guid id = Guid.NewGuid();
            var subject = new DebitLedgerTransaction(id);

            Assert.AreEqual(id, subject.Id);
        }
        public void WithReversal50ShouldReturnSameObjectForChaining()
        {
            var subject = new DebitLedgerTransaction();

            LedgerTransaction result = subject.WithReversal(50);

            Assert.AreSame(subject, result);
        }
        public void WithReversal50ShouldCreateANegativeDebitOf50()
        {
            var subject = new DebitLedgerTransaction();

            LedgerTransaction result = subject.WithReversal(50);

            Assert.AreEqual(-50M, result.Debit);
        }
        public void WithReversal50ShouldAZeroCreditAmount()
        {
            var subject = new DebitLedgerTransaction();

            LedgerTransaction result = subject.WithReversal(50);

            Assert.AreEqual(0M, result.Credit);
        }
        public void WithAmount50ShouldCreateADebitOf50()
        {
            var subject = new DebitLedgerTransaction();

            LedgerTransaction result = subject.WithAmount(50);

            Assert.AreEqual(50M, result.Debit);
        }
        private void SaveNewEntryTransaction()
        {
            try
            {
                if (NewTransactionIsCredit || NewTransactionIsDebit)
                {
                    LedgerTransaction newTransaction;
                    if (NewTransactionIsCredit)
                    {
                        newTransaction = new CreditLedgerTransaction();
                    }
                    else
                    {
                        newTransaction = new DebitLedgerTransaction();
                    }

                    if (NewTransactionIsReversal)
                    {
                        newTransaction.WithReversal(NewTransactionAmount).WithNarrative(NewTransactionNarrative);
                    }
                    else
                    {
                        newTransaction.WithAmount(NewTransactionAmount).WithNarrative(NewTransactionNarrative);
                    }

                    if (NewTransactionAccountType != null)
                    {
                        newTransaction.WithAccountType(NewTransactionAccountType);
                    }

                    LedgerEntry.AddTransaction(newTransaction);
                    ShownTransactions.Add(newTransaction);
                }
            }
            catch (ArgumentException)
            {
                // Invalid transaction data
                return;
            }

            RaisePropertyChanged(() => TransactionsTotal);
            this.wasChanged = true;
        }
Esempio n. 7
0
        public LedgerTransaction BalanceAdjustment(decimal adjustment, string narrative)
        {
            if (!IsNew)
            {
                throw new InvalidOperationException("Cannot adjust existing ledger lines, only newly added lines can be adjusted.");
            }

            if (adjustment == 0)
            {
                throw new ArgumentException("The balance adjustment amount cannot be zero.", "adjustment");
            }

            LedgerTransaction newAdjustment;
            if (adjustment < 0)
            {
                newAdjustment = new DebitLedgerTransaction
                {
                    Debit = -adjustment,
                    Narrative = narrative,
                };
            }
            else
            {
                newAdjustment = new CreditLedgerTransaction
                {
                    Credit = adjustment,
                    Narrative = narrative,
                };
            }

            this.bankBalanceAdjustments.Add(newAdjustment);
            return newAdjustment;
        }
Esempio n. 8
0
        /// <summary>
        ///     Called by <see cref="LedgerBook.Reconcile" />. Sets up this new Entry with transactions.
        /// </summary>
        /// <param name="newTransactions">The list of new transactions for this entry.</param>
        internal LedgerEntry SetTransactionsForReconciliation(List<LedgerTransaction> newTransactions)
        {
            this.transactions = newTransactions;
            if (LedgerColumn.BudgetBucket is SpentMonthlyExpenseBucket && NetAmount != 0)
            {
                // SpentMonthly ledgers automatically zero their balance. They dont accumulate nor can they be negative.
                LedgerTransaction zeroingTransaction = null;
                if (NetAmount < 0)
                {
                    if (newTransactions.OfType<BudgetCreditLedgerTransaction>().Any())
                    {
                        zeroingTransaction = new CreditLedgerTransaction
                        {
                            Credit = -NetAmount,
                            Narrative = "SpentMonthlyLedger: automatically supplementing shortfall from surplus",
                        };
                    }
                    else
                    {
                        if (Balance + NetAmount < 0)
                        {
                            zeroingTransaction = new CreditLedgerTransaction
                            {
                                Credit = -(Balance + NetAmount),
                                Narrative = "SpentMonthlyLedger: automatically supplementing shortfall from surplus",
                            };
                        }
                    }
                }
                else
                {
                    zeroingTransaction = new DebitLedgerTransaction
                    {
                        Debit = NetAmount,
                        Narrative = "SpentMonthlyLedger: automatically zeroing the credit remainder",
                    };
                }

                if (zeroingTransaction != null)
                {
                    this.transactions.Add(zeroingTransaction);
                }
            }
            else
            {
                // All other ledgers can accumulate a balance but cannot be negative.
                decimal newBalance = Balance + NetAmount;
                Balance = newBalance < 0 ? 0 : newBalance;
            }

            return this;
        }
        public void UsingTestData1_AddTransactionShouldEffectEntryNetAmount()
        {
            LedgerBook book = LedgerBookTestData.TestData1();
            BudgetModel budget = BudgetModelTestData.CreateTestData1();
            StatementModel statement = StatementModelTestData.TestData1();
            LedgerEntryLine entryLine = book.Reconcile(NextReconcileDate, NextReconcileBankBalance, budget, statement);
            var newTransaction = new DebitLedgerTransaction { Debit = 100 };
            LedgerEntry entry = entryLine.Entries.First();
            entry.AddTransaction(newTransaction);

            Assert.AreEqual(-100, entry.NetAmount);
        }