public async Task <HolidayCalculationResponseDTO> PerformHolidayCalculationWithoutHPAAsync(HolidayCalculationRequestModel data, IOptions <ConfigLookupRoot> options)
        {
            string selectedInputString = null;
            var    result    = new HolidayCalculationResponseDTO();
            var    traceinfo = new TraceInfo();

            var firstHtnp   = data.Htnp.First();
            var htnpEndDate = firstHtnp.DismissalDate.Date < firstHtnp.InsolvencyDate.Date ? firstHtnp.DismissalDate.Date : firstHtnp.InsolvencyDate.Date;
            var maximumHolidayEntitlement = 6m * firstHtnp.ShiftPattern.Count;

            var tweleveMonthsPrior = firstHtnp.InsolvencyDate.Date.AddMonths(-12).AddDays(1);
            var numRp1HtnpDays     = (await data.Htnp.GetHTNPDays(InputSource.Rp1, tweleveMonthsPrior, htnpEndDate)).Count;
            var numRp14aHtnpDays   = (await data.Htnp.GetHTNPDays(InputSource.Rp14a, tweleveMonthsPrior, htnpEndDate)).Count;

            if ((numRp1HtnpDays > 0 && numRp1HtnpDays < numRp14aHtnpDays) ||
                (numRp14aHtnpDays == 0 && numRp1HtnpDays > 0))
            {
                selectedInputString = InputSource.Rp1;
            }
            else
            {
                selectedInputString = InputSource.Rp14a;
            }

            result.Htnp = new HolidayTakenNotPaidAggregateOutput();
            result.Htnp.SelectedInputSource = selectedInputString;

            result.Htnp.RP1ResultsList = await _htnpService.PerformCalculationAsync(
                data.Htnp,
                InputSource.Rp1,
                0,
                (selectedInputString == InputSource.Rp1)?maximumHolidayEntitlement : 0,
                null,
                options,
                (selectedInputString == InputSource.Rp1)?traceinfo : null);

            result.Htnp.RP14aResultsList = await _htnpService.PerformCalculationAsync(
                data.Htnp,
                InputSource.Rp14a,
                0,
                (selectedInputString == InputSource.Rp14a)?maximumHolidayEntitlement : 0,
                null,
                options,
                (selectedInputString == InputSource.Rp14a)?traceinfo : null);

            result.Htnp.TraceInfo = await traceinfo?.ConvertToJson();

            return(result);
        }
