Пример #1
0
        public bool ApplyLateCharge(Loan loan, decimal amount, int loanChargesTypeId, DateTime date)
        {
            var charge = new LoanCharge {
                Amount      = amount,
                ChargesType = new ConfigurationVariable(CurrentValues.Instance.GetByID(loanChargesTypeId)),
                Date        = date,
                Loan        = loan
            };

            var res = loan.TryAddCharge(charge);

            var facade = new LoanPaymentFacade();

            facade.Recalculate(loan, date);

            _loans.Update(loan);

            //Log.Debug(string.Format("updated loan: {0}", loan));

            return(res);
        }
Пример #2
0
        public void ManualPayment(ManualPaymentModel model)
        {
            var realAmount = model.TotalSumPaid;
            var customer   = this.customerRepository.Get(model.CustomerId);

            try {
                Log.InfoFormat("Manual payment request for customer id {0}, amount {1}", customer.Id, realAmount);

                if (realAmount < 0)
                {
                    throw new Exception("Amount is too small");
                }

                var date = FormattingUtils.ParseDateWithoutTime(model.PaymentDate);

                if (date > DateTime.UtcNow)
                {
                    throw new Exception("The date is more than now");
                }

                if (date < DateTime.UtcNow.AddDays(-7))
                {
                    throw new Exception("The date is less than a week ago");
                }

                string payPointTransactionId = PaypointTransaction.Manual;

                if (model.ChargeClient)
                {
                    var paypointCard = customer.PayPointCards.FirstOrDefault(x => x.IsDefaultCard);
                    if (paypointCard == null && customer.PayPointCards.Any())
                    {
                        paypointCard = customer.PayPointCards.First();
                    }

                    if (paypointCard == null)
                    {
                        throw new Exception("No Debit card found");
                    }

                    payPointTransactionId = paypointCard.TransactionId;

                    this.paypoint.RepeatTransactionEx(paypointCard.PayPointAccount, payPointTransactionId, realAmount);
                }

                string description = string.Format("UW Manual payment method: {0}, description: {2}{2}{1}", model.PaymentMethod,
                                                   model.Description, Environment.NewLine);

                string nlMethod = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.PaymentMethod).Replace(" ", "").Replace("-", "");
                NLLoanTransactionMethods nlPaymentMethod = (NLLoanTransactionMethods)Enum.Parse(typeof(NLLoanTransactionMethods), nlMethod);
                var nlPayment = new NL_Payments()
                {
                    CreatedByUserID   = this.context.UserId,
                    Amount            = realAmount,
                    PaymentMethodID   = (int)nlPaymentMethod,
                    PaymentSystemType = NLPaymentSystemTypes.None,
                };

                Log.InfoFormat("ManualPayment: Sending nlPayment: {0} for customer {1}", nlPayment, customer.Id);

                var facade = new LoanPaymentFacade();
                facade.MakePayment(payPointTransactionId, realAmount, null,
                                   "other", model.LoanId, customer,
                                   date, description, null, model.PaymentMethod, nlPayment);

                Log.InfoFormat("add payment to new payment table customer {0}", customer.Id);
                var loan = customer.GetLoan(model.LoanId);
                facade.Recalculate(loan, DateTime.Now);

                if (model.SendEmail)
                {
                    this.serviceClient.Instance.PayEarly(customer.Id, realAmount, customer.GetLoan(model.LoanId).RefNumber);
                }

                this.serviceClient.Instance.LoanStatusAfterPayment(
                    this.context.UserId,
                    customer.Id,
                    customer.Name,
                    model.LoanId,
                    realAmount,
                    model.SendEmail,
                    loan.Balance,
                    loan.Status == LoanStatus.PaidOff
                    );

                string requestType = string.Format("UW Manual payment for customer {0}, amount {1}",
                                                   customer.PersonalInfo.Fullname, realAmount);

                Log.InfoFormat("Successful. userID {0} at {1}. requestType: {2}", this.context.UserId, date, requestType);
            } catch (PayPointException ex) {
                Log.ErrorFormat("Paypoint Manual Payment for customer {0}, at {1} failed with error {2}", customer.Id, DateTime.UtcNow, ex);
            } catch (Exception exx) {
                Log.ErrorFormat("Paypoint Manual Payment for customer {0}, at {1} failed with error {2}", customer.Id, DateTime.UtcNow, exx);
            }
        }