Ejemplo n.º 1
0
        protected override StepResults Run()
        {
            LinkOfferToInvestor loti = null;

            if (this.backdoorLogicApplied)
            {
                if (this.backdoorInvestorID == null)
                {
                    Log.Debug("Back door investor for {0}: look for investor as usual.", OuterContextDescription);
                }
                else if (this.backdoorInvestorID <= 0)
                {
                    this.outcome = string.Format("'back door investor not found'");
                    return(StepResults.NotFound);
                }
                else
                {
                    Log.Debug(
                        "Back door investor for {0}: try to set investor with id {1}.",
                        OuterContextDescription,
                        this.backdoorInvestorID.Value
                        );

                    loti = new LinkOfferToInvestor(
                        this.customerID,
                        this.cashRequestID,
                        true,
                        this.backdoorInvestorID.Value,
                        this.underwriterID
                        );
                }         // if
            }             // if back door logic

            if (loti == null)
            {
                loti = new LinkOfferToInvestor(this.customerID, this.cashRequestID, false, null, this.underwriterID);
            }

            loti.Execute();

            bool investorFound = !loti.IsForOpenPlatform || loti.FoundInvestor;

            this.outcome = string.Format(
                "'investor {0}found: for Open platform = {1}, really found = {2}'",
                investorFound ? string.Empty : "not ",
                loti.IsForOpenPlatform ? "yes" : "no",
                loti.FoundInvestor ? "yes" : "no"
                );

            return(investorFound ? StepResults.Found : StepResults.NotFound);
        }         // Run
Ejemplo n.º 2
0
        public void TestLinkOfferToInvestor()
        {
            var linkOfferToInvestor = new LinkOfferToInvestor(3406, 42824, false, null, 1);

            linkOfferToInvestor.Execute();
        }