Exemplo n.º 2
0
        public async Task <APPACalculationResponseDTO> PerformCalculationAsync(APPACalculationRequestModel data, IOptions <ConfigLookupRoot> options)
        {
            var allWeeks      = new List <IWeeklyResult>();
            var result        = new APPACalculationResponseDTO();
            var rp1TraceInfo  = new TraceInfo();
            var rp14TraceInfo = new TraceInfo();

            if (data.Ap != null && data.Ap.Any())
            {
                result.Ap = new ArrearsOfPayAggregateOutput();
                result.Ap.RP1ResultsList = await _apService.PerformCalculationAsync(data.Ap, InputSource.Rp1, options, rp1TraceInfo);

                result.Ap.RP14aResultsList = await _apService.PerformCalculationAsync(data.Ap, InputSource.Rp14a, options, rp14TraceInfo);

                var rp1Any = result.Ap.RP1ResultsList != null && result.Ap.RP1ResultsList.WeeklyResult.Any();
                var rp1Sum = rp1Any ? result.Ap.RP1ResultsList.WeeklyResult.Sum(x => x.NetEntitlement) : 0M;

                var rp14aAny = result.Ap.RP14aResultsList != null && result.Ap.RP14aResultsList.WeeklyResult.Any();
                var rp14aSum = rp14aAny ? result.Ap.RP14aResultsList.WeeklyResult.Sum(x => x.NetEntitlement) : 0M;

                if ((rp1Any && rp1Sum == 0) || (rp1Sum > 0 && rp1Sum < rp14aSum) || (rp1Any && !rp14aAny))
                {
                    result.Ap.SelectedInputSource = InputSource.Rp1;
                    allWeeks.AddRange(result.Ap.RP1ResultsList.WeeklyResult);
                    result.Ap.TraceInfo = await rp1TraceInfo.ConvertToJson();
                }
                else
                {
                    result.Ap.SelectedInputSource = InputSource.Rp14a;
                    allWeeks.AddRange(result.Ap.RP14aResultsList.WeeklyResult);
                    result.Ap.TraceInfo = await rp14TraceInfo.ConvertToJson();
                }
            }

            if (data.Pa != null)
            {
                result.Pa = await _paService.PerformProtectiveAwardCalculationAsync(data.Pa, options);

                allWeeks.AddRange(result.Pa.PayLines);
            }

            allWeeks.OrderByDescending(x => x.NetEntitlement)
            .ThenByDescending(x => x.GrossEntitlementIn4Months)
            .Take(8)
            .ToList()
            .ForEach(x => x.IsSelected = true);

            return(result);
        }
        public async Task <HolidayCalculationResponseDTO> PerformHolidayCalculationWithHPAAsync(HolidayCalculationRequestModel data, IOptions <ConfigLookupRoot> options)
        {
            string selectedInputString = null;
            var    result    = new HolidayCalculationResponseDTO();
            var    traceinfo = new TraceInfo();

            // select the input source with lowest count in the currrent holiday year
            if (data.Htnp != null && data.Htnp.Any())
            {
                var firstHtnp = data.Htnp.First();

                var holidayYearStart = await data.Hpa.GetHolidayYearStart();

                var htnpEndDate = firstHtnp.DismissalDate.Date < firstHtnp.InsolvencyDate.Date ? firstHtnp.DismissalDate.Date : firstHtnp.InsolvencyDate.Date;

                var tweleveMonthsPrior = firstHtnp.InsolvencyDate.Date.AddMonths(-12).AddDays(1);
                var numRp1HtnpDays     = (await data.Htnp.GetHTNPDays(InputSource.Rp1, tweleveMonthsPrior, htnpEndDate)).Count;
                var numRp14aHtnpDays   = (await data.Htnp.GetHTNPDays(InputSource.Rp14a, tweleveMonthsPrior, htnpEndDate)).Count;

                if ((numRp1HtnpDays > 0 && numRp1HtnpDays < numRp14aHtnpDays) ||
                    (numRp14aHtnpDays == 0 && numRp1HtnpDays > 0))
                {
                    selectedInputString = InputSource.Rp1;
                }
                else
                {
                    selectedInputString = InputSource.Rp14a;
                }

                // align HPA day taken with htnp days
                int numHTNPDaysInCurrentHolYear = (await data.Htnp.GetHTNPDays(selectedInputString, holidayYearStart, htnpEndDate)).Count;
                data.Hpa.DaysTaken = Math.Max(data.Hpa.DaysTaken.Value, numHTNPDaysInCurrentHolYear);
            }

            result.Hpa = await _hpaService.PerformHolidayPayAccruedCalculationAsync(data.Hpa, options);

            if (data.Htnp != null && data.Htnp.Any())
            {
                result.Htnp = new HolidayTakenNotPaidAggregateOutput();
                result.Htnp.SelectedInputSource = selectedInputString;

                var firstHtnp = data.Htnp.First();
                var maximumHolidayEntitlement = 6m * firstHtnp.ShiftPattern.Count;

                var holidayYearStart = await data.Hpa.GetHolidayYearStart();

                decimal statHolEntitlement = 0.00m;
                statHolEntitlement = await statHolEntitlement.GetStatutoryHolidayEntitlement(data.Hpa.ShiftPattern);

                var holidayEntitlementForCurrentYear = (await statHolEntitlement.GetAdjustedHolidayEntitlement(data.Hpa.ContractedHolEntitlement.Value)) + data.Hpa.DaysCFwd.Value;

                var maximumHTNPDaysInHolidayYear = Math.Min(holidayEntitlementForCurrentYear, maximumHolidayEntitlement) - (result.Hpa?.ProRataAccruedDays ?? 0);
                var maximumHTNPDaysInTotal       = maximumHolidayEntitlement - (result.Hpa?.ProRataAccruedDays ?? 0);

                result.Htnp.RP1ResultsList = await _htnpService.PerformCalculationAsync(
                    data.Htnp,
                    InputSource.Rp1,
                    (selectedInputString == InputSource.Rp1)?maximumHTNPDaysInHolidayYear : 0,
                    (selectedInputString == InputSource.Rp1)?maximumHTNPDaysInTotal : 0,
                    holidayYearStart,
                    options,
                    (selectedInputString == InputSource.Rp1)?traceinfo : null);

                result.Htnp.RP14aResultsList = await _htnpService.PerformCalculationAsync(
                    data.Htnp,
                    InputSource.Rp14a,
                    (selectedInputString == InputSource.Rp14a)?maximumHTNPDaysInHolidayYear : 0,
                    (selectedInputString == InputSource.Rp14a)?maximumHTNPDaysInTotal : 0,
                    holidayYearStart,
                    options,
                    (selectedInputString == InputSource.Rp14a)?traceinfo : null);

                result.Htnp.TraceInfo = await traceinfo?.ConvertToJson();
            }
            return(result);
        }
