private List <AuthorizationBreakdown> getBreakdownsForRule(Domain2.Hours.Hours entry, AuthorizationMatchRule matchedRule)
        {
            var breakdowns      = new List <AuthorizationBreakdown>();
            var activeCaseAuths = ResolutionServiceRepository.GetCase(entry.CaseID).GetActiveAuthorizations(entry.Date);
            int totalMinutes    = (int)Math.Round(entry.TotalHours * 60);

            if (!matchedRule.IsInitialAuthUsableForTimeEntry)
            {
                return(null);
            }

            if (totalMinutes < matchedRule.InitialMinimumMinutes)
            {
                return(null);
            }

            var initialAuth = activeCaseAuths.Where(x => x.AuthorizationCodeID == matchedRule.InitialAuthorizationID).FirstOrDefault();

            if (initialAuth == null)
            {
                return(null);
            }

            var initialBreakdown = new AuthorizationBreakdown();

            initialBreakdown.AuthorizationID = matchedRule.InitialAuthorization.ID;
            initialBreakdown.Authorization   = initialAuth;
            initialBreakdown.HoursEntry      = entry;
            //initialBreakdown.HoursID = _hours.ID;
            initialBreakdown.Minutes = matchedRule.GetApplicableInitialMinutes(totalMinutes);

            breakdowns.Add(initialBreakdown);

            if (!matchedRule.IsFinalAuthUsableForTimeEntry)
            {
                return(breakdowns);
            }

            var finalAuth = activeCaseAuths.Where(x => x.AuthorizationCodeID == matchedRule.FinalAuthorizationID).FirstOrDefault();

            if (finalAuth == null)
            {
                return(breakdowns);
            }

            var finalBreakdown = new AuthorizationBreakdown();

            finalBreakdown.AuthorizationID = matchedRule.FinalAuthorization.ID;
            finalBreakdown.Authorization   = finalAuth;
            finalBreakdown.HoursEntry      = entry;
            //finalBreakdown.HoursID = entry.ID;
            finalBreakdown.Minutes = matchedRule.GetApplicableFinalMinutes(totalMinutes);

            if (finalBreakdown.Minutes > 0)
            {
                breakdowns.Add(finalBreakdown);
            }

            return(breakdowns);
        }
        public void FinalAuthRoundsToUpperUnitSize()
        {
            var rule = new AuthorizationMatchRule();

            rule.InitialAuthorization = new AuthorizationCode();
            rule.FinalAuthorization   = new AuthorizationCode();

            rule.InitialMinimumMinutes = 16;
            rule.InitialUnitSize       = 30;
            rule.FinalMinimumMinutes   = 16;
            rule.FinalUnitSize         = 30;

            var sut = rule.GetApplicableFinalMinutes(140);

            Assert.AreEqual(120, sut);
        }
        private List <AuthorizationBreakdown> getAuthorizationHoursBreakdowns(AuthorizationMatchRule matchRule)
        {
            var breakdowns      = new List <AuthorizationBreakdown>();
            var activeCaseAuths = _case.GetActiveAuthorizations(_hours.Date);
            int totalMinutes    = (int)Math.Round(_hours.TotalHours * 60);

            // make sure the basic initial match rule auth is usable
            if (!matchRule.IsInitialAuthUsableForTimeEntry)
            {
                return(null);
            }

            if (totalMinutes < matchRule.InitialMinimumMinutes)
            {
                return(null);
            }

            // make sure we actually map to one of the case's auths
            var initialAuth = activeCaseAuths.Where(x => x.AuthorizationCodeID == matchRule.InitialAuthorizationID).FirstOrDefault();

            if (initialAuth == null)
            {
                return(null);
            }

            // we have a good match, create the initial breakdown
            var initialBreakdown = new AuthorizationBreakdown();

            initialBreakdown.AuthorizationID = matchRule.InitialAuthorization.ID;
            initialBreakdown.Authorization   = initialAuth;
            initialBreakdown.HoursEntry      = _hours;
            initialBreakdown.HoursID         = _hours.ID;
            initialBreakdown.Minutes         = matchRule.GetApplicableInitialMinutes(totalMinutes);

            breakdowns.Add(initialBreakdown);

            // make sure the final auth is usable
            if (!matchRule.IsFinalAuthUsableForTimeEntry)
            {
                return(breakdowns);
            }

            var finalAuth = activeCaseAuths.Where(x => x.AuthorizationCodeID == matchRule.FinalAuthorizationID).FirstOrDefault();

            if (finalAuth == null)
            {
                return(breakdowns);
            }

            var finalBreakdown = new AuthorizationBreakdown();

            finalBreakdown.AuthorizationID = matchRule.FinalAuthorization.ID;
            finalBreakdown.Authorization   = finalAuth;
            finalBreakdown.HoursEntry      = _hours;
            finalBreakdown.HoursID         = _hours.ID;
            finalBreakdown.Minutes         = matchRule.GetApplicableFinalMinutes(totalMinutes);

            if (finalBreakdown.Minutes > 0)
            {
                breakdowns.Add(finalBreakdown);
            }

            return(breakdowns);
        }