Ejemplo n.º 1
0
        private MedalDetail BuildNewCharecteristics(MedalCalculations medal)
        {
            var detail = new MedalDetail {
                Score = BuildNewScore(medal),
                MedalCharacteristics = new List <MedalCharacteristic>()
            };

            DateTime?businessSeniority    = medal.BusinessSeniority;
            string   businessSeniorityStr = businessSeniority.HasValue ? businessSeniority.Value.ToString("yyyy-MM-dd") : null;

            DateTime?regDate           = medal.EzbobSeniority;
            string   ezbobSeniorityStr = regDate.HasValue ? regDate.Value.ToString("yyyy-MM-dd") : null;

            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Business Score", Value = medal.BusinessScore.ToString("N0"), WeightUsed = medal.BusinessScoreWeight, Score = medal.BusinessScoreScore, Grade = (int)medal.BusinessScoreGrade
            });
            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Free Cash Flow", Value = medal.FreeCashFlow.ToString("N2"), WeightUsed = medal.FreeCashFlowWeight, Score = medal.FreeCashFlowScore, Grade = (int)medal.FreeCashFlowGrade
            });
            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Annual Turnover", Value = medal.AnnualTurnover.ToString("N2"), WeightUsed = medal.AnnualTurnoverWeight, Score = medal.AnnualTurnoverScore, Grade = (int)medal.AnnualTurnoverGrade
            });
            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Tangible Equity", Value = medal.TangibleEquity.ToString("N2"), WeightUsed = medal.TangibleEquityWeight, Score = medal.TangibleEquityScore, Grade = (int)medal.TangibleEquityGrade
            });
            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Business Seniority", Value = businessSeniorityStr, WeightUsed = medal.BusinessSeniorityWeight, Score = medal.BusinessSeniorityScore, Grade = (int)medal.BusinessSeniorityGrade
            });
            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Consumer Score", Value = medal.ConsumerScore.ToString("N0"), WeightUsed = medal.ConsumerScoreWeight, Score = medal.ConsumerScoreScore, Grade = (int)medal.ConsumerScoreGrade
            });
            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Net Worth", Value = medal.NetWorth.ToString("N2"), WeightUsed = medal.NetWorthWeight, Score = medal.NetWorthScore, Grade = (int)medal.NetWorthGrade
            });
            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Marital Status", Value = medal.MaritalStatus, WeightUsed = medal.MaritalStatusWeight, Score = medal.MaritalStatusScore, Grade = (int)medal.MaritalStatusGrade
            });
            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Num Of Loans", Value = medal.NumOfLoans.ToString("N0"), WeightUsed = medal.NumOfLoansWeight, Score = medal.NumOfLoansScore, Grade = (int)medal.NumOfLoansGrade
            });
            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Num Of Early Repayments", Value = medal.NumOfEarlyRepayments.ToString("N0"), WeightUsed = medal.NumOfEarlyRepaymentsWeight, Score = medal.NumOfEarlyRepaymentsScore, Grade = (int)medal.NumOfEarlyRepaymentsGrade
            });
            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Num Of Late Repayments", Value = medal.NumOfLateRepayments.ToString("N0"), WeightUsed = medal.NumOfLateRepaymentsWeight, Score = medal.NumOfLateRepaymentsScore, Grade = (int)medal.NumOfLateRepaymentsGrade
            });
            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Num Of Stores", Value = medal.NumberOfStores.ToString("N0"), WeightUsed = medal.NumberOfStoresWeight, Score = medal.NumberOfStoresScore, Grade = (int)medal.NumberOfStoresGrade
            });
            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Positive Feedbacks", Value = medal.PositiveFeedbacks.ToString("N0"), WeightUsed = medal.PositiveFeedbacksWeight, Score = medal.PositiveFeedbacksScore, Grade = (int)medal.PositiveFeedbacksGrade
            });
            detail.MedalCharacteristics.Add(new MedalCharacteristic {
                CustomerCharacteristic = "Ezbob Seniority", Value = ezbobSeniorityStr, WeightUsed = medal.EzbobSeniorityWeight, Score = medal.EzbobSeniorityScore, Grade = (int)medal.EzbobSeniorityGrade
            });

            GetTotal(detail);

            return(detail);
        }
Ejemplo n.º 2
0
 private Score BuildNewScore(MedalCalculations medalCalculation)
 {
     return(new Score
     {
         MedalType = medalCalculation.MedalType,
         Medal = medalCalculation.Medal,
         Points = (double)medalCalculation.TotalScore,
         Result = (double)medalCalculation.TotalScoreNormalized,
         Date = medalCalculation.CalculationTime,
         Error = medalCalculation.Error,
         OfferedAmount = medalCalculation.OfferedLoanAmount,
         MaxOfferedLoanAmount = medalCalculation.MaxOfferedLoanAmount
     });
 }
Ejemplo n.º 3
0
        }         // BuildMultiBrandAlert

        private void BuildAlerts(ProfileSummaryModel summary, Customer customer)
        {
            TimeCounter tc = new TimeCounter("BuildAlerts building time for customer " + customer.Id);

            summary.Alerts = new AlertsModel {
                Errors   = new List <AlertModel>(),
                Warnings = new List <AlertModel>(),
                Infos    = new List <AlertModel>(),
            };

            using (tc.AddStep("BuildMultiBrandAlert Time taken")) {
                BuildMultiBrandAlert(customer.Id, summary.Alerts);
            }

            using (tc.AddStep("CustomerAlerts Time taken")) {
                var isBrokerRegulated = (customer.Broker != null) && customer.Broker.FCARegistered;

                var IsWizardComplete = (customer.WizardStep != null) && customer.WizardStep.TheLastOne;

                if (!isBrokerRegulated && customer.PersonalInfo.IsRegulated && IsWizardComplete)
                {
                    summary.Alerts.Infos.Add(new AlertModel {
                        Abbreviation = "NRB",
                        Alert        = "Regulated customer for a Non-Regulated broker",
                        AlertType    = AlertType.Warning.DescriptionAttr(),
                        Tab          = ProfileTab.Dashboard.DescriptionAttr()
                    });
                }                 // if

                if (customer.IsTest)
                {
                    summary.Alerts.Infos.Add(new AlertModel {
                        Abbreviation = "Test",
                        Alert        = "Is test",
                        AlertType    = AlertType.Info.DescriptionAttr(),
                        Tab          = ProfileTab.Dashboard.DescriptionAttr()
                    });
                }                 // if

                if (customer.IsAlibaba)
                {
                    summary.Alerts.Infos.Add(new AlertModel {
                        Abbreviation = "Ali",
                        Alert        = "Is alibaba customer",
                        AlertType    = AlertType.Info.DescriptionAttr(),
                        Tab          = ProfileTab.Dashboard.DescriptionAttr()
                    });
                }                 // if

                if (customer.CciMark)
                {
                    summary.Alerts.Errors.Add(new AlertModel {
                        Abbreviation = "CCI",
                        Alert        = "CCI Mark",
                        AlertType    = AlertType.Error.DescriptionAttr(),
                        Tab          = ProfileTab.Dashboard.DescriptionAttr()
                    });
                }                 // if

                if (customer.CollectionStatus.IsDefault || customer.CollectionStatus.Name == "Bad")
                {
                    summary.Alerts.Errors.Add(new AlertModel {
                        Abbreviation = "Bad",
                        Alert        = string.Format("Customer Status : {0}", customer.CollectionStatus.Name),
                        AlertType    = AlertType.Error.DescriptionAttr(),
                        Tab          = ProfileTab.Dashboard.DescriptionAttr()
                    });
                }
                else if (customer.CollectionStatus.Name == "Risky")
                {
                    summary.Alerts.Warnings.Add(new AlertModel {
                        Abbreviation = "Risky",
                        Alert        = string.Format("Customer Status : {0}", customer.CollectionStatus.Name),
                        AlertType    = AlertType.Warning.DescriptionAttr(),
                        Tab          = ProfileTab.Dashboard.DescriptionAttr()
                    });
                }                 // if

                if (customer.FraudStatus != FraudStatus.Ok)
                {
                    summary.Alerts.Errors.Add(new AlertModel {
                        Abbreviation = "F",
                        Alert        = string.Format("Fraud Status : {0}", customer.FraudStatus.DescriptionAttr()),
                        AlertType    = AlertType.Error.DescriptionAttr(),
                        Tab          = ProfileTab.FraudDetection.DescriptionAttr()
                    });
                }                 // if

                if (customer.CreditResult == CreditResultStatus.PendingInvestor)
                {
                    summary.Alerts.Warnings.Add(new AlertModel {
                        Abbreviation = "PI",
                        Alert        = string.Format("Credit Result : {0}", customer.CreditResult.DescriptionAttr()),
                        AlertType    = AlertType.Warning.DescriptionAttr(),
                        Tab          = ProfileTab.Dashboard.DescriptionAttr()
                    });
                }                 // if

                switch (customer.AMLResult)
                {
                case "Rejected":
                    summary.Alerts.Errors.Add(new AlertModel {
                        Abbreviation = "AML",
                        Alert        = string.Format("AML Status : {0}", customer.AMLResult),
                        AlertType    = AlertType.Error.DescriptionAttr(),
                        Tab          = ProfileTab.CreditBureau.DescriptionAttr()
                    });
                    break;

                case "Not performed":
                case "Warning":
                    summary.Alerts.Warnings.Add(new AlertModel {
                        Abbreviation = "AML",
                        Alert        = string.Format("AML Status : {0}", customer.AMLResult),
                        AlertType    = AlertType.Warning.DescriptionAttr(),
                        Tab          = ProfileTab.CreditBureau.DescriptionAttr()
                    });
                    break;
                }                 // switch

                switch (summary.CreditBureau.ThinFile)
                {
                case "Yes":
                    summary.Alerts.Errors.Add(new AlertModel {
                        Abbreviation = "TF",
                        Alert        = "Thin file",
                        AlertType    = AlertType.Error.DescriptionAttr(),
                        Tab          = ProfileTab.CreditBureau.DescriptionAttr()
                    });
                    break;

                case "N/A":
                    summary.Alerts.Warnings.Add(new AlertModel {
                        Abbreviation = "N/A",
                        Alert        = "Couldn't get financial accounts",
                        AlertType    = AlertType.Warning.DescriptionAttr(),
                        Tab          = ProfileTab.Dashboard.DescriptionAttr()
                    });
                    break;
                }                 // switch

                if (summary.CreditBureau.NumDirectorThinFiles > 0)
                {
                    summary.Alerts.Errors.Add(new AlertModel {
                        Abbreviation = "TF",
                        Alert        =
                            string.Format("{0} director{1} with thin file", summary.CreditBureau.NumDirectorThinFiles,
                                          summary.CreditBureau.NumDirectorThinFiles == 1 ? "" : "s"),
                        AlertType = AlertType.Error.DescriptionAttr(),
                        Tab       = ProfileTab.Dashboard.DescriptionAttr()
                    });
                }                 // if

                if (summary.CreditBureau.NumDirectorNA > 0)
                {
                    summary.Alerts.Warnings.Add(new AlertModel {
                        Abbreviation = "N/A",
                        Alert        =
                            string.Format("{0} director{1} with no experian data available", summary.CreditBureau.NumDirectorNA,
                                          summary.CreditBureau.NumDirectorThinFiles == 1 ? "" : "s"),
                        AlertType = AlertType.Warning.DescriptionAttr(),
                        Tab       = ProfileTab.Dashboard.DescriptionAttr()
                    });
                }                 // if

                if (summary.CreditBureau.ApplicantDOBs != null)
                {
                    foreach (var dob in summary.CreditBureau.ApplicantDOBs)
                    {
                        if (dob.HasValue && (dob.Value.AddYears(18) > DateTime.Today))
                        {
                            summary.Alerts.Errors.Add(new AlertModel {
                                Abbreviation = "A",
                                Alert        = "Age of applicant under 18",
                                AlertType    = AlertType.Error.DescriptionAttr(),
                                Tab          = ProfileTab.Dashboard.DescriptionAttr()
                            });
                        }         // if
                    }             // for each
                }                 // if

                if (customer.CustomerRelationStates.Any())
                {
                    var state = customer.CustomerRelationStates.First();
                    if (state.IsFollowUp.HasValue && state.IsFollowUp.Value && state.FollowUp.FollowUpDate <= DateTime.UtcNow)
                    {
                        summary.Alerts.Errors.Add(new AlertModel {
                            Abbreviation = "Follow",
                            Alert        = "Customer relations follow up date is due " + state.FollowUp.FollowUpDate.ToString("dd/MM/yyyy"),
                            AlertType    = AlertType.Error.DescriptionAttr(),
                            Tab          = ProfileTab.CustomerRelations.DescriptionAttr()
                        });
                    }             // if
                }                 // if
            }

            using (tc.AddStep("GetCompanySeniorityAlerts Time taken")) {
                try {
                    if (customer.PersonalInfo != null)
                    {
                        DateTime?companySeniority =
                            this.serviceClient.Instance.GetCompanySeniority(customer.Id,
                                                                            customer.PersonalInfo.TypeOfBusiness.Reduce() ==
                                                                            TypeOfBusinessReduced.Limited, this.context.UserId)
                            .Value;
                        if (companySeniority.HasValue && companySeniority.Value.AddYears(1) > DateTime.UtcNow &&
                            (companySeniority.Value.Year != DateTime.UtcNow.Year || companySeniority.Value.Month != DateTime.UtcNow.Month ||
                             companySeniority.Value.Day != DateTime.UtcNow.Day))
                        {
                            summary.Alerts.Errors.Add(new AlertModel {
                                Abbreviation = "YC",
                                Alert        = "Young company. Incorporation date: " + companySeniority.Value.ToString("dd/MM/yyyy"),
                                AlertType    = AlertType.Error.DescriptionAttr(),
                                Tab          = ProfileTab.CompanyScore.DescriptionAttr()
                            });
                        }
                    }
                } catch (Exception e) {
                    log.Debug(e, "Error fetching company seniority.");
                }                 // try
            }
            using (tc.AddStep("BuildLandRegistryAlerts Time taken")) {
                bool bResult = BuildLandRegistryAlerts(customer, summary);
                log.Debug("Just FYI: BuildLandRegistryAlerts() returned {0}", bResult ? "true" : "false");
            }
            using (tc.AddStep("BuildDataAlerts Time taken")) {
                BuildDataAlerts(customer, summary);
            }
            using (tc.AddStep("BuildCompanyCaisAlerts Time taken")) {
                BuildCompanyCaisAlerts(customer, summary, this.context.UserId);
            }
            using (tc.AddStep("LoadExperianConsumerMortgageData Time taken")) {
                bool hasMortgage = false;
                bool isHomeOwner = customer.PropertyStatus != null && (customer.PropertyStatus.IsOwnerOfMainAddress || customer.PropertyStatus.IsOwnerOfOtherProperties);
                try {
                    hasMortgage = this.serviceClient.Instance.LoadExperianConsumerMortgageData(this.context.UserId, customer.Id)
                                  .Value.NumMortgages > 0;
                } catch (Exception e) {
                    log.Debug(e, "Error fetching customer's mortgages.");
                }                 // try

                if (isHomeOwner && !hasMortgage)
                {
                    summary.Alerts.Warnings.Add(new AlertModel {
                        Abbreviation = "MTG",
                        Alert        = "Home owner and no mortgages",
                        AlertType    = AlertType.Warning.DescriptionAttr(),
                        Tab          = ProfileTab.Properties.DescriptionAttr()
                    });
                }
                else if (!isHomeOwner && hasMortgage)
                {
                    summary.Alerts.Warnings.Add(new AlertModel {
                        Abbreviation = "MTG",
                        Alert        = "Has mortgages but not a home owner",
                        AlertType    = AlertType.Warning.DescriptionAttr(),
                        Tab          = ProfileTab.Properties.DescriptionAttr()
                    });
                }                 // if
            }
            using (tc.AddStep("MedalAlerts Time taken")) {
                this.medalCalculationsRepository = ObjectFactory.GetInstance <MedalCalculationsRepository>();
                MedalCalculations medalCalculationsRecord = this.medalCalculationsRepository.GetActiveMedal(customer.Id);

                if (customer.Company != null && (customer.Company.TypeOfBusiness == EZBob.DatabaseLib.Model.Database.TypeOfBusiness.LLP || customer.Company.TypeOfBusiness == EZBob.DatabaseLib.Model.Database.TypeOfBusiness.Limited) && customer.CustomerMarketPlaces.Count(x => x.Marketplace.Name == "HMRC") < 2)
                {
                    // The customer should have medal
                    if (medalCalculationsRecord == null)
                    {
                        summary.Alerts.Errors.Add(new AlertModel {
                            Abbreviation = "MDL",
                            Alert        = "New medal was not calculated",
                            AlertType    = AlertType.Error.DescriptionAttr(),
                            Tab          = ProfileTab.Calculator.DescriptionAttr()
                        });
                    }
                    else if (!string.IsNullOrEmpty(medalCalculationsRecord.Error))
                    {
                        summary.Alerts.Errors.Add(new AlertModel {
                            Abbreviation = "MDL",
                            Alert        = string.Format("Error while calculating new medal: {0}", medalCalculationsRecord.Error),
                            AlertType    = AlertType.Error.DescriptionAttr(),
                            Tab          = ProfileTab.Calculator.DescriptionAttr()
                        });
                    }                     // if
                }
                else if (customer.Company != null && (customer.Company.TypeOfBusiness != EZBob.DatabaseLib.Model.Database.TypeOfBusiness.LLP &&
                                                      customer.Company.TypeOfBusiness != EZBob.DatabaseLib.Model.Database.TypeOfBusiness.Limited) ||
                         customer.CustomerMarketPlaces.Count(x => x.Marketplace.Name == "HMRC") > 1)
                {
                    summary.Alerts.Infos.Add(new AlertModel {
                        Abbreviation = "MDL",
                        Alert        = "This customer shouldn't have new medal",
                        AlertType    = AlertType.Info.DescriptionAttr(),
                        Tab          = ProfileTab.Calculator.DescriptionAttr()
                    });
                } // if
            }     //MedalAlerts
            log.Info(tc.ToString());
        }         // BuildAlerts