Exemple #1
0
        public IActionResult PostTransaction([FromBody] TransactionForDisplay transaction)
        {
            var transactions = new List <TransactionForDisplay>();

            if (transaction.TransactionId == null || transaction.TransactionId == Guid.Empty)
            {
                transaction.TransactionId = Guid.NewGuid();
            }
            if (transaction.AccountId == null)
            {
                transaction.AccountId = _accountRepo.GetAll().Single(a => a.Name.Equals(transaction.AccountName, StringComparison.CurrentCultureIgnoreCase)).AccountId;
            }
            transaction.SetAmount();
            transaction.EnteredDate = DateTime.Now;
            if (transaction.CategoryId.IsNullOrEmpty() && !string.IsNullOrWhiteSpace(transaction.CategoryName))
            {
                var category = _categoryRepo.GetAll().SingleOrDefault(c => (c.Name.Equals(transaction.CategoryName, StringComparison.CurrentCultureIgnoreCase)));
                if (category == null)
                {
                    category = new Category
                    {
                        CategoryId = Guid.NewGuid(),
                        Name       = transaction.CategoryName,
                        Type       = "Expenses"
                    };
                    _categoryRepo.Insert(category);
                }
                transaction.CategoryId = category.CategoryId;
            }

            var bankFeeTransactions = TransactionHelpers.GetBankFeeTransactions(transaction, _categoryRepo, _accountRepo);

            transactions.Add(transaction);
            transactions.AddRange(bankFeeTransactions);
            foreach (var trx in transactions)
            {
                _transactionRepo.Insert(trx);
            }

            var accountBalances       = _accountRepo.GetAccountBalances().Select(a => new { a.AccountId, a.CurrentBalance });
            InvoiceForPosting invoice = null;

            if (transaction.InvoiceId.HasValue)
            {
                invoice = _invoiceRepo.Get(transaction.InvoiceId.Value);
            }
            var vendor = _vendorRepo.GetAll().SingleOrDefault(v => v.Name == transaction.Vendor);

            return(CreatedAtAction("PostTransaction", new { id = transaction.TransactionId }, new { transactions, accountBalances, invoice, vendor }));
        }
Exemple #2
0
        public IActionResult PostTransfer([FromBody] TransactionForDisplay transaction)
        {
            var transactions = new List <TransactionForDisplay>();

            if (transaction.TransactionId == null || transaction.TransactionId == Guid.Empty)
            {
                transaction.TransactionId = Guid.NewGuid();
            }
            if (!transaction.AccountId.HasValue)
            {
                transaction.AccountId = _accountRepo.GetAll().Single(
                    a => a.Name.Equals(transaction.AccountName, StringComparison.CurrentCultureIgnoreCase)).AccountId;
            }
            transaction.SetAmount();
            var relatedTransactionId = Guid.NewGuid();
            var relatedTransaction   = new TransactionForDisplay {
                TransactionDate      = transaction.TransactionDate,
                TransactionId        = relatedTransactionId,
                Vendor               = transaction.Vendor,
                Description          = transaction.Description,
                AccountId            = transaction.RelatedAccountId.Value,
                Amount               = 0 - transaction.Amount,
                EnteredDate          = DateTime.Now,
                RelatedTransactionId = transaction.TransactionId
            };

            relatedTransaction.SetDebitAndCredit();

            transaction.RelatedTransactionId = relatedTransactionId;

            var bankFeeTransactions = TransactionHelpers.GetBankFeeTransactions(transaction, _categoryRepo, _accountRepo);

            transactions.Add(transaction);
            transactions.Add(relatedTransaction);
            transactions.AddRange(bankFeeTransactions);
            _transactionRepo.InsertRelatedTransaction(transaction, relatedTransaction);
            foreach (var trx in bankFeeTransactions)
            {
                _transactionRepo.Insert(trx);
            }

            var accountBalances = _accountRepo.GetAccountBalances().Select(a => new { a.AccountId, a.CurrentBalance });

            return(CreatedAtAction("PostTransfer",
                                   new { id = transaction.TransactionId }, new { transactions, accountBalances }));
        }
Exemple #3
0
        public IActionResult PostMortgagePayment([FromBody] TransactionForDisplay transaction)
        {
            var principal = transaction.Debit.Value;
            var interest  = transaction.Credit.Value;

            transaction.Credit = null;
            var transactions = new List <TransactionForDisplay>();

            if (transaction.TransactionId == null || transaction.TransactionId == Guid.Empty)
            {
                transaction.TransactionId = Guid.NewGuid();
            }
            if (!transaction.AccountId.HasValue)
            {
                transaction.AccountId = _accountRepo.GetAll().Single(
                    a => a.Name.Equals(transaction.AccountName, StringComparison.CurrentCultureIgnoreCase)).AccountId;
            }
            transaction.SetAmount();
            var relatedTransactionId = Guid.NewGuid();
            var relatedTransaction   = new TransactionForDisplay {
                TransactionDate      = transaction.TransactionDate,
                TransactionId        = relatedTransactionId,
                Vendor               = transaction.Vendor,
                Description          = string.IsNullOrWhiteSpace(transaction.Description) ? "Mortgage Payment" : transaction.Description,
                AccountId            = transaction.RelatedAccountId.Value,
                Amount               = 0 - transaction.Amount,
                EnteredDate          = DateTime.Now,
                RelatedTransactionId = transaction.TransactionId
            };

            relatedTransaction.SetDebitAndCredit();

            transaction.RelatedTransactionId = relatedTransactionId;

            var mortgageInterestCategoryId = TransactionHelpers.GetOrCreateCategory("Mortgage Interest", _categoryRepo).CategoryId;
            var interestTransaction        = new TransactionForDisplay {
                TransactionDate = transaction.TransactionDate,
                TransactionId   = Guid.NewGuid(),
                Vendor          = transaction.Vendor,
                AccountId       = transaction.AccountId,
                Amount          = 0 - interest,
                Debit           = interest,
                EnteredDate     = DateTime.Now,
                CategoryId      = mortgageInterestCategoryId,
                CategoryDisplay = "Mortgage Interest"
            };

            var bankFeeTransactions = TransactionHelpers.GetBankFeeTransactions(transaction, _categoryRepo, _accountRepo);

            transactions.Add(transaction);
            transactions.Add(relatedTransaction);
            transactions.Add(interestTransaction);
            transactions.AddRange(bankFeeTransactions);
            _transactionRepo.InsertRelatedTransaction(transaction, relatedTransaction);
            _transactionRepo.Insert(interestTransaction);
            foreach (var trx in bankFeeTransactions)
            {
                _transactionRepo.Insert(trx);
            }

            var accountBalances = _accountRepo.GetAccountBalances();

            return(CreatedAtAction("PostTransfer",
                                   new { id = transaction.TransactionId }, new { transactions, accountBalances }));
        }