Exemple #1
0
        public InstallmentPlan CalculateInstallmentPlan(CalculateInstallmentPlanRequest request)
        {
            #region Request Validation
            int termUnits = 0;
            SimpleUnitOfTime termUnitOfTime = SimpleUnitOfTime.M;

            if (!string.IsNullOrEmpty(request.Term))
            {
                termUnits = Utility.GetMonthsFromPeriod(request.Term);
                if (termUnits <= 0)
                {
                    termUnits      = Utility.GetDaysFromPeriod(request.Term);
                    termUnitOfTime = SimpleUnitOfTime.D;
                }
                // string tmp = request.Term.Trim();

                /*string uot = request.Term.Substring(request.Term.Length - 1);
                 * string trm = request.Term.Substring(0, request.Term.Length - 1);
                 * if (!int.TryParse(trm, out termUnits) || !SimpleUnitOfTime.TryParse(uot, out termUnitOfTime) || termUnits == 0)
                 * {
                 *  // vp.Add(new ValidationproblemInner() { Field = "term", Errors = new List<ValidationproblemInnerErrors>() { new ValidationproblemInnerErrors() { Error = "002", Message = "Invalid term!" } } });
                 * }*/
            }
            else if (request.FixedAnnuity == 0)
            {
                // vp.Add(new ValidationproblemInner() { Field = "fixedAnnuity", Errors = new List<ValidationproblemInnerErrors>() { new ValidationproblemInnerErrors() { Error = "003", Message = "If term is not specified, then fixedAnnuity must be!" } } });
            }
            #endregion

            var calcReq = PrepareInstallmentPlanRequest(request, termUnits, termUnitOfTime);
            var res     = CalculateInstalmentPlanCS(calcReq);

            var plan = GetPlanFromCalculationResponse(res.CalculationResponse);

            return(plan);
        }
Exemple #2
0
        public ActionResult CalculateInstallmentPlan([FromBody] CalculateInstallmentPlanRequest request)
        {
            var plan = _calculator.CalculateInstallmentPlan(request);

            return(Ok(plan));
        }
Exemple #3
0
        private KdpInstallmentPlanCalculationRequest PrepareInstallmentPlanRequest(CalculateInstallmentPlanRequest request, int termUnits = 0,
                                                                                   SimpleUnitOfTime termUnitOfTime = SimpleUnitOfTime.M)
        {
            KdpInstallmentPlanCalculationRequest calcReq = Mapper.Map <CalculateInstallmentPlanRequest, KdpInstallmentPlanCalculationRequest>(request);

            if (termUnits != 0)
            {
                switch (termUnitOfTime)
                {
                case SimpleUnitOfTime.Y:
                    calcReq.NumberOfInstallments = termUnits * 12;
                    break;

                case SimpleUnitOfTime.D:
                    calcReq.NumberOfInstallments = termUnits / 30;     // aproksimiramo
                    break;

                default:
                    calcReq.NumberOfInstallments = termUnits;
                    break;
                }
            }
            else
            {
                calcReq.NumberOfInstallments = 9999;
            }
            calcReq.NumberOfInstallmentsSpecified = true;

            if (termUnits != 0)
            {
                switch (termUnitOfTime)
                {
                case SimpleUnitOfTime.Y:
                    calcReq.MaturityDate = calcReq.StartDate.AddYears(termUnits);
                    break;

                case SimpleUnitOfTime.D:
                    calcReq.MaturityDate = calcReq.StartDate.AddDays(termUnits);
                    break;

                default:
                    calcReq.MaturityDate = calcReq.StartDate.AddMonths(termUnits);
                    break;
                }
            }
            else
            {
                calcReq.MaturityDate = calcReq.StartDate.AddYears(100);
            }
            calcReq.MaturityDateSpecified = true;

            // da postavim sve datume koje sam zaboravio :)
            foreach (var prop in typeof(KdpInstallmentPlanCalculationRequest).GetProperties().Where(p => p.PropertyType == typeof(DateTime)))
            {
                prop.SetValue(calcReq, ((DateTime)prop.GetValue(calcReq)).Date);
                if (((DateTime)prop.GetValue(calcReq)).Date < calcReq.StartDate.Date)
                {
                    prop.SetValue(calcReq, calcReq.StartDate.Date);
                }
                typeof(KdpInstallmentPlanCalculationRequest).GetProperty(prop.Name + "Specified").SetValue(calcReq, true);
            }
            calcReq.AdditionalRegularInterestInfo = GetAdditionalRegularInterestInfo(request.Periods, calcReq.StartDate, calcReq.MaturityDate,
                                                                                     calcReq.RegularInterestPercentage, calcReq.RegularInterestUnitOfTime);
            calcReq.AdditionalConditions          = calcReq.AdditionalRegularInterestInfo != null && calcReq.AdditionalRegularInterestInfo.Count() > 0;
            calcReq.AdditionalConditionsSpecified = calcReq.AdditionalRegularInterestInfo != null && calcReq.AdditionalRegularInterestInfo.Count() > 0;

            calcReq.RouteIdentifier  = _options.Value.RouteIdentifier;
            calcReq.ArrangementType  = _options.Value.ArrangementType;
            calcReq.ClientIdentifier = _options.Value.ClientIdentifier;
            calcReq.InstallmentPlanCalculationScenario          = 2;
            calcReq.InstallmentPlanCalculationScenarioSpecified = true;

            return(calcReq);
        }