Beispiel #1
0
		} // CreateNewLoan

		public BuiltLoan BuildLoan(CashRequest cr, decimal amount, DateTime now, int term, int interestOnlyTerm = 0) {
			decimal setupFeePct = cr.ManualSetupFeePercent ?? 0;
			decimal brokerFeePct = cr.BrokerSetupFeePercent ?? 0;

			decimal approvedAmount = (decimal)(cr.ManagerApprovedSum ?? cr.SystemCalculatedSum ?? 0);

			if ((cr.Customer.Broker != null) && (approvedAmount != amount)) {
				log.Debug(
					"CreateNewLoan: broker customer '{0}', broker fee in cash request with approved amount {1} is {2}.",
					cr.Customer.Stringify(),
					approvedAmount.ToString("C2"),
					brokerFeePct.ToString("P2")
				);

				Loan firstLoan = cr.Customer.Loans.OrderBy(l => l.Date).FirstOrDefault();

				brokerFeePct = new CommissionCalculator(amount, firstLoan == null ? (DateTime?)null : firstLoan.Date)
					.Calculate()
					.BrokerCommission;

				log.Debug(
					"CreateNewLoan: broker customer '{0}', broker fee adjusted to loan amount {1} is {2}.",
					cr.Customer.Stringify(),
					amount.ToString("C2"),
					brokerFeePct.ToString("P2")
				);
			} // if broker customer

			var fees = new SetupFeeCalculator(setupFeePct, brokerFeePct).Calculate(amount);

			decimal setupFee = fees.Total;
			decimal brokerFee = fees.Broker;

			var calculator = new LoanScheduleCalculator { Interest = cr.InterestRate, Term = term };

			LoanLegal loanLegal = cr.LoanLegals.LastOrDefault();

			var loan = new Loan {
				LoanAmount = amount,
				Date = now,
				LoanType = cr.LoanType,
				CashRequest = cr,
				SetupFee = setupFee,
				LoanLegalId = loanLegal == null ? (int?)null : loanLegal.Id
			};

			calculator.Calculate(amount, loan, loan.Date, interestOnlyTerm, cr.SpreadSetupFee());

			loan.LoanSource = cr.LoanSource;

			if (brokerFee > 0 && cr.Customer.Broker != null) {
				loan.BrokerCommissions.Add(new LoanBrokerCommission {
					Broker = cr.Customer.Broker,
					CardInfo = cr.Customer.Broker.BankAccounts.FirstOrDefault(
						x => x.IsDefault.HasValue && x.IsDefault.Value
					),
					CommissionAmount = brokerFee,
					CreateDate = now,
					Loan = loan,
				});
			} // if broker fee & broker

			return new BuiltLoan {
				Loan = loan,
				BrokerFeePercent = brokerFeePct,
				ManualSetupFeePercent = setupFeePct,
			};
		} // BuildLoan