Ejemplo n.º 3
0
        }         // RejectCustomer

        private bool ApproveCustomer(NL_Decisions newDecision)
        {
            LinkOfferToInvestor linkOfferToInvestor = new LinkOfferToInvestor(this.decisionToApply.Customer.ID, this.decisionToApply.CashRequest.ID, this.decisionModel.ForceInvestor, this.decisionModel.InvestorID, this.decisionModel.underwriterID);

            linkOfferToInvestor.Execute();

            Log.Info("ApproveCustomer Decision {0} for Customer {1} cr {2} OP {3} FoundInvestor {4}",
                     this.decisionToApply.CashRequest.UnderwriterDecision,
                     this.decisionToApply.Customer.ID,
                     this.decisionToApply.CashRequest.ID,
                     linkOfferToInvestor.IsForOpenPlatform,
                     linkOfferToInvestor.FoundInvestor);

            if (linkOfferToInvestor.IsForOpenPlatform && !linkOfferToInvestor.FoundInvestor)
            {
                PendingInvestor(newDecision);
                return(false);
            }

            this.decisionToApply.Customer.DateApproved   = this.now;
            this.decisionToApply.Customer.ApprovedReason = this.decisionModel.reason;

            this.decisionToApply.Customer.CreditSum                  = this.currentState.OfferedCreditLine;
            this.decisionToApply.Customer.ManagerApprovedSum         = this.currentState.OfferedCreditLine;
            this.decisionToApply.Customer.NumApproves                = 1 + this.currentState.NumOfPrevApprovals;
            this.decisionToApply.Customer.IsLoanTypeSelectionAllowed = this.currentState.IsLoanTypeSelectionAllowed;

            this.decisionToApply.CashRequest.ManagerApprovedSum = (int)this.currentState.OfferedCreditLine;

            if (!SaveDecision <ManuallyApprove>())
            {
                return(false);
            }

            bool bSendBrokerForceResetCustomerPassword =
                this.currentState.FilledByBroker &&
                (this.currentState.NumOfPrevApprovals == 0);

            bool bSendApprovedUser = !this.currentState.EmailSendingBanned;

            int validForHours = (int)(this.currentState.OfferValidUntil - this.currentState.OfferStart).TotalHours;

            if (bSendBrokerForceResetCustomerPassword && bSendApprovedUser)
            {
                FireToBackground(
                    new ApprovedUser(
                        this.decisionModel.customerID,
                        this.currentState.OfferedCreditLine,
                        validForHours,
                        this.currentState.NumOfPrevApprovals == 0
                        )
                {
                    SendToCustomer = false,
                },
                    e => Warning = "Failed to force reset customer password and send 'approved user' email: " + e.Message
                    );
            }
            else if (bSendApprovedUser)
            {
                FireToBackground(
                    new ApprovedUser(
                        this.decisionModel.customerID,
                        this.currentState.OfferedCreditLine,
                        validForHours,
                        this.currentState.NumOfPrevApprovals == 0
                        ),
                    e => Warning = "Failed to send 'approved user' email: " + e.Message
                    );
            }
            else if (bSendBrokerForceResetCustomerPassword)
            {
                FireToBackground(new BrokerForceResetCustomerPassword(this.decisionModel.customerID));
            }

            newDecision.DecisionNameID = (int)DecisionActions.Approve;

            AddDecision nlAddDecision = new AddDecision(newDecision, this.decisionToApply.CashRequest.ID, null);

            nlAddDecision.Context.CustomerID = this.decisionModel.customerID;
            nlAddDecision.Context.UserID     = this.decisionModel.underwriterID;

            try {
                try {
                    nlAddDecision.Execute();
                    Log.Debug("nl AddDecision {0}, Error: {1}", nlAddDecision.DecisionID, nlAddDecision.Error);

                    // ReSharper disable once CatchAllClause
                } catch (Exception ex) {
                    Log.Error("Failed to add NL_decision. Err: {0}", ex.Message);
                }

                NL_Offers nlOffer = new NL_Offers()
                {
                    DecisionID            = nlAddDecision.DecisionID,
                    CreatedTime           = this.currentState.CreationDate,
                    Amount                = this.currentState.OfferedCreditLine,
                    BrokerSetupFeePercent = this.currentState.BrokerSetupFeePercent,
                    //IsAmountSelectionAllowed = this.currentState.
                    SendEmailNotification = !this.currentState.EmailSendingBanned,
                    StartTime             = this.currentState.OfferStart,
                    EndTime = this.currentState.OfferValidUntil,
                    IsLoanTypeSelectionAllowed = this.currentState.IsLoanTypeSelectionAllowed == 1,
                    Notes = this.decisionToApply.CashRequest.UnderwriterComment + " old cr " + this.decisionToApply.CashRequest.ID,
                    MonthlyInterestRate               = this.currentState.InterestRate,
                    LoanSourceID                      = this.currentState.LoanSourceID,
                    DiscountPlanID                    = this.currentState.DiscountPlanID,
                    LoanTypeID                        = this.currentState.LoanTypeID,
                    RepaymentIntervalTypeID           = (int)RepaymentIntervalTypes.Month,
                    RepaymentCount                    = this.currentState.RepaymentPeriod,  // ApprovedRepaymentPeriod???
                    IsRepaymentPeriodSelectionAllowed = this.currentState.IsCustomerRepaymentPeriodSelectionAllowed
                };

                Log.Debug("Adding nl offer: {0}", nlOffer);

                NL_OfferFees setupFee = new NL_OfferFees()
                {
                    LoanFeeTypeID          = (int)NLFeeTypes.SetupFee,
                    Percent                = this.currentState.ManualSetupFeePercent,
                    OneTimePartPercent     = 1,
                    DistributedPartPercent = 0
                };

                if (this.currentState.SpreadSetupFee)
                {
                    setupFee.LoanFeeTypeID          = (int)NLFeeTypes.ServicingFee;
                    setupFee.OneTimePartPercent     = 0;
                    setupFee.DistributedPartPercent = 1;
                }
                NL_OfferFees[] ofeerFees = { setupFee };

                AddOffer sAddOffer = new AddOffer(nlOffer, ofeerFees);
                sAddOffer.Context.CustomerID = this.decisionToApply.Customer.ID;
                sAddOffer.Context.UserID     = this.decisionModel.underwriterID;

                try {
                    sAddOffer.Execute();
                    Log.Debug("nl offer added: {0}, Error: {1}", sAddOffer.OfferID, sAddOffer.Error);
                    // ReSharper disable once CatchAllClause
                } catch (Exception ex) {
                    Log.Error("Failed to AddOffer. Err: {0}", ex.Message);
                }

                // ReSharper disable once CatchAllClause
            } catch (Exception nlException) {
                Log.Error("Failed to run NL offer/decision Err: {0}", nlException.Message);
            }

            UpdateSalesForceOpportunity(OpportunityStage.s90, model => {
                model.ApprovedAmount  = (int)this.currentState.OfferedCreditLine;
                model.ExpectedEndDate = this.currentState.OfferValidUntil;
            });

            return(true);
        }        // ApproveCustomer