Esempio n. 1
0
        public void LoanFullyPaid()
        {
            var s = new LoanFullyPaid(3060, "fdsfdf");

            s.Execute();
        }
Esempio n. 2
0
        public override void Execute()
        {
            SafeReader sr = DB.GetFirst(
                "GetLoanStatus",
                CommandSpecies.StoredProcedure,
                new QueryParameter("LoanId", this.loanID)
                );

            //TODO in the futuere replace with this call.
            //var numOfActiveLoans = DB.ExecuteScalar<long>(
            //"NL_GetNumOfActiveLoans",
            //CommandSpecies.StoredProcedure,
            //new QueryParameter("CustomerID", this.customerID));

            //SafeReader sr = DB.GetFirst(
            //    "NL_LoanStatusGet",
            //    CommandSpecies.StoredProcedure,
            //    new QueryParameter("LoanId", this.loanID)
            //);

            if ((this.balance == null) || (this.isPaidOff == null))
            {
                this.balance = sr["Balance"];
                string loanStatus = sr["Status"];
                this.isPaidOff = (loanStatus == "PaidOff");
            }

            bool     wasLate          = sr["WasLate"];
            decimal  loanAmount       = sr["LoanAmount"];
            string   loanRefNum       = sr["RefNum"];
            int      numOfActiveLoans = sr["NumOfActiveLoans"];
            DateTime loanDate         = sr["LoanDate"];
            DateTime now = DateTime.UtcNow;
            double   monthsSinceLoanWasTaken = (now - loanDate).TotalDays / (365.0 / 12.0);

            this.origin = sr["Origin"];
            Log.Info("LoanStatusAfterPayment customer {0}, loan {1}, is paid off {2}, loan amount {3}, balance {4}, paid {5}, was late {6}, numOfActiveLoans {7}, monthsSinceLoanWasTaken {8}",
                     this.customerID, this.loanID, this.isPaidOff, loanAmount, this.balance, this.paymentAmount, wasLate, numOfActiveLoans, monthsSinceLoanWasTaken);

            if ((bool)this.isPaidOff)
            {
                if (!wasLate &&
                    numOfActiveLoans < CurrentValues.Instance.NumofAllowedActiveLoans &&
                    monthsSinceLoanWasTaken > CurrentValues.Instance.MinLoanLifetimeMonths)
                {
                    SalesForce.AddOpportunity addOpportunity = new AddOpportunity(this.customerID, new OpportunityModel {
                        CreateDate = DateTime.UtcNow,
                        Email      = this.customerEmail,
                        Origin     = this.origin,
                        Stage      = OpportunityStage.s5.DescriptionAttr(),
                        Type       = OpportunityType.FinishLoan.DescriptionAttr(),
                        Name       = this.customerEmail + OpportunityType.FinishLoan.DescriptionAttr()
                    });
                    addOpportunity.Execute();
                }

                if (this.sendMail)
                {
                    LoanFullyPaid loanFullyPaid = new LoanFullyPaid(this.customerID, loanRefNum);
                    loanFullyPaid.Execute();
                }
            }
            else
            {
                decimal       repaidPercent = (decimal)(loanAmount == 0 ? 0 : (loanAmount - this.balance) / loanAmount);
                decimal       repaidPercentBeforePayment = (decimal)(loanAmount == 0 ? 0 : (loanAmount - this.balance - this.paymentAmount) / loanAmount);
                const decimal fiftyPercent = 0.5M;
                if (repaidPercent >= fiftyPercent &&
                    repaidPercentBeforePayment < fiftyPercent &&
                    !wasLate &&
                    numOfActiveLoans < CurrentValues.Instance.NumofAllowedActiveLoans &&
                    monthsSinceLoanWasTaken > CurrentValues.Instance.MinLoanLifetimeMonths)
                {
                    AddSalesForceFiftyPercentOpportunity();
                } //if
            }     //if
        }         //Execute