public ActionResult AllocatePayment(PaymentAllocationModel model)
        {
            var success        = true;
            var failureMessage = "There has been an error whilst allocating the payment.";

            try
            {
                if (model.Allocations.Sum(x => x.Value) > model.Amount)
                {
                    failureMessage += " The amount allocated to individual invoices cannot exceed the total payment amount.";
                    success         = false;
                }
                else
                {
                    var transaction = paymentService.GetBankTransaction(model.Transaction.ID);
                    if (transaction != null)
                    {
                        foreach (var allocation in model.Allocations.Where(x => x.Value > 0))
                        {
                            paymentService.AllocatePayment(transaction, allocation.Value, allocation.Key.ID, model.Notes);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                success = false;
                loggingService.LogException(ex);
            }

            SetFeedbackMessage(success,
                               "Payment has been allocated.",
                               failureMessage);
            return(RedirectToSamePage());
        }
        public ActionResult AllocationModal(int id)
        {
            var transaction = paymentService.GetBankTransaction(id);
            var statements  = statementService.GetCustomerStatementsByPayerID(transaction.PayerID.Value)
                              .Where(x => x.AmountOutstanding > 0)
                              .OrderBy(x => x.StatementDate)
                              .ToList();

            var model = new PaymentAllocationModel()
            {
                Transaction = transaction
            };

            statements.ForEach(statement =>
            {
                model.Allocations.Add(statement, 0);
            });

            return(PartialView("_AllocationModal", model));
        }