Example #1
0
        }         // IsDirector

        public void DetectTangibleEquity(ExperianLtd oExperianLtd, out decimal nResultTangibleEquity, out decimal nResultTotalCurrentAssets)
        {
            nResultTangibleEquity     = -1;
            nResultTotalCurrentAssets = 0;

            IEnumerable <ExperianLtdDL99> lst = oExperianLtd.GetChildren <ExperianLtdDL99>();

            ExperianLtdDL99 oCurNode = null;

            foreach (var oNode in lst)
            {
                if (!oNode.Date.HasValue)
                {
                    continue;
                }

                if (oCurNode == null)
                {
                    oCurNode = oNode;
                    continue;
                }                 // if

                // ReSharper disable PossibleInvalidOperationException
                if (oCurNode.Date.Value < oNode.Date.Value)
                {
                    oCurNode = oNode;
                }
                // ReSharper restore PossibleInvalidOperationException
            }             // for each

            if (oCurNode == null)
            {
                return;
            }

            // ReSharper disable PossibleInvalidOperationException
            Log.Debug("Calculating tangible equity from data for {0}.", oCurNode.Date.Value.ToString("MMMM d yyyy", CultureInfo.InvariantCulture));
            // ReSharper restore PossibleInvalidOperationException

            decimal nTangibleEquity     = 0;
            decimal nTotalCurrentAssets = 0;

            Action <decimal?> oPlus  = x => nTangibleEquity += x ?? 0;
            Action <decimal?> oMinus = x => nTangibleEquity -= x ?? 0;
            Action <decimal?> oSet   = x => nTotalCurrentAssets = x ?? 0;

            var oTags = new List <Tuple <decimal?, Action <decimal?> > > {
                new Tuple <decimal?, Action <decimal?> >(oCurNode.TotalShareFund, oPlus),
                new Tuple <decimal?, Action <decimal?> >(oCurNode.InTngblAssets, oMinus),
                new Tuple <decimal?, Action <decimal?> >(oCurNode.FinDirLoans, oPlus),
                new Tuple <decimal?, Action <decimal?> >(oCurNode.CredDirLoans, oPlus),
                new Tuple <decimal?, Action <decimal?> >(oCurNode.FinLbltsDirLoans, oPlus),
                new Tuple <decimal?, Action <decimal?> >(oCurNode.DebtorsDirLoans, oMinus),
                new Tuple <decimal?, Action <decimal?> >(oCurNode.OnClDirLoans, oPlus),
                new Tuple <decimal?, Action <decimal?> >(oCurNode.CurrDirLoans, oMinus),
                new Tuple <decimal?, Action <decimal?> >(oCurNode.TotalCurrAssets, oSet),
            };

            foreach (var oTag in oTags)
            {
                oTag.Item2(oTag.Item1);
            }

            var ci = new CultureInfo("en-GB", false);

            Log.Debug("Tangible equity is {0}.", nTangibleEquity.ToString("C2", ci));
            Log.Debug("Total current assets is {0}.", nTotalCurrentAssets.ToString("C2", ci));

            nResultTangibleEquity     = nTangibleEquity;
            nResultTotalCurrentAssets = nTotalCurrentAssets;
        }         // DetectTangibleEquity
        public ComapanyDashboardModel BuildLimitedDashboardModel(ExperianLtdActionResult data, ComapanyDashboardModel oModel = null)
        {
            if (oModel == null)
            {
                oModel = new ComapanyDashboardModel {
                    FinDataHistories = new List <FinDataModel>(),
                    LastFinData      = new FinDataModel(),
                    IsLimited        = true,
                    CompanyHistories = new List <CompanyHistory>()
                };
            }             // if
            var oExperianLtd = data.Value;

            oModel.CompanyName   = oExperianLtd.CompanyName;
            oModel.CompanyRefNum = oExperianLtd.RegisteredNumber;

            oModel.Score      = oExperianLtd.GetCommercialDelphiScore();
            oModel.ScoreColor = CreditBureauModelBuilder.GetScorePositionAndColor(oModel.Score, 100, 0).Color;

            oModel.CcjMonths = oExperianLtd.GetAgeOfMostRecentCCJDecreeMonths();

            oModel.Ccjs            = oExperianLtd.GetNumberOfCcjsInLast24Months();
            oModel.CcjValue        = oExperianLtd.GetSumOfCcjsInLast24Months();
            oModel.OriginationDate = oExperianLtd.GetOriginationDate();
            if (data.History != null)
            {
                foreach (ScoreAtDate scoreAtDate in data.History)
                {
                    oModel.CompanyHistories.Add(new CompanyHistory {
                        Score        = scoreAtDate.Score,
                        Date         = scoreAtDate.Date,
                        ServiceLogId = scoreAtDate.ServiceLogId,
                        Balance      = scoreAtDate.Balance
                    });
                }
            }

            List <ExperianLtdDL97> oDL97List = new List <ExperianLtdDL97>();
            List <ExperianLtdDL99> oDL99List = new List <ExperianLtdDL99>();

            foreach (var oKid in oExperianLtd.Children)
            {
                if (typeof(ExperianLtdDL97) == oKid.GetType())
                {
                    oDL97List.Add((ExperianLtdDL97)oKid);
                }
                else if (typeof(ExperianLtdDL99) == oKid.GetType())
                {
                    ExperianLtdDL99 dl99 = (ExperianLtdDL99)oKid;

                    if (dl99.Date.HasValue)
                    {
                        oDL99List.Add(dl99);
                    }
                }         // if
            }             // for each

            string worstStatusAll = "0";

            //Calc and add Cais Balance

            oModel.CaisBalance = 0;

            foreach (var cais in oDL97List)
            {
                var state   = cais.AccountState;
                var balance = cais.CurrentBalance ?? 0;

                // Sum all accounts balance that are not settled
                if (!string.IsNullOrEmpty(state) && state[0] != 'S')
                {
                    oModel.CaisBalance += balance;
                    oModel.CaisAccounts++;
                }                 // if

                if (!string.IsNullOrEmpty(state) && state[0] == 'D')
                {
                    oModel.DefaultAccounts++;
                    oModel.DefaultAmount += cais.DefaultBalance ?? 0;
                }
                else
                {
                    var status      = cais.AccountStatusLast12AccountStatuses ?? string.Empty;
                    var worstStatus = CreditBureauModelBuilder.GetWorstStatus(Regex.Split(status, string.Empty));
                    if (worstStatus != "0")
                    {
                        oModel.LateAccounts++;
                        worstStatusAll = CreditBureauModelBuilder.GetWorstStatus(worstStatusAll, worstStatus);
                    }     // if
                }         // if
            }             // for each

            string date;

            oModel.LateStatus = CreditBureauModelBuilder.GetAccountStatusString(worstStatusAll, out date, true);

            // Calc and add tangible equity and adjusted profit

            if (oDL99List.Count > 0)
            {
                // ReSharper disable PossibleInvalidOperationException
                oDL99List.Sort((a, b) => b.Date.Value.CompareTo(a.Date.Value));
                // ReSharper restore PossibleInvalidOperationException

                for (var i = 0; i < oDL99List.Count - 1; i++)
                {
                    ExperianLtdDL99 oCurItem = oDL99List[i];

                    decimal totalShareFund  = oCurItem.TotalShareFund ?? 0;
                    decimal inTngblAssets   = oCurItem.InTngblAssets ?? 0;
                    decimal debtorsDirLoans = oCurItem.DebtorsDirLoans ?? 0;
                    decimal credDirLoans    = oCurItem.CredDirLoans ?? 0;
                    decimal onClDirLoans    = oCurItem.OnClDirLoans ?? 0;

                    decimal tangibleEquity = totalShareFund - inTngblAssets - debtorsDirLoans + credDirLoans + onClDirLoans;

                    if (oDL99List.Count > 1)
                    {
                        var oNextItem = oDL99List[i + 1];

                        decimal retainedEarnings     = oCurItem.RetainedEarnings ?? 0;
                        decimal retainedEarningsPrev = oNextItem.RetainedEarnings ?? 0;
                        decimal fixedAssetsPrev      = oNextItem.TngblAssets ?? 0;

                        decimal adjustedProfit = retainedEarnings - retainedEarningsPrev + fixedAssetsPrev / 5;

                        var fin = new FinDataModel {
                            TangibleEquity = tangibleEquity,
                            AdjustedProfit = adjustedProfit,
                        };
                        oModel.FinDataHistories.Add(fin);

                        if (i == 0)
                        {
                            oModel.LastFinData = fin;
                        }
                    }     // if
                }         // for each
            }             // if DL99 has data

            return(oModel);
        }         // BuildLimitedDashboardModel