public async Task<ActionResult> AddPayment(PaymentDetailsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var data = await mediator.SendAsync(new GetAccountManagementData(model.NotificationId));
                var accountManagementViewModel = new AccountManagementViewModel(data);
                accountManagementViewModel.RefundViewModel = await GetNewRefundDetailsViewModel(model.NotificationId);
                accountManagementViewModel.PaymentViewModel = model;
                accountManagementViewModel.ShowPaymentDetails = true;

                return View("Index", accountManagementViewModel);
            }

            if (model.PaymentMethod != PaymentMethod.Cheque)
            {
                model.Receipt = "NA";
            }

            var paymentData = new NotificationTransactionData
            {
                Date = model.PaymentDate.AsDateTime().Value,
                NotificationId = model.NotificationId,
                Credit = Convert.ToDecimal(model.PaymentAmount),
                PaymentMethod = model.PaymentMethod,
                ReceiptNumber = model.Receipt,
                Comments = model.Comments
            };

            await mediator.SendAsync(new AddNotificationTransaction(paymentData));

            return RedirectToAction("Index", "AccountManagement");
        }
        public async Task <ActionResult> AddPayment(PaymentDetailsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var data = await mediator.SendAsync(new GetAccountManagementData(model.NotificationId));

                var accountManagementViewModel = new AccountManagementViewModel(data);
                accountManagementViewModel.RefundViewModel = await GetNewRefundDetailsViewModel(model.NotificationId);

                accountManagementViewModel.PaymentViewModel   = model;
                accountManagementViewModel.ShowPaymentDetails = true;

                return(View("Index", accountManagementViewModel));
            }

            if (model.PaymentMethod != PaymentMethod.Cheque)
            {
                model.Receipt = "NA";
            }

            var paymentData = new NotificationTransactionData
            {
                Date           = model.PaymentDate.AsDateTime().Value,
                NotificationId = model.NotificationId,
                Credit         = Convert.ToDecimal(model.PaymentAmount),
                PaymentMethod  = model.PaymentMethod,
                ReceiptNumber  = model.Receipt,
                Comments       = model.PaymentComments.Trim()
            };

            await mediator.SendAsync(new AddNotificationTransaction(paymentData));

            return(RedirectToAction("Index", "AccountManagement"));
        }
        public async Task <ActionResult> AddRefund(RefundDetailsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var data = await mediator.SendAsync(new GetAccountManagementData(model.NotificationId));

                var accountManagementViewModel = new AccountManagementViewModel(data);
                accountManagementViewModel.PaymentViewModel = new PaymentDetailsViewModel {
                    NotificationId = model.NotificationId
                };
                accountManagementViewModel.RefundViewModel   = model;
                accountManagementViewModel.ShowRefundDetails = true;

                return(View("Index", accountManagementViewModel));
            }

            var refundData = new NotificationTransactionData
            {
                Date           = model.RefundDate.AsDateTime().Value,
                NotificationId = model.NotificationId,
                Debit          = Convert.ToDecimal(model.RefundAmount),
                Comments       = model.RefundComments.Trim(),
                ReceiptNumber  = "NA"
            };

            await mediator.SendAsync(new AddNotificationTransaction(refundData));

            return(RedirectToAction("index", "AccountManagement", new { id = model.NotificationId }));
        }
        public async Task<bool> PaymentIsNowFullyReceived(NotificationTransactionData data)
        {
            var newBalance = await Balance(data.NotificationId)
                - data.Credit.GetValueOrDefault()
                + data.Debit.GetValueOrDefault();

            return newBalance <= 0;
        }
        private void AddCalculatorTransaction(DateTime date, decimal?credit, decimal?debit)
        {
            var transactionData =
                new NotificationTransactionData
            {
                Date           = date,
                Credit         = credit,
                Debit          = debit,
                NotificationId = NotificationId,
                PaymentMethod  = PaymentMethod.BacsChaps
            };

            calculatorTransactions.Add(new NotificationTransaction(transactionData));
        }
        private AddNotificationTransaction GetAddNotificationTransaction(DateTime date, decimal?credit, decimal?debit)
        {
            var transactionData =
                new NotificationTransactionData
            {
                Date           = date,
                Credit         = credit,
                Debit          = debit,
                NotificationId = NotificationId,
                PaymentMethod  = PaymentMethod.BacsChaps
            };

            var message = new AddNotificationTransaction(transactionData);

            transactions.Add(new NotificationTransaction(transactionData));

            return(message);
        }
        public async Task Save(NotificationTransactionData data)
        {
            if (data.Debit > await transactionCalculator.RefundLimit(data.NotificationId))
            {
                throw new InvalidOperationException("Transaction cannot refund more than has already been paid");
            }

            transactionRepository.Add(data);

            if (data.Credit > 0 && await transactionCalculator.PaymentIsNowFullyReceived(data))
            {
                var assessment = await notificationAssessmentRepository.GetByNotificationId(data.NotificationId);

                if (assessment.Dates.PaymentReceivedDate == null)
                {
                    assessment.Dates.PaymentReceivedDate = data.Date;
                }
            }
        }
        public NotificationTransaction(NotificationTransactionData notificationTransactionData)
        {
            if (notificationTransactionData.ReceiptNumber != null && notificationTransactionData.ReceiptNumber.Length > 70)
            {
                throw new InvalidOperationException(string.Format("NotificationId {0} - Receipt number must not be more than 70 characters", Id));
            }

            if (notificationTransactionData.Comments != null && notificationTransactionData.Comments.Length > 500)
            {
                throw new InvalidOperationException(string.Format("NotificationId {0} - Comments must not be more than 500 characters", Id));
            }

            Date           = notificationTransactionData.Date;
            NotificationId = notificationTransactionData.NotificationId;
            Debit          = notificationTransactionData.Debit;
            Credit         = notificationTransactionData.Credit;
            PaymentMethod  = notificationTransactionData.PaymentMethod;
            ReceiptNumber  = notificationTransactionData.ReceiptNumber;
            Comments       = notificationTransactionData.Comments;
        }
        public NotificationTransaction(NotificationTransactionData notificationTransactionData)
        {
            if (notificationTransactionData.ReceiptNumber != null && notificationTransactionData.ReceiptNumber.Length > 70)
            {
                throw new InvalidOperationException(string.Format("NotificationId {0} - Receipt number must not be more than 70 characters", Id));
            }

            if (notificationTransactionData.Comments != null && notificationTransactionData.Comments.Length > 500)
            {
                throw new InvalidOperationException(string.Format("NotificationId {0} - Comments must not be more than 500 characters", Id));
            }

            Date = notificationTransactionData.Date;
            NotificationId = notificationTransactionData.NotificationId;
            Debit = notificationTransactionData.Debit;
            Credit = notificationTransactionData.Credit;
            PaymentMethod = notificationTransactionData.PaymentMethod;
            ReceiptNumber = notificationTransactionData.ReceiptNumber;
            Comments = notificationTransactionData.Comments;
        }
        public async Task<ActionResult> AddRefund(RefundDetailsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var data = await mediator.SendAsync(new GetAccountManagementData(model.NotificationId));
                var accountManagementViewModel = new AccountManagementViewModel(data);
                accountManagementViewModel.PaymentViewModel = new PaymentDetailsViewModel { NotificationId = model.NotificationId };
                accountManagementViewModel.RefundViewModel = model;
                accountManagementViewModel.ShowRefundDetails = true;

                return View("Index", accountManagementViewModel);
            }

            var refundData = new NotificationTransactionData
            {
                Date = model.RefundDate.AsDateTime().Value,
                NotificationId = model.NotificationId,
                Debit = Convert.ToDecimal(model.RefundAmount),
                Comments = model.Comments,
                ReceiptNumber = "NA"
            };

            await mediator.SendAsync(new AddNotificationTransaction(refundData));

            return RedirectToAction("index", "AccountManagement", new { id = model.NotificationId });
        }
Exemple #11
0
 public AddNotificationTransaction(NotificationTransactionData data)
 {
     Data = data;
 }
 public void Add(NotificationTransactionData notificationTransactionData)
 {
     context.NotificationTransactions.Add(new NotificationTransaction(notificationTransactionData));
 }