} // GenerateAgreementModel

		private void GetSetupFees(
			Customer customer,
			Loan loan,
			out decimal manualSetupFeePct,
			out decimal brokerSetupFeePct
		) {
			if (loan.LoanLegalId != null) {
				var loanLegal = this.loanLegalRepo.GetAll().FirstOrDefault(ll => ll.Id == loan.LoanLegalId.Value);

				if (loanLegal != null) {
					manualSetupFeePct = loanLegal.ManualSetupFeePercent ?? 0;
					brokerSetupFeePct = loanLegal.BrokerSetupFeePercent ?? 0;
					return;
				} // if
			} // if

			manualSetupFeePct = loan.CashRequest.ManualSetupFeePercent ?? 0;
			brokerSetupFeePct = loan.CashRequest.BrokerSetupFeePercent ?? 0;

			decimal approvedAmount =
				(decimal)(loan.CashRequest.ManagerApprovedSum ?? loan.CashRequest.SystemCalculatedSum ?? 0);

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

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

				brokerSetupFeePct = new CommissionCalculator(
					loan.LoanAmount,
					firstLoan == null ? (DateTime?)null : firstLoan.Date
				)
					.Calculate()
					.BrokerCommission;

				this.log.Debug(
					"CreateNewLoan: broker customer '{0}', broker fee adjusted to loan amount {1} is {2}.",
					customer.Stringify(),
					loan.LoanAmount.ToString("C2"),
					brokerSetupFeePct.ToString("P2")
				);
			} // if broker customer
		} // GetSetupFees
示例#2
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