Esempio n. 1
0
        /// <summary>
        /// Insert a ledger transaction
        /// </summary>
        /// <param name="ledgerTransaction">Ledger transaction</param>
        public virtual void InsertLedgerTransaction(LedgerTransaction ledgerTransaction)
        {
            if (ledgerTransaction.LedgerTransactionLines.Count <= 1)
            {
                throw new ArgumentException("There are no ledger transaction lines.");
            }

            // Attach properties
            ledgerTransaction.ChartOfAccounts = _repository.GetById <ChartOfAccounts>(ledgerTransaction.ChartOfAccountsId);

            foreach (var line in ledgerTransaction.LedgerTransactionLines)
            {
                line.LedgerAccount = _repository.GetById <LedgerAccount>(line.LedgerAccountId);
            }

            if (ledgerTransaction.AreThereAccountsFromDifferentCOAs())
            {
                throw new ArgumentException(
                          "Ledger transaction lines contains ledger accounts from different chart of accounts.");
            }

            var currentLedgerPeriodStartingDate = ledgerTransaction.ChartOfAccounts.CurrentLedgerPeriodStartDate;

            if (ledgerTransaction.PostingDate.Year != currentLedgerPeriodStartingDate.Year ||
                ledgerTransaction.PostingDate.Month != currentLedgerPeriodStartingDate.Month ||
                ledgerTransaction.PostingDate > DateTime.Now)
            {
                throw new ArgumentException("Invalid posting period.");
            }

            if (ledgerTransaction.GetTotalDebitAmount() != ledgerTransaction.GetTotalCreditAmount())
            {
                throw new ArgumentException("Total debit amount differs from total credit amount.");
            }

            if (ledgerTransaction.AreThereDuplicateAccounts())
            {
                throw new ArgumentException("Ledger transaction lines contain duplicate ledger accounts.");
            }

            _repository.Create(ledgerTransaction);

            _repository.Save();
        }
Esempio n. 2
0
        public void Can_check_whether_there_are_duplicate_ledgerAccounts()
        {
            var transaction = new LedgerTransaction
            {
                Documentation = "Test",
                Description   = "Test",
                PostingDate   = DateTime.Now
            };
            var transactionLine1 = new LedgerTransactionLine
            {
                Id = 1,
                LedgerAccountId = 1,
                Amount          = 2000,
                IsDebit         = true
            };
            var transactionLine2 = new LedgerTransactionLine
            {
                Id = 2,
                LedgerAccountId = 1,
                Amount          = 2000,
                IsDebit         = false
            };
            var transactionLine3 = new LedgerTransactionLine
            {
                Id = 3,
                LedgerAccountId = 3,
                Amount          = 1000,
                IsDebit         = true
            };

            transaction.LedgerTransactionLines.Add(transactionLine1);
            transaction.LedgerTransactionLines.Add(transactionLine2);
            transaction.LedgerTransactionLines.Add(transactionLine3);
            var areThereDuplicateLedgerAccounts = transaction.AreThereDuplicateAccounts();

            Assert.True(areThereDuplicateLedgerAccounts);
        }