Ejemplo n.º 1
0
        }         // GetLogicalProposedAmount

        private void CreateUnlogicalOffer()
        {
            this.medalAgent.Notify();

            if (Medal.HasError)
            {
                CreateErrorResult("Error calculating medal for {0}.", OuterContextDescription);
                return;
            }             // if

            bool isHomeOwner = DB.ExecuteScalar <bool>(
                "GetIsCustomerHomeOwnerAccordingToLandRegistry",
                CommandSpecies.StoredProcedure,
                new QueryParameter("CustomerId", this.customerID)
                );

            ProposedAmount = Math.Min(
                Medal.RoundOfferedAmount(),
                isHomeOwner ? this.homeOwnerCap : this.notHomeOwnerCap
                );

            bool noGo =
                (ProposedAmount <= 0) ||
                (Medal.MedalClassification == EZBob.DatabaseLib.Model.Database.Medal.NoClassification);

            if (noGo)
            {
                string errorMsg = string.Join(
                    " ",
                    new List <string> {
                    ProposedAmount <= 0 ? "Proposed amount is not positive." : null,
                    (Medal.MedalClassification == EZBob.DatabaseLib.Model.Database.Medal.NoClassification)
                                                        ? "No medal calculated."
                                                        : null,
                }.Where(s => !string.IsNullOrWhiteSpace(s))
                    );

                CreateErrorResult("'{0}' for {1}, no offer.", errorMsg, OuterContextDescription);
                return;
            }             // if

            GradeRangeSubproduct grsp = LoadOfferRanges(false);

            if (grsp == null)
            {
                return;
            }

            Calculate();
        }         // CreateUnlogicalOffer
Ejemplo n.º 2
0
        }         // Run

        private void CreateLogicalOffer()
        {
            var offerIsImpossibleReasons = new List <string>();

            if (this.autoRejectionOutput.ErrorInLGData)
            {
                offerIsImpossibleReasons.Add("error in LG data");
            }

            if (this.autoRejectionOutput.GradeRangeID <= 0)
            {
                offerIsImpossibleReasons.Add("GradeRangeID is not positive");
            }

            if (this.autoRejectionOutput.ProductSubTypeID <= 0)
            {
                offerIsImpossibleReasons.Add("ProductSubTypeID is not positive");
            }

            if (offerIsImpossibleReasons.Count > 0)
            {
                Log.Debug(
                    "Cannot calculate Logical Glue based offer for {0}: {1}.",
                    OuterContextDescription,
                    string.Join(", ", offerIsImpossibleReasons)
                    );

                return;
            }             // if

            GradeRangeSubproduct grsp = LoadOfferRanges(true);

            if (grsp == null)
            {
                return;
            }

            ProposedAmount = GetLogicalProposedAmount(grsp);

            if (ProposedAmount <= 0)
            {
                CreateErrorResult("Proposed amount is not positive for {0}, no offer.", OuterContextDescription);
                return;
            }             // if

            Calculate();
        }         // CreateLogicalOffer
Ejemplo n.º 3
0
        }         // CreateLogicalOffer

        private int GetLogicalProposedAmount(GradeRangeSubproduct grsp)
        {
            decimal annualTurnover = 0;
            decimal freeCashFlow   = 0;
            decimal valueAdded     = 0;

            try {
                var turnoverCalc = new TurnoverCalculator(this.customerID, DateTime.UtcNow, DB, Log).LoadInputData();

                if (turnoverCalc.OutOfDate)
                {
                    Log.Debug("Out of date marketplaces detected for {0}.", OuterContextDescription);
                }
                else
                {
                    turnoverCalc.Execute();

                    if (turnoverCalc.HasOnline)
                    {
                        Log.Debug("Online turnover for {0}.", OuterContextDescription);
                        turnoverCalc.ExecuteOnline();
                    }
                    else
                    {
                        Log.Debug("Offline turnover for {0}.", OuterContextDescription);
                    }

                    annualTurnover = turnoverCalc.Model.AnnualTurnover;
                    freeCashFlow   = turnoverCalc.Model.UseHmrc ? turnoverCalc.Model.FreeCashFlowValue : 0;
                    valueAdded     = turnoverCalc.Model.UseHmrc ? turnoverCalc.Model.ValueAdded : 0;
                }                 // if
            } catch (Exception e) {
                Log.Alert(e, "Failed to load turnover for {0}.", OuterContextDescription);
            }             // try

            Log.Debug(
                "Turnover = {0}, FCF = {1}, VA = {2} for {3}.",
                annualTurnover,
                freeCashFlow,
                valueAdded,
                OuterContextDescription
                );

            decimal[] allOffers =
            {
                annualTurnover *(grsp.TurnoverShare ?? 0),
                freeCashFlow *(grsp.FreeCashFlowShare ?? 0),
                valueAdded *(grsp.ValueAddedShare ?? 0),
            };

            List <int> validOffers = allOffers.Where(v => v > 0).Select(grsp.LoanAmount).Where(v => v > 0).ToList();

            Log.Debug(
                "Proposed amounts for {0}:\n\tAll   offer amounts: {1}\n\tValid offer amounts: {2}",
                OuterContextDescription,
                string.Join(", ", allOffers),
                string.Join(", ", validOffers)
                );

            if (validOffers.Count > 0)
            {
                int minOffer = validOffers.Min();
                Log.Debug("Proposed offer amount for {0} is {1}.", OuterContextDescription, minOffer);
                return(minOffer);
            }             // if

            Log.Debug("No valid offers found for {0}.", OuterContextDescription);
            return(0);
        }         // GetLogicalProposedAmount