Beispiel #2
0
        }         // BuildWizardModel

        private void BuildProfileModel(CustomerModel customerModel, Customer customer)
        {
            customerModel.FirstName  = string.Empty;
            customerModel.MiddleName = string.Empty;
            customerModel.LastName   = string.Empty;

            if (customer.PersonalInfo != null)
            {
                customerModel.FirstName  = customer.PersonalInfo.FirstName;
                customerModel.MiddleName = customer.PersonalInfo.MiddleInitial;
                customerModel.LastName   = customer.PersonalInfo.Surname;
            }             // if

            customerModel.bankAccountAdded = customer.HasBankAccount;

            if (customer.HasBankAccount)
            {
                customerModel.BankAccountNumber = customer.BankAccount.AccountNumber;
                customerModel.SortCode          = customer.BankAccount.SortCode;
            }             // if

            customerModel.LastApprovedLoanTypeID        = 0;
            customerModel.LastApprovedRepaymentPeriod   = 0;
            customerModel.IsLastApprovedLoanSourceEu    = false;
            customerModel.IsLastApprovedLoanSourceCOSME = false;
            customerModel.SignedLegalID              = 0;
            customerModel.LastApprovedAmount         = 0;
            customerModel.HasApprovalChance          = customer.HasApprovalChance;
            customerModel.IsLoanTypeSelectionAllowed = customer.IsLoanTypeSelectionAllowed;
            if (customer.LastCashRequest != null)
            {
                customerModel.LastApprovedAmount = (int)(customer.LastCashRequest.ManagerApprovedSum ?? 0);

                customerModel.LastApprovedLoanTypeID      = customer.LastCashRequest.LoanType.Id;
                customerModel.LastRepaymentPeriod         = customer.LastCashRequest.RepaymentPeriod;
                customerModel.LastApprovedRepaymentPeriod = customer.LastCashRequest.ApprovedRepaymentPeriod ?? customer.LastCashRequest.RepaymentPeriod;
                customerModel.IsLastApprovedLoanSourceEu  =
                    customer.LastCashRequest.LoanSource.Name == LoanSourceName.EU.ToString();
                customerModel.IsLastApprovedLoanSourceCOSME =
                    customer.LastCashRequest.LoanSource.Name == LoanSourceName.COSME.ToString();

                LoanLegal lastll = customer.LastCashRequest.LoanLegals.LastOrDefault();

                customerModel.SignedLegalID = (lastll == null) ? 0 : lastll.Id;

                customerModel.IsCustomerRepaymentPeriodSelectionAllowed = customer.LastCashRequest.IsCustomerRepaymentPeriodSelectionAllowed;
            }             // if

            customerModel.Medal = customer.Medal.HasValue ? customer.Medal.ToString() : "";

            customerModel.OfferStart      = customer.OfferStart;
            customerModel.OfferValidUntil = customer.OfferValidUntil;


            customerModel.Loans = customer.Loans
                                  .OrderBy(l => l.Status)
                                  .ThenByDescending(l => l.Date)
                                  .Select(l => LoanModel.FromLoan(l,
                                                                  new LoanRepaymentScheduleCalculator(l, null, CurrentValues.Instance.AmountToChargeFrom),
                                                                  new LoanRepaymentScheduleCalculator(l, DateTime.UtcNow, CurrentValues.Instance.AmountToChargeFrom)))
                                  .ToList();

            customerModel.TotalBalance      = customerModel.Loans.Sum(l => l.Balance);
            customerModel.PrincipalBalance  = customer.ActiveLoans.Sum(l => l.LoanAmount);
            customerModel.TotalEarlyPayment = customerModel.Loans.Sum(l => l.TotalEarlyPayment);

            customerModel.TotalLatePayment = customerModel.Loans
                                             .Where(l => l.Status == LoanStatus.Late.ToString())
                                             .Sum(l => l.Late);

            var nextPayment = (
                from loan in customer.ActiveLoans
                from repayment in loan.Schedule
                where repayment.AmountDue > 0
                where repayment.Status == LoanScheduleStatus.StillToPay || repayment.Status == LoanScheduleStatus.Late
                orderby repayment.Date
                select repayment
                ).FirstOrDefault();

            if (nextPayment != null)
            {
                customerModel.NextPayment     = nextPayment.AmountDue;
                customerModel.NextPaymentDate = nextPayment.Date;
                customerModel.IsEarly         =
                    nextPayment.Date > DateTime.UtcNow && (
                        nextPayment.Date.Year != DateTime.UtcNow.Year ||
                        nextPayment.Date.Month != DateTime.UtcNow.Month ||
                        nextPayment.Date.Day != DateTime.UtcNow.Day
                        );
            }             // if

            try {
                customerModel.TotalPayEarlySavings = new LoanPaymentFacade().CalculateSavings(customer, DateTime.UtcNow);
            } catch (Exception) {
                //do nothing
            }             // try

            var payments =
                from loan in customer.Loans
                from tran in loan.Transactions
                where tran is PaypointTransaction
                orderby tran.PostDate descending
                select tran;

            var lastPayment = payments.OfType <PaypointTransaction>().FirstOrDefault();

            if (lastPayment != null)
            {
                customerModel.LastPaymentTotal     = lastPayment.Amount;
                customerModel.LastPaymentPrincipal = lastPayment.Principal;
                customerModel.LastPaymentInterest  = lastPayment.Interest;
                customerModel.LastPaymentFees      = lastPayment.Fees;
            }             // if

            var isDefault =
                customer.CollectionStatus != null &&
                customer.CollectionStatus.IsDefault;

            customerModel.BlockTakingLoan = customer.BlockTakingLoan;
            //customerModel.Perks = isDefault ? null : m_oPerksRepository.GetActivePerk();

            customerModel.TrustPilotStatusID = customer.TrustPilotStatus.ID;

            // Currently disabled trust pilot for EVL customers
            customerModel.TrustPilotReviewEnabled =
                CurrentValues.Instance.TrustPilotReviewEnabled &&
                customer.CustomerOrigin.IsEzbob();

            customerModel.PayPointCards = FillPayPointCards(customer);

            customerModel.ActiveRollovers = m_oPaymentRolloverRepository
                                            .GetRolloversForCustomer(customer.Id)
                                            .Where(x => x.Status == RolloverStatus.New)
                                            .Select(x => new RolloverModel {
                Created     = x.Created,
                CreatorName = x.CreatorName,
                CustomerConfirmationDate = x.CustomerConfirmationDate,
                ExpiryDate        = x.ExpiryDate,
                Id                = x.Id,
                LoanScheduleId    = x.LoanSchedule.Id,
                PaidPaymentAmount = x.PaidPaymentAmount,
                Payment           = x.Payment,
                PaymentDueDate    = x.PaymentDueDate,
                PaymentNewDate    = x.PaymentNewDate,
                Status            = x.Status,
                LoanId            = x.LoanSchedule.Loan.Id,
                RolloverPayValue  = GetRolloverPayValue(x.LoanSchedule.Loan)
            });

            customerModel.ApplyCount = customer.ApplyCount;
            customerModel.IsDefaultCustomerStatus = customer.CollectionStatus.IsDefault;
            customerModel.HasRollovers            = customerModel.ActiveRollovers.Any();

            var lastTurnover = customer.Turnovers.OrderByDescending(x => x.Timestamp)
                               .FirstOrDefault();

            if (lastTurnover != null)
            {
                customerModel.Turnover          = lastTurnover.Turnover;
                customerModel.IsTurnoverExpired = (DateTime.Today - lastTurnover.Timestamp).TotalDays > (365.0 / 2);                 //half year
            }
            else
            {
                customerModel.Turnover          = 0;
                customerModel.IsTurnoverExpired = true;
            }

            SafeReader sr = DbConnectionGenerator.Get(new SafeILog(this)).GetFirst(
                "LoadActiveLotteries",
                CommandSpecies.StoredProcedure,
                new QueryParameter("UserID", customer.Id),
                new QueryParameter("Now", DateTime.UtcNow)
                );

            customerModel.LotteryPlayerID = sr.IsEmpty ? string.Empty : ((Guid)sr["UniqueID"]).ToString("N");
            customerModel.LotteryCode     = sr["LotteryCode"];
        }         // BuildProfileModel