Ejemplo n.º 1
0
		public HmrcIsOfBusiness(DecisionStatus nDecisionStatus) : base(nDecisionStatus) {} // constructor
		
		/// <summary>
		/// Init if has HMRC.
		/// </summary>
		public void Init(List<NameForComparison> hmrcBusinessName, NameForComparison experianCompanyName) {
			Comment = string.Format(
				"HMRC business name: '{0}', experian business name: '{1}'", 
				hmrcBusinessName.Select(n => n.RawName).Aggregate((a, b) => string.Format("{0},{1}", a, b)),
				experianCompanyName.RawName
			);
		} // Init
            }                       // StructToSave

            public void SetOtherNameAndBelongs(NameForComparison companyName, string fullName)
            {
                CompanyName = companyName;
                FullName    = fullName;

                BelongsToCustomer = Name.SameAsCompany(CompanyName);

                if (BelongsToCustomer.Value)
                {
                    return;
                }

                BelongsToCustomer = Name.SameAsPerson(fullName);
            }             // SetOtherNameAndBelongs
Ejemplo n.º 3
0
        }         // constructor

        public Approval Init()
        {
            using (this.trail.AddCheckpoint(ProcessCheckpoints.Initializtion)) {
                var stra = new LoadExperianConsumerData(this.trail.CustomerID, null, null);
                stra.Execute();

                this.experianConsumerData = stra.Result;

                if (this.customer == null)
                {
                    this.isBrokerCustomer = false;
                }
                else
                {
                    this.isBrokerCustomer = this.customer.Broker != null;
                }

                bool hasLtd =
                    (this.customer != null) &&
                    (this.customer.Company != null) &&
                    (this.customer.Company.TypeOfBusiness.Reduce() == TypeOfBusinessReduced.Limited) &&
                    (this.customer.Company.ExperianRefNum != "NotFound");

                if (hasLtd)
                {
                    var limited = new LoadExperianLtd(this.customer.Company.ExperianRefNum, 0);
                    limited.Execute();

                    this.companyDissolutionDate = limited.Result.DissolutionDate;

                    this.directors = new List <Name>();

                    foreach (ExperianLtdDL72 dataRow in limited.Result.GetChildren <ExperianLtdDL72>())
                    {
                        this.directors.Add(new Name(dataRow.FirstName, dataRow.LastName));
                    }

                    foreach (ExperianLtdDLB5 dataRow in limited.Result.GetChildren <ExperianLtdDLB5>())
                    {
                        this.directors.Add(new Name(dataRow.FirstName, dataRow.LastName));
                    }
                }                 // if

                this.hmrcNames = new List <NameForComparison>();

                this.db.ForEachRowSafe(
                    names => {
                    if (!names["BelongsToCustomer"])
                    {
                        return;
                    }

                    var name = new NameForComparison(names["BusinessName"]);
                    if (name.AdjustedName != string.Empty)
                    {
                        this.hmrcNames.Add(name);
                    }
                },
                    "GetHmrcBusinessNames",
                    CommandSpecies.StoredProcedure,
                    new QueryParameter("CustomerId", this.trail.CustomerID)
                    );

                SafeReader sr = this.db.GetFirst(
                    "GetExperianMinMaxConsumerDirectorsScore",
                    CommandSpecies.StoredProcedure,
                    new QueryParameter("CustomerId", this.trail.CustomerID),
                    new QueryParameter("Now", Now)
                    );

                if (!sr.IsEmpty)
                {
                    this.minExperianScore = sr["MinExperianScore"];
                }

                var oScore = new QueryParameter("CompanyScore")
                {
                    Type      = DbType.Int32,
                    Direction = ParameterDirection.Output,
                };

                var oDate = new QueryParameter("IncorporationDate")
                {
                    Type      = DbType.DateTime2,
                    Direction = ParameterDirection.Output,
                };

                this.db.ExecuteNonQuery(
                    "GetCompanyScoreAndIncorporationDate",
                    CommandSpecies.StoredProcedure,
                    new QueryParameter("CustomerId", this.trail.CustomerID),
                    new QueryParameter("TakeMinScore", true),
                    oScore,
                    oDate
                    );

                int nScore;
                if (int.TryParse(oScore.SafeReturnedValue, out nScore))
                {
                    this.minCompanyScore = nScore;
                }

                this.m_oSecondaryImplementation.Init();
            }             // using timer step

            return(this);
        }         // Init
        }         // constructor

        public override void Execute()
        {
            string experianCompanyName = null;
            string enteredCompanyName  = null;
            string enteredFullName     = null;
            string experianFullName    = null;

            var businessNames = new List <BusinessRelevance>();

            DB.ForEachRowSafe(
                sr => {
                string rowType = sr["RowType"];

                switch (rowType)
                {
                case "CompanyName":
                    experianCompanyName = sr["ExperianCompanyName"];
                    enteredCompanyName  = sr["EnteredCompanyName"];
                    enteredFullName     = sr["FullName"];
                    break;

                case "HmrcBusinessName":
                    bool?belongsToCustomer = sr["BelongsToCustomer"];

                    if (belongsToCustomer == null)
                    {
                        businessNames.Add(new BusinessRelevance {
                            Name       = new NameForComparison(sr["Name"]),
                            BusinessID = sr["BusinessID"],
                        });
                    }                             // if

                    break;

                case "ExperianName":
                    experianFullName = Concat(sr["ForeName"], sr["MiddleInitial"], sr["Surname"]);
                    break;
                }                         // switch
            },
                "LoadCustomerCompanyNames",
                CommandSpecies.StoredProcedure,
                new QueryParameter("CustomerID", this.customerID),
                new QueryParameter("Now", this.now)
                );

            if (businessNames.Count < 1)
            {
                Log.Debug(
                    "Not updating HMRC business relevance for customer {0}: no HMRC business found.",
                    this.customerID
                    );

                return;
            }             // if

            var companyName = new NameForComparison(experianCompanyName, enteredCompanyName);

            Log.Debug(
                "Customer {0}: company name '{1}' (adjusted to '{2}') with {3} HMRC business(es).",
                this.customerID,
                companyName.RawName,
                companyName.AdjustedName,
                businessNames.Count
                );

            foreach (BusinessRelevance bn in businessNames)
            {
                bn.SetOtherNameAndBelongs(companyName, experianFullName ?? enteredFullName);
            }

            DB.ExecuteNonQuery(
                "UpdateHmrcBusinessRelevance",
                CommandSpecies.StoredProcedure,
                DB.CreateTableParameter(
                    typeof(BusinessRelevance),
                    "RelevanceList",
                    businessNames,
                    o => ((BusinessRelevance)o).ToParameter(),
                    BusinessRelevance.StructToSave()
                    )
                );
        }         // Execute