Exemplo n.º 4
0
        public async Task <NoticePayCompositeCalculationResponseDTO> PerformNoticePayCompositeCalculationAsync(NoticePayCompositeCalculationRequestModel data, IOptions <ConfigLookupRoot> options)
        {
            var result        = new NoticePayCompositeCalculationResponseDTO();
            var cnpOutput     = new CompensatoryNoticePayCalculationResponseDTO();
            var nwnpOutput    = new NoticeWorkedNotPaidCompositeOutput();
            var rp1TraceInfo  = new TraceInfo();
            var rp14TraceInfo = new TraceInfo();

            //CNP calculation
            if (data.Cnp != null)
            {
                cnpOutput = await _cnpService.PerformCompensatoryNoticePayCalculationAsync(data.Cnp, options);

                cnpOutput.WeeklyResults.ForEach(x => x.IsSelected = true);
            }

            //NWNP calculation
            if (data.Nwnp != null && data.Nwnp.Any())
            {
                var statutoryMax = ConfigValueLookupHelper.GetStatutoryMax(options, data.Nwnp.FirstOrDefault().InsolvencyDate);

                foreach (var nwnp in data.Nwnp)
                {
                    var traceDate = new TraceInfoDate();
                    var res       = await _nwnpService.PerformNwnpCalculationAsync(nwnp, options, traceDate);

                    if (res.InputSource == InputSource.Rp1)
                    {
                        //nwnpOutput.nwnpResults.rP1ResultsList.Add(res);
                        nwnpOutput.rp1Results.WeeklyResult.AddRange(res.WeeklyResult);
                        rp1TraceInfo.Dates.Add(traceDate);
                        rp1TraceInfo.NumberOfDays = 0.00m;
                        foreach (var week in res.WeeklyResult)
                        {
                            rp1TraceInfo.NumberOfDays += week.EmploymentDays;
                        }
                    }
                    else if (res.InputSource == InputSource.Rp14a)
                    {
                        //nwnpOutput.nwnpResults.rP14aResultsList.Add(res);
                        nwnpOutput.rp14aResults.WeeklyResult.AddRange(res.WeeklyResult);
                        rp14TraceInfo.Dates.Add(traceDate);
                        rp14TraceInfo.NumberOfDays = 0.00m;
                        foreach (var week in res.WeeklyResult)
                        {
                            rp14TraceInfo.NumberOfDays += week.EmploymentDays;
                        }
                    }
                }

                var rp1Total   = 0m;
                var rp14aTotal = 0m;

                //merge pay weeks
                nwnpOutput.rp1Results = await nwnpOutput.rp1Results.MergePayWeeks(options);

                nwnpOutput.rp1Results.InputSource  = InputSource.Rp1;
                nwnpOutput.rp1Results.StatutoryMax = statutoryMax;
                rp1Total = nwnpOutput.rp1Results.WeeklyResult.Sum(x => x.NetEntitlement);

                //merge pay weeks
                nwnpOutput.rp14aResults = await nwnpOutput.rp14aResults.MergePayWeeks(options);

                nwnpOutput.rp14aResults.InputSource  = InputSource.Rp14a;
                nwnpOutput.rp14aResults.StatutoryMax = statutoryMax;
                rp14aTotal = nwnpOutput.rp14aResults.WeeklyResult.Sum(x => x.NetEntitlement);

                //select the input source
                // Choose RP1 list or RP14a list with the lowest total NetEntitlement
                if ((rp1Total < rp14aTotal && rp14aTotal != 0 && rp1Total != 0) || (rp1Total > 0 && rp14aTotal == 0))
                {
                    nwnpOutput.SelectedInputSource = InputSource.Rp1;
                    nwnpOutput.rp1Results.WeeklyResult.ForEach(x => x.IsSelected   = true);
                    nwnpOutput.rp14aResults.WeeklyResult.ForEach(x => x.IsSelected = false);
                    nwnpOutput.TraceInfo = await rp1TraceInfo.ConvertToJson();
                }
                else
                {
                    nwnpOutput.SelectedInputSource = InputSource.Rp14a;
                    nwnpOutput.rp1Results.WeeklyResult.ForEach(x => x.IsSelected   = false);
                    nwnpOutput.rp14aResults.WeeklyResult.ForEach(x => x.IsSelected = true);
                    nwnpOutput.TraceInfo = await rp14TraceInfo.ConvertToJson();
                }
            }

            result.Cnp  = cnpOutput;
            result.Nwnp = nwnpOutput;
            return(result);
        }