Ejemplo n.º 1
0
        public ExperianConsumerModel GenerateConsumerModel(ExperianConsumerData eInfo, Customer customer, Director director, long?logId, string name)
        {
            var model = new ExperianConsumerModel {
                ErrorList = new List <string>(),
                Id        = director != null ? director.Id : customer.Id
            };

            if (eInfo == null || eInfo.ServiceLogId == null)
            {
                model.HasExperianError = true;
                model.ErrorList.Add("No data");
                model.ApplicantFullNameAge = name;
                return(model);
            }

            var scorePosColor = GetScorePositionAndColor(eInfo.BureauScore ?? 0, ConsumerScoreMax, ConsumerScoreMin);

            model.ServiceLogId           = eInfo.ServiceLogId;
            model.HasExperianError       = eInfo.HasExperianError;
            model.ModelType              = "Consumer";
            model.CheckDate              = eInfo.InsertDate.ToShortDateString();
            model.IsDataRelevant         = (DateTime.UtcNow - eInfo.InsertDate).TotalDays < CurrentValues.Instance.UpdateConsumerDataPeriodDays;
            model.CheckValidity          = eInfo.InsertDate.AddDays(CurrentValues.Instance.UpdateConsumerDataPeriodDays).ToShortDateString();
            model.BorrowerType           = "Consumer";
            model.Score                  = eInfo.BureauScore;
            model.Odds                   = Math.Pow(2, (((double)(eInfo.BureauScore ?? 0)) - 600) / 80);
            model.ScorePosition          = scorePosColor.Position;
            model.ScoreAlign             = scorePosColor.Align;
            model.ScoreValuePosition     = scorePosColor.ValPosition;
            model.ScoreColor             = scorePosColor.Color;
            model.Applicant              = eInfo.Applicants.FirstOrDefault();
            model.Location               = eInfo.Locations.FirstOrDefault();
            model.TotalAccountBalances   = eInfo.TotalAccountBalances;
            model.TotalMonthlyRepayments = eInfo.CreditCommitmentsRevolving + eInfo.CreditCommitmentsNonRevolving +
                                           eInfo.MortgagePayments;
            model.CreditCardBalances = eInfo.CreditCardBalances;

            if (model.Applicant != null)
            {
                var days = model.Applicant.DateOfBirth.HasValue ? (DateTime.UtcNow - model.Applicant.DateOfBirth.Value).TotalDays : 0;
                var age  = (int)Math.Round(days / 365);
                model.ApplicantFullNameAge = string.Format("{0} {1} {2} {3} {4} {5}",
                                                           model.Applicant.Title,
                                                           model.Applicant.Forename,
                                                           model.Applicant.MiddleName,
                                                           model.Applicant.Surname,
                                                           model.Applicant.Suffix,
                                                           age);
            }
            if (eInfo.Applicants.Count > 1)
            {
                Errors.Add("More than one applicant specified");
            }

            if (eInfo.Locations.Count > 1)
            {
                Errors.Add("More than one locations specified");
            }

            model.CII = eInfo.CII;
            if (!string.IsNullOrEmpty(eInfo.Error))
            {
                model.ErrorList.AddRange(eInfo.Error.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
            }

            model.NumberOfAccounts           = 0;
            model.NumberOfAccounts3M         = 0;
            model.WorstCurrentStatus         = AccountStatusDictionary.GetAccountStatus(eInfo.WorstCurrentStatus).LongDescription;
            model.WorstCurrentStatus3M       = AccountStatusDictionary.GetAccountStatus(eInfo.WorstHistoricalStatus).LongDescription;
            model.EnquiriesLast3M            = eInfo.EnquiriesLast3Months;
            model.EnquiriesLast6M            = eInfo.EnquiriesLast6Months;
            model.NumberOfDefaults           = 0;
            model.NumberOfCCOverLimit        = eInfo.CreditCardOverLimit;
            model.CreditCardUtilization      = eInfo.CreditLimitUtilisation;
            model.NOCsOnCCJ                  = eInfo.NOCsOnCCJ;
            model.NOCsOnCAIS                 = eInfo.NOCsOnCAIS;
            model.NumberOfCCJs               = eInfo.NumCCJs;
            model.TotalCCJValueStr           = GetClass1String(eInfo.TotalCCJValue1);
            model.TotalCCJValue              = (eInfo.TotalCCJValue1.HasValue && eInfo.TotalCCJValue1.Value > 0) ? eInfo.TotalCCJValue1.Value * 100 : (int?)null;
            model.SatisfiedJudgements        = eInfo.SatisfiedJudgement;
            model.AgeOfMostRecentCCJ         = eInfo.CCJLast2Years;
            model.CAISSpecialInstructionFlag = eInfo.CAISSpecialInstructionFlag;

            model.ConsumerAccountsOverview = new ConsumerAccountsOverview();
            var accList = new List <AccountInfo>();

            var years      = new List <AccountDisplayedYear>();
            var quarters   = new List <AccountDisplayedQuarter>();
            var monthsList = new List <string>();

            var displayedMonths = new List <DateTime>();
            var mthStart        = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);

            for (int i = 1 - StatusHistoryMonths; i <= 0; i++)
            {
                var date = mthStart.AddMonths(i);
                displayedMonths.Add(date);
                var monthYear = date.Year;
                var monthQ    = (date.Month - 1) / 3 + 1;
                var monthQStr = string.Format("Q{0}", monthQ);
                var month     = date.Month;
                if ((years.Count > 0) && (years[years.Count - 1].Year == monthYear))
                {
                    years[years.Count - 1].Span++;
                }
                else
                {
                    years.Add(new AccountDisplayedYear {
                        Year = date.Year, Span = 1
                    });
                }

                if ((quarters.Count > 0) && (quarters[quarters.Count - 1].Quarter == monthQStr))
                {
                    quarters[quarters.Count - 1].Span++;
                }
                else
                {
                    quarters.Add(new AccountDisplayedQuarter {
                        Quarter = monthQStr, Span = 1
                    });
                }
                monthsList.Add(month.ToString("00"));
            }

            var numberOfAccounts = 0;
            var numberOfAcc3M    = 0;

            // 0 - CC, 1 - Mortgage, 2 - PL, 3 - other
            var    accounts         = new[] { 0, 0, 0, 0 };
            var    worstStatus      = new[] { "0", "0", "0", "0" };
            var    limits           = new[] { 0, 0, 0, 0 };
            var    balances         = new[] { 0, 0, 0, 0 };
            int    numberOfDefaults = 0;
            int    defaultAmount    = 0;
            int    numberOfLates    = 0;
            string lateStatus       = "0";

            foreach (var caisDetails in eInfo.Cais)
            {
                var accountInfo = new AccountInfo();
                //check which acccount type show
                Variables?var = null;
                if (caisDetails.MatchTo.HasValue)
                {
                    var = map[caisDetails.MatchTo.Value];

                    var isShowThisFinancinalAccount = CurrentValues.Instance[var.Value];
                    if (isShowThisFinancinalAccount == null || !isShowThisFinancinalAccount)
                    {
                        continue;
                    }

                    accountInfo.MatchTo = var.DescriptionAttr();
                }
                accountInfo.OpenDate = caisDetails.CAISAccStartDate;
                accountInfo.Account  = AccountTypeDictionary.GetAccountType(caisDetails.AccountType);
                var    accStatus = caisDetails.AccountStatus;
                string dateType;
                accountInfo.AccountStatus = GetAccountStatusString(accStatus, out dateType);
                accountInfo.DateType      = dateType;
                if (accStatus == DefaultCaisStatusName && var == Variables.FinancialAccounts_MainApplicant)
                {
                    numberOfDefaults++;
                    defaultAmount += caisDetails.CurrentDefBalance ?? 0;
                }

                var accType = GetAccountType(caisDetails.AccountType);
                if (accType < 0)
                {
                    continue;
                }

                if (((accStatus == DelinquentCaisStatusName) || (accStatus == ActiveCaisStatusName)) && var == Variables.FinancialAccounts_MainApplicant)
                {
                    accounts[accType]++;
                    var ws     = caisDetails.WorstStatus;
                    var status = AccountStatusDictionary.GetAccountStatus(ws);
                    worstStatus[accType] = GetWorstStatus(worstStatus[accType], ws);
                    limits[accType]     += caisDetails.CreditLimit ?? 0;
                    balances[accType]   += caisDetails.Balance ?? 0;

                    numberOfAccounts++;
                    if ((accountInfo.OpenDate.HasValue) && (accountInfo.OpenDate.Value >= DateTime.Today.AddMonths(-3)))
                    {
                        numberOfAcc3M++;
                    }

                    if (status.IsLate)
                    {
                        numberOfLates++;
                        lateStatus = GetWorstStatus(lateStatus, ws);
                    }
                }

                string statuses = caisDetails.AccountStatusCodes ?? string.Empty;
                var    sList    = new List <AccountStatus>();
                for (int i = 0; i < StatusHistoryMonths; i++)
                {
                    sList.Add(new AccountStatus {
                        Status = "", StatusColor = "white"
                    });
                }

                accountInfo.SettlementDate = caisDetails.SettlementDate ?? caisDetails.LastUpdatedDate;

                if (accountInfo.SettlementDate.HasValue)
                {
                    var histStart = new DateTime(accountInfo.SettlementDate.Value.Year, accountInfo.SettlementDate.Value.Month, 1);

                    for (int i = 0; i < caisDetails.AccountStatusCodes.Length; i++)
                    {
                        var    histDate  = histStart.AddMonths(-i);
                        string indicator = (statuses.Length > i) ? statuses.Substring(i, 1) : string.Empty;
                        var    idx       = displayedMonths.IndexOf(histDate);
                        if (idx >= 0)
                        {
                            var status = AccountStatusDictionary.GetAccountStatus(indicator);
                            sList[idx].Status      = status.ShortDescription;
                            sList[idx].StatusColor = status.Color;
                        }
                    }
                }
                accountInfo.LatestStatuses    = sList.ToArray();
                accountInfo.TermAndfreq       = GetRepaymentPeriodString(caisDetails.RepaymentPeriod);
                accountInfo.Limit             = caisDetails.CreditLimit;
                accountInfo.AccBalance        = caisDetails.Balance;
                accountInfo.CurrentDefBalance = caisDetails.CurrentDefBalance;

                foreach (var cardHistory in caisDetails.CardHistories)
                {
                    accountInfo.CashWithdrawals = string.Format("{0} ({1})", cardHistory.NumCashAdvances, cardHistory.CashAdvanceAmount);
                    accountInfo.MinimumPayment  = cardHistory.PaymentCode ?? string.Empty;
                    break;
                }

                accountInfo.Years           = years.ToArray();
                accountInfo.Quarters        = quarters.ToArray();
                accountInfo.MonthsDisplayed = monthsList.ToArray();

                if (caisDetails.AccountBalances.Any(x => x.AccountBalance.HasValue))
                {
                    accountInfo.BalanceHistory = caisDetails.AccountBalances
                                                 .Where(x => x.AccountBalance.HasValue)
                                                 .Select(x => x.AccountBalance.Value.ToString(CultureInfo.InvariantCulture))
                                                 .Reverse()
                                                 .Aggregate((a, b) => a + "," + b);
                }
                accList.Add(accountInfo);
            }

            model.NumberOfAccounts   = numberOfAccounts;
            model.NumberOfAccounts3M = numberOfAcc3M;
            model.NumberOfDefaults   = numberOfDefaults;
            model.NumberOfLates      = numberOfLates;
            model.LateStatus         = AccountStatusDictionary.GetAccountStatus(lateStatus).LongDescription;
            model.DefaultAmount      = defaultAmount;

            Log.DebugFormat("Accounts List length: {0}", accList.Count);
            accList.Sort(new AccountInfoComparer());

            model.AccountsInformation = accList.ToArray();

            model.ConsumerAccountsOverview.OpenAccounts_CC    = accounts[0];
            model.ConsumerAccountsOverview.OpenAccounts_Mtg   = accounts[1];
            model.ConsumerAccountsOverview.OpenAccounts_PL    = accounts[2];
            model.ConsumerAccountsOverview.OpenAccounts_Other = accounts[3];
            model.ConsumerAccountsOverview.OpenAccounts_Total = accounts.Sum();

            model.ConsumerAccountsOverview.WorstArrears_CC    = AccountStatusDictionary.GetAccountStatus(worstStatus[0]).LongDescription;
            model.ConsumerAccountsOverview.WorstArrears_Mtg   = AccountStatusDictionary.GetAccountStatus(worstStatus[1]).LongDescription;
            model.ConsumerAccountsOverview.WorstArrears_PL    = AccountStatusDictionary.GetAccountStatus(worstStatus[2]).LongDescription;
            model.ConsumerAccountsOverview.WorstArrears_Other = AccountStatusDictionary.GetAccountStatus(worstStatus[3]).LongDescription;
            model.ConsumerAccountsOverview.WorstArrears_Total = AccountStatusDictionary.GetAccountStatus(GetWorstStatus(worstStatus)).LongDescription;

            model.ConsumerAccountsOverview.TotalCurLimits_CC    = limits[0];
            model.ConsumerAccountsOverview.TotalCurLimits_Mtg   = limits[1];
            model.ConsumerAccountsOverview.TotalCurLimits_PL    = limits[2];
            model.ConsumerAccountsOverview.TotalCurLimits_Other = limits[3];
            model.ConsumerAccountsOverview.TotalCurLimits_Total = limits.Sum();

            model.ConsumerAccountsOverview.Balance_CC    = balances[0];
            model.ConsumerAccountsOverview.Balance_Mtg   = balances[1];
            model.ConsumerAccountsOverview.Balance_PL    = balances[2];
            model.ConsumerAccountsOverview.Balance_Other = balances[3];
            model.ConsumerAccountsOverview.Balance_Total = balances.Sum();
            model.NOCs = eInfo.Nocs.Select(nocDetails => new NOCInfo {
                NOCReference = nocDetails.Reference, NOCLines = nocDetails.TextLine
            }).ToArray();

            Log.DebugFormat("Error List: {0}", PrintErrorList(model.ErrorList));

            using (this.tc.AddStep("GetConsumerHistoryModel time taken")) {
                model.ConsumerHistory = GetConsumerHistoryModel(customer, director);
            }
            return(model);
        }
Ejemplo n.º 2
0
        }         // GetConsumerInfo

        private void SaveDefaultAccountIntoDb(OutputRoot output, int customerId, MP_ServiceLog serviceLog)
        {
            var customerRepo = ObjectFactory.GetInstance <CustomerRepository>();

            var customer = customerRepo.Get(customerId);

            OutputFullConsumerDataConsumerDataCAIS[] cais = null;

            TryRead(() => cais = output.Output.FullConsumerData.ConsumerData.CAIS);

            if (cais == null)
            {
                return;
            }

            var dateAdded = DateTime.UtcNow;
            var repo      = ObjectFactory.GetInstance <NHibernateRepositoryBase <ExperianDefaultAccount> >();

            foreach (var caisData in cais)
            {
                if (caisData.CAISDetails == null)
                {
                    continue;
                }
                foreach (var detail in caisData.CAISDetails.Where(detail => detail.AccountStatus == "F"))
                {
                    int relevantYear, relevantMonth, relevantDay;

                    if (detail.SettlementDate != null)
                    {
                        relevantYear  = detail.SettlementDate.CCYY;
                        relevantMonth = detail.SettlementDate.MM;
                        relevantDay   = detail.SettlementDate.DD;
                    }
                    else
                    {
                        relevantYear  = detail.LastUpdatedDate.CCYY;
                        relevantMonth = detail.LastUpdatedDate.MM;
                        relevantDay   = detail.LastUpdatedDate.DD;
                    }                     // if

                    var settlementDate    = new DateTime(relevantYear, relevantMonth, relevantDay);
                    var currentDefBalance = 0;
                    var balance           = 0;
                    var reg        = new Regex("[^0-9,]");
                    var tempDetail = detail;

                    TryRead(() =>
                            int.TryParse(reg.Replace(tempDetail.CurrentDefBalance.Amount, ""), out currentDefBalance)
                            );

                    TryRead(() => int.TryParse(reg.Replace(tempDetail.Balance.Amount, ""), out balance));

                    var eda = new ExperianDefaultAccount {
                        AccountType       = AccountTypeDictionary.GetAccountType(detail.AccountType ?? string.Empty),
                        Date              = settlementDate,
                        DelinquencyType   = "Default",
                        Customer          = customer,
                        DateAdded         = dateAdded,
                        CurrentDefBalance = currentDefBalance,
                        Balance           = balance,
                        ServiceLog        = serviceLog,
                    };

                    m_oRetryer.Retry(() => repo.SaveOrUpdate(eda));
                } // foreach detail in cais datum
            }     // foreach cais datum in cais data
        }         // SaveDefaultAccountIntoDb