private static List <int> GetYearRangesImpl(IProject projectUpdate, DateTime?startDate)
        {
            var currentYearToUse = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting();

            if (projectUpdate != null)
            {
                if (startDate.HasValue && startDate.Value.Year < MultiTenantHelpers.GetMinimumYear() &&
                    (projectUpdate.GetCompletionYear().HasValue&& projectUpdate.GetCompletionYear().Value < MultiTenantHelpers.GetMinimumYear()))
                {
                    // both start and completion year are before the minimum year, so no year range required
                    return(new List <int>());
                }

                if (startDate.HasValue && startDate.Value.Year > currentYearToUse && (projectUpdate.GetCompletionYear().HasValue&& projectUpdate.GetCompletionYear().Value > currentYearToUse))
                {
                    return(new List <int>());
                }

                if (startDate.HasValue && projectUpdate.GetCompletionYear().HasValue&& startDate.Value.Year > projectUpdate.GetCompletionYear().Value)
                {
                    return(new List <int>());
                }
            }
            return(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(),
                                                                                           startDate,
                                                                                           projectUpdate.GetCompletionYear(),
                                                                                           currentYearToUse,
                                                                                           MultiTenantHelpers.GetMinimumYear(),
                                                                                           currentYearToUse));
        }
            public ViewDataForAngularClass(ProjectFirmaModels.Models.Project project,
                                           List <FundingSourceSimple> allFundingSources,
                                           List <int> requiredCalendarYearRange)
            {
                RequiredCalendarYearRange = requiredCalendarYearRange;
                AllFundingSources         = allFundingSources;
                ProjectID = project.ProjectID;

                MaxYear        = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting();
                UseFiscalYears = MultiTenantHelpers.UseFiscalYears();
            }
            public ViewDataForAngularClass(Models.Project project,
                                           List <GrantAllocationSimple> allGrantAllocations,
                                           List <int> calendarYearRange, bool showNoExpendituresExplanation)
            {
                CalendarYearRange             = calendarYearRange;
                ShowNoExpendituresExplanation = showNoExpendituresExplanation;
                AllGrantAllocations           = allGrantAllocations;
                ProjectID = project.ProjectID;

                MaxYear        = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting();
                UseFiscalYears = MultiTenantHelpers.UseFiscalYears();
            }
        public BasicsValidationResult(ProjectFirmaModels.Models.ProjectUpdate projectUpdate)
        {
            _warningMessages = new List <string>();

            if (projectUpdate.PlanningDesignStartYear == null)
            {
                _warningMessages.Add(PlanningDesignStartYearIsRequired);
            }
            if (projectUpdate.ImplementationStartYear == null && projectUpdate.ProjectStage != ProjectStage.Terminated && projectUpdate.ProjectStage != ProjectStage.Deferred)
            {
                _warningMessages.Add(ImplementationStartYearIsRequired);
            }

            if ((projectUpdate.ProjectStage == ProjectStage.Completed || projectUpdate.ProjectStage == ProjectStage.PostImplementation) && projectUpdate.CompletionYear == null)
            {
                _warningMessages.Add(CompletionYearIsRequired);
            }

            if (GeneralUtility.IsNullOrEmptyOrOnlyWhitespace(projectUpdate.ProjectDescription))
            {
                _warningMessages.Add(ProjectDescriptionIsRequired);
            }

            var currentYear = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting();

            if ((projectUpdate.ProjectStage == ProjectStage.Completed || projectUpdate.ProjectStage == ProjectStage.PostImplementation) && projectUpdate.CompletionYear > currentYear)
            {
                _warningMessages.Add(CompletionYearShouldBeLessThanCurrentYear);
            }
            if (projectUpdate.ProjectStage == ProjectStage.PlanningDesign && projectUpdate.PlanningDesignStartYear > currentYear)
            {
                _warningMessages.Add(PlanningDesignStartYearShouldBeLessThanCurrentYear);
            }
            if (projectUpdate.ProjectStage == ProjectStage.Implementation && projectUpdate.ImplementationStartYear > currentYear)
            {
                _warningMessages.Add(ImplementationStartYearShouldBeLessThanCurrentYear);
            }

            if (projectUpdate.ImplementationStartYear < projectUpdate.PlanningDesignStartYear)
            {
                _warningMessages.Add(FirmaValidationMessages.ImplementationStartYearGreaterThanPlanningDesignStartYear);
            }
            if (projectUpdate.CompletionYear < projectUpdate.ImplementationStartYear)
            {
                _warningMessages.Add(FirmaValidationMessages.CompletionYearGreaterThanEqualToImplementationStartYear);
            }
            if (projectUpdate.CompletionYear < projectUpdate.PlanningDesignStartYear)
            {
                _warningMessages.Add(FirmaValidationMessages.CompletionYearGreaterThanEqualToPlanningDesignStartYear);
            }
        }
Exemple #5
0
 public ViewDataForAngularClass(ProjectUpdateBatch projectUpdateBatch,
                                List <FundingSourceSimple> allFundingSources,
                                List <CostTypeSimple> allCostTypes,
                                List <int> requiredCalendarYearRange,
                                IEnumerable <SelectListItem> fundingTypes)
 {
     RequiredCalendarYearRange = requiredCalendarYearRange;
     AllFundingSources         = allFundingSources;
     AllCostTypes         = allCostTypes;
     ProjectID            = projectUpdateBatch.ProjectID;
     ProjectUpdateBatchID = projectUpdateBatch.ProjectUpdateBatchID;
     FundingTypes         = fundingTypes;
     MaxYear = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting();
 }
        public void ProjectUpdateYearRangesTest()
        {
            var projectUpdate = TestFramework.TestProjectUpdate.Create();

            projectUpdate.ProjectStageID = ProjectStage.Completed.ProjectStageID;
            var warningMessages = new BasicsValidationResult(projectUpdate).GetWarningMessages();

            Assert.That(warningMessages.Contains(BasicsValidationResult.PlanningDesignStartYearIsRequired));
            Assert.That(warningMessages.Contains(BasicsValidationResult.ImplementationStartYearIsRequired));
            Assert.That(warningMessages.Contains(BasicsValidationResult.CompletionYearIsRequired));

            projectUpdate.CompletionYear = 2007;
            warningMessages = new BasicsValidationResult(projectUpdate).GetWarningMessages();

            Assert.That(warningMessages.Contains(BasicsValidationResult.PlanningDesignStartYearIsRequired));
            Assert.That(warningMessages.Contains(BasicsValidationResult.ImplementationStartYearIsRequired));
            Assert.That(!warningMessages.Contains(BasicsValidationResult.CompletionYearIsRequired));

            projectUpdate.ImplementationStartYear = 2010;
            warningMessages = new BasicsValidationResult(projectUpdate).GetWarningMessages();

            Assert.That(warningMessages.Contains(BasicsValidationResult.PlanningDesignStartYearIsRequired));
            Assert.That(!warningMessages.Contains(BasicsValidationResult.ImplementationStartYearIsRequired));
            Assert.That(!warningMessages.Contains(BasicsValidationResult.CompletionYearIsRequired));
            Assert.That(warningMessages.Contains(FirmaValidationMessages.CompletionYearGreaterThanEqualToImplementationStartYear));

            projectUpdate.ImplementationStartYear = 2006;
            warningMessages = new BasicsValidationResult(projectUpdate).GetWarningMessages();

            Assert.That(!warningMessages.Contains(FirmaValidationMessages.CompletionYearGreaterThanEqualToImplementationStartYear));

            // This should always be the next calendar year, I believe -- SLG 1/2/2020 (writing after this test started crashing)
            int nextCalendarYear = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting() + 1;

            projectUpdate.ProjectStageID          = ProjectStage.PlanningDesign.ProjectStageID;
            projectUpdate.PlanningDesignStartYear = nextCalendarYear;
            warningMessages = new BasicsValidationResult(projectUpdate).GetWarningMessages();

            Assert.That(!warningMessages.Contains(BasicsValidationResult.PlanningDesignStartYearIsRequired));
            Assert.That(warningMessages.Contains(BasicsValidationResult.PlanningDesignStartYearShouldBeLessThanCurrentYear));
            Assert.That(warningMessages.Contains(FirmaValidationMessages.ImplementationStartYearGreaterThanPlanningDesignStartYear));


            projectUpdate.ProjectStageID          = ProjectStage.Implementation.ProjectStageID;
            projectUpdate.ImplementationStartYear = nextCalendarYear;
            warningMessages = new BasicsValidationResult(projectUpdate).GetWarningMessages();

            Assert.That(warningMessages.Contains(BasicsValidationResult.ImplementationStartYearShouldBeLessThanCurrentYear));
        }
Exemple #7
0
 public EditProjectFundingSourceBudgetByCostTypeViewDataForAngular(ProjectFirmaModels.Models.ProjectUpdateBatch projectUpdateBatch,
                                                                   List <FundingSourceSimple> allFundingSources,
                                                                   List <CostTypeSimple> allCostTypes,
                                                                   List <int> requiredCalendarYearRange,
                                                                   IEnumerable <SelectListItem> fundingTypes)
 {
     RequiredCalendarYearRange = requiredCalendarYearRange;
     AllFundingSources         = allFundingSources;
     AllCostTypes   = allCostTypes;
     ProjectID      = projectUpdateBatch.ProjectID;
     FundingTypes   = fundingTypes;
     MaxYear        = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting();
     UseFiscalYears = MultiTenantHelpers.UseFiscalYears();
     ObligationItemBudgetRollUps  = projectUpdateBatch.Project.GetObligationItemBudgetRollUpByYearAndCostTypeAndFundingSourceSimples();
     ObligationItemInvoiceRollUps = projectUpdateBatch.Project.GetObligationItemInvoiceRollUpByYearAndCostTypeAndFundingSourceSimples();
 }
Exemple #8
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (ImplementationStartYear < PlanningDesignStartYear)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>(
                                 FirmaValidationMessages.ImplementationStartYearGreaterThanPlanningDesignStartYear,
                                 m => m.ImplementationStartYear));
            }

            if (CompletionYear < ImplementationStartYear)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>(
                                 FirmaValidationMessages.CompletionYearGreaterThanEqualToImplementationStartYear,
                                 m => m.CompletionYear));
            }

            if (ProjectStageID == ProjectStage.Completed.ProjectStageID && !CompletionYear.HasValue)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>($"Since the {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} is in the Completed stage, the Completion year is required", m => m.CompletionYear));
            }

            if (ProjectStageID == ProjectStage.PostImplementation.ProjectStageID && !CompletionYear.HasValue)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>($"Since the {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} is in the Post-Implementation stage, the Completion year is required", m => m.CompletionYear));
            }

            var isCompletedOrPostImplementation = ProjectStageID == ProjectStage.Completed.ProjectStageID || ProjectStageID == ProjectStage.PostImplementation.ProjectStageID;
            var currentYear = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting();

            if (isCompletedOrPostImplementation && CompletionYear > currentYear)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>(
                                 $"The {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} is in Completed or Post-Implementation stage; the Completion Year must be less than or equal to the current year",
                                 m => m.CompletionYear));
            }

            if (!string.IsNullOrEmpty(BpaProjectNumber))
            {
                var regexMatch = Regex.Match(BpaProjectNumber, "^" + ProjectModelExtensions.BpaProjectNumberRegexString);
                if (!regexMatch.Success)
                {
                    yield return(new SitkaValidationResult <BasicsViewModel, string>(
                                     $"You must enter a valid {FieldDefinitionEnum.BpaProjectNumber.ToType().GetFieldDefinitionLabel()} (e.g. XXXX-XXX-XX).",
                                     m => m.BpaProjectNumber));
                }
            }
        }
        public static void CreateFromProject(ProjectUpdateBatch projectUpdateBatch)
        {
            if (projectUpdateBatch.AreAccomplishmentsRelevant())
            {
                var project = projectUpdateBatch.Project;
                var performanceMeasureActualUpdates  = new List <PerformanceMeasureActualUpdate>();
                var currentPerformanceMeasureActuals = project.PerformanceMeasureActuals.ToList();
                var currentYear    = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting();
                var completionYear = projectUpdateBatch.ProjectUpdate != null
                    ? projectUpdateBatch.ProjectUpdate.GetCompletionYear()
                    : project.GetCompletionYear();

                var currentStage = projectUpdateBatch.ProjectUpdate != null
                    ? projectUpdateBatch.ProjectUpdate.ProjectStage
                    : project.ProjectStage;
                var endYearToFill = Math.Min(completionYear ?? currentYear, currentYear);
                // if we have a project completion year, we only fill up to that unless current year is earlier; no completion year set we use current year
                if (currentPerformanceMeasureActuals.Any())
                {
                    performanceMeasureActualUpdates.AddRange(
                        currentPerformanceMeasureActuals.Select(
                            performanceMeasureActual =>
                            ClonePerformanceMeasureValue(projectUpdateBatch, performanceMeasureActual,
                                                         performanceMeasureActual.CalendarYear, performanceMeasureActual.ActualValue)));
                }
                // use expected values if any only if we are not in Planning/Design
                else if (currentStage != ProjectStage.Planned)
                {
                    var currentPerformanceMeasureExpecteds =
                        new List <IPerformanceMeasureValue>(project.PerformanceMeasureExpecteds.ToList());
                    if (currentPerformanceMeasureExpecteds.Any())
                    {
                        // we want to pre-create records from project Start Year to current year; if no start year then we just create for current year
                        var initialYearToFill = project.GetImplementationStartYear() ?? currentYear;
                        performanceMeasureActualUpdates.AddRange(
                            CreatePerformanceMeasureActualUpdateRecordsForGivenYearToCurrentYear(projectUpdateBatch,
                                                                                                 currentPerformanceMeasureExpecteds,
                                                                                                 initialYearToFill,
                                                                                                 endYearToFill));
                    }
                }
                projectUpdateBatch.PerformanceMeasureActualUpdates = performanceMeasureActualUpdates;
            }
        }
Exemple #10
0
        public BasicsValidationResult(Models.ProjectUpdate projectUpdate)
        {
            _warningMessages = new List <string>();

            if (projectUpdate.GetImplementationStartYear() == null && projectUpdate.ProjectStage != ProjectStage.Cancelled)
            {
                _warningMessages.Add(ImplementationStartYearIsRequired);
            }

            if ((projectUpdate.ProjectStage == ProjectStage.Completed) && projectUpdate.GetCompletionYear() == null)
            {
                _warningMessages.Add(CompletionDateIsRequired);
            }


            var currentYear = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting();

            if ((projectUpdate.ProjectStage == ProjectStage.Completed) && projectUpdate.GetCompletionYear() > currentYear)
            {
                _warningMessages.Add(CompletionDateShouldBeLessThanCurrentYear);
            }
            if (projectUpdate.ProjectStage == ProjectStage.Planned && projectUpdate.PlannedDate?.Year > currentYear)
            {
                _warningMessages.Add(PlannedDateShouldBeLessThanCurrentYear);
            }
            if (projectUpdate.ProjectStage == ProjectStage.Implementation && projectUpdate.GetImplementationStartYear() > currentYear)
            {
                _warningMessages.Add(ImplementationStartYearShouldBeLessThanCurrentYear);
            }

            if (projectUpdate.GetCompletionYear() < projectUpdate.GetImplementationStartYear())
            {
                _warningMessages.Add(FirmaValidationMessages.CompletionDateGreaterThanEqualToImplementationStartYear);
            }
            if (projectUpdate.GetCompletionYear() < projectUpdate.PlannedDate?.Year)
            {
                _warningMessages.Add(FirmaValidationMessages.CompletionDateGreaterThanEqualToPlannedDate);
            }
        }
Exemple #11
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (ImplementationStartYear < PlanningDesignStartYear)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>(
                                 FirmaValidationMessages.ImplementationStartYearGreaterThanPlanningDesignStartYear,
                                 m => m.ImplementationStartYear));
            }

            if (CompletionYear < ImplementationStartYear)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>(
                                 FirmaValidationMessages.CompletionYearGreaterThanEqualToImplementationStartYear,
                                 m => m.CompletionYear));
            }

            if (ProjectStageID == ProjectStage.Completed.ProjectStageID && !CompletionYear.HasValue)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>($"Since the {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} is in the Completed stage, the Completion year is required", m => m.CompletionYear));
            }

            if (ProjectStageID == ProjectStage.PostImplementation.ProjectStageID && !CompletionYear.HasValue)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>($"Since the {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} is in the Post-Implementation stage, the Completion year is required", m => m.CompletionYear));
            }

            var isCompletedOrPostImplementation = ProjectStageID == ProjectStage.Completed.ProjectStageID || ProjectStageID == ProjectStage.PostImplementation.ProjectStageID;
            var currentYear = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting();

            if (isCompletedOrPostImplementation && CompletionYear > currentYear)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>(
                                 $"The {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} is in Completed or Post-Implementation stage; the Completion Year must be less than or equal to the current year",
                                 m => m.CompletionYear));
            }
        }
Exemple #12
0
        public IEnumerable <ValidationResult> GetValidationResults()
        {
            var projects = HttpRequestStorage.DatabaseEntities.Projects.ToList();

            if (ProjectTypeID == -1)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>($"{MultiTenantHelpers.GetProjectTypeDisplayNameForProject()} is required.", m => m.ProjectTypeID));
            }

            if (!Models.Project.IsProjectNameUnique(projects, ProjectName, ProjectID))
            {
                yield return(new SitkaValidationResult <BasicsViewModel, string>(FirmaValidationMessages.ProjectNameUnique, m => m.ProjectName));
            }

            if (CompletionDate < PlannedDate)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, DateTime?>(FirmaValidationMessages.CompletionDateGreaterThanEqualToImplementationStartYear, m => m.CompletionDate));
            }

            if (CompletionDate < PlannedDate)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, DateTime?>(FirmaValidationMessages.CompletionDateGreaterThanEqualToPlannedDate, m => m.CompletionDate));
            }

            var currentYear = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting();

            if (ProjectStageID == ProjectStage.Implementation.ProjectStageID)
            {
                if (PlannedDate?.Year > currentYear)
                {
                    yield return(new SitkaValidationResult <BasicsViewModel, DateTime?>(
                                     FirmaValidationMessages.ImplementationYearMustBePastOrPresentForImplementationProjects,
                                     m => m.PlannedDate));
                }
            }

            if (PlannedDate == null && ProjectStageID != ProjectStage.Cancelled.ProjectStageID)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, DateTime?>(
                                 $"Implementation year is required when the {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} stage is not Deferred or Terminated",
                                 m => m.PlannedDate));
            }

            if (ProjectStageID == ProjectStage.Completed.ProjectStageID && !CompletionDate.HasValue)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, DateTime?>($"Since the {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} is in the Completed stage, the Completion year is required", m => m.CompletionDate));
            }
            if (ProjectStageID == ProjectStage.Completed.ProjectStageID)
            {
                var landownerCostShareLineItemsOnProject = HttpRequestStorage.DatabaseEntities.GrantAllocationAwardLandownerCostShareLineItems.Where(x => x.ProjectID == ProjectID).ToList();
                if (landownerCostShareLineItemsOnProject.Any(x => x.LandownerCostShareLineItemStatus == LandownerCostShareLineItemStatus.Planned))
                {
                    yield return(new SitkaValidationResult <BasicsViewModel, int?>($"Before marking the {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} completed, all {Models.FieldDefinition.GrantAllocationAwardLandownerCostShareLineItem} Treatments must be Completed or Cancelled.", m => m.ProjectStageID));
                }
            }


            if ((ProjectStageID == ProjectStage.Completed.ProjectStageID) && CompletionDate?.Year > currentYear)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, DateTime?>(FirmaValidationMessages.CompletionDateMustBePastOrPresentForCompletedProjects, m => m.CompletionDate));
            }

            if (ProjectStageID == ProjectStage.Planned.ProjectStageID && PlannedDate?.Year > currentYear)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, DateTime?>(
                                 $"Since the {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} is in the Planning / Design stage, the Planning / Design start year must be less than or equal to the current year",
                                 m => m.PlannedDate));
            }
        }
        public static List <int> CalculateCalendarYearRangeForExpendituresWithoutAccountingForExistingYears(this ProjectUpdate projectUpdate)
        {
            if (projectUpdate.CompletionYear < projectUpdate.ImplementationStartYear)
            {
                return(new List <int>());
            }
            if (projectUpdate.CompletionYear < projectUpdate.PlanningDesignStartYear)
            {
                return(new List <int>());
            }

            return(FirmaDateUtilities.CalculateCalendarYearRangeForExpendituresAccountingForExistingYears(new List <int>(), projectUpdate, FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting()));
        }
Exemple #14
0
        public IEnumerable <ValidationResult> GetValidationResults()
        {
            var projects = HttpRequestStorage.DatabaseEntities.Projects.ToList();

            if (!Enum.IsDefined(typeof(ProjectCategoryEnum), ProjectCategoryEnum))
            {
                yield return(new SitkaValidationResult <BasicsViewModel, ProjectCategoryEnum>($"A valid value for {FieldDefinitionEnum.ProjectCategory.ToType().GetFieldDefinitionLabel()} is required.", m => m.ProjectCategoryEnum));
            }

            if (TaxonomyLeafID == -1)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>($"{MultiTenantHelpers.GetTaxonomyLeafDisplayNameForProject()} is required.", m => m.TaxonomyLeafID));
            }

            if (!ProjectModelExtensions.IsProjectNameUnique(projects, ProjectName, ProjectID))
            {
                yield return(new SitkaValidationResult <BasicsViewModel, string>(FirmaValidationMessages.ProjectNameUnique, m => m.ProjectName));
            }

            if (ImplementationStartYear < PlanningDesignStartYear)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>(FirmaValidationMessages.ImplementationStartYearGreaterThanPlanningDesignStartYear, m => m.ImplementationStartYear));
            }

            if (CompletionYear < ImplementationStartYear)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>(FirmaValidationMessages.CompletionYearGreaterThanEqualToImplementationStartYear, m => m.CompletionYear));
            }

            if (CompletionYear < PlanningDesignStartYear)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>(FirmaValidationMessages.CompletionYearGreaterThanEqualToPlanningDesignStartYear, m => m.CompletionYear));
            }

            var currentYear = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting();

            if (ProjectStageID == ProjectStage.Implementation.ProjectStageID)
            {
                if (ImplementationStartYear > currentYear)
                {
                    yield return(new SitkaValidationResult <BasicsViewModel, int?>(
                                     FirmaValidationMessages.ImplementationYearMustBePastOrPresentForImplementationProjects,
                                     m => m.ImplementationStartYear));
                }
            }

            if (ImplementationStartYear == null && ProjectStageID != ProjectStage.Terminated.ProjectStageID && ProjectStageID != ProjectStage.Deferred.ProjectStageID)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>(
                                 $"Implementation year is required when the {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} stage is not Deferred or Terminated",
                                 m => m.ImplementationStartYear));
            }

            if (ProjectStageID == ProjectStage.Completed.ProjectStageID && !CompletionYear.HasValue)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>($"Since the {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} is in the Completed stage, the Completion year is required", m => m.CompletionYear));
            }

            if (ProjectStageID == ProjectStage.PostImplementation.ProjectStageID && !CompletionYear.HasValue)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>($"Since the {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} is in the Post-Implementation stage, the Completion year is required", m => m.CompletionYear));
            }

            if ((ProjectStageID == ProjectStage.Completed.ProjectStageID || ProjectStageID == ProjectStage.PostImplementation.ProjectStageID) && CompletionYear > currentYear)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>(FirmaValidationMessages.CompletionYearMustBePastOrPresentForCompletedProjects, m => m.CompletionYear));
            }

            if (ProjectStageID == ProjectStage.PlanningDesign.ProjectStageID && PlanningDesignStartYear > currentYear)
            {
                yield return(new SitkaValidationResult <BasicsViewModel, int?>(
                                 $"Since the {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} is in the Planning / Design stage, the Planning / Design start year must be less than or equal to the current year",
                                 m => m.PlanningDesignStartYear));
            }

            if (TaxonomyLeafID != null && SecondaryProjectTaxonomyLeafIDs.ToList().Contains(TaxonomyLeafID.Value))
            {
                yield return(new SitkaValidationResult <BasicsViewModel, IEnumerable <int> >(
                                 $"Cannot have a {FieldDefinitionEnum.SecondaryProjectTaxonomyLeaf.ToType().GetFieldDefinitionLabel()} " +
                                 $"that is the same as the Primary {FieldDefinitionEnum.TaxonomyLeaf.ToType().GetFieldDefinitionLabel()}.",
                                 m => m.SecondaryProjectTaxonomyLeafIDs));
            }
        }
Exemple #15
0
        private PartialViewResult ViewEditTechnicalAssistanceRequests(Project project, EditTechnicalAssistanceRequestsViewModel viewModel)
        {
            var firmaPage = FirmaPageTypeEnum.TechnicalAssistanceInstructions.GetFirmaPage();
            var technicalAssistanceTypes = TechnicalAssistanceType.All;
            var fiscalYearStrings        = FirmaDateUtilities.GetRangeOfYears(MultiTenantHelpers.GetMinimumYear(), FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting() + 2).OrderByDescending(x => x).Select(x => new CalendarYearString(x)).ToList();
            var personDictionary         = HttpRequestStorage.DatabaseEntities.People.Where(x => x.RoleID == Role.Admin.RoleID || x.RoleID == Role.ProjectSteward.RoleID).OrderBy(x => x.LastName).ThenBy(x => x.FirstName).ToList().Select(x => new PersonSimple(x)).ToList();
            var viewData = new EditTechnicalAssistanceRequestsViewData(CurrentFirmaSession, firmaPage, project, technicalAssistanceTypes, fiscalYearStrings, personDictionary);

            return(RazorPartialView <EditTechnicalAssistanceRequests, EditTechnicalAssistanceRequestsViewData, EditTechnicalAssistanceRequestsViewModel>(viewData, viewModel));
        }
Exemple #16
0
        public static List <int> CalculateCalendarYearRangeForExpenditures(this IList <ProjectGrantAllocationExpenditureUpdate> projectGrantAllocationExpenditureUpdates, ProjectUpdate projectUpdate)
        {
            if (projectUpdate.GetCompletionYear() < projectUpdate.GetImplementationStartYear())
            {
                return(new List <int>());
            }
            if (projectUpdate.GetCompletionYear() < projectUpdate.PlannedDate.GetValueOrDefault().Year)
            {
                return(new List <int>());
            }

            var existingYears = projectGrantAllocationExpenditureUpdates.Select(x => x.CalendarYear).ToList();

            return(FirmaDateUtilities.CalculateCalendarYearRangeForExpendituresAccountingForExistingYears(existingYears, projectUpdate, FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting()));
        }
        public static List <int> CalculateCalendarYearRangeForExpenditures(this IList <ProjectFundingSourceExpenditureUpdate> projectFundingSourceExpenditureUpdates, ProjectUpdate projectUpdate)
        {
            if (projectUpdate.CompletionYear < projectUpdate.ImplementationStartYear)
            {
                return(new List <int>());
            }
            if (projectUpdate.CompletionYear < projectUpdate.PlanningDesignStartYear)
            {
                return(new List <int>());
            }

            var existingYears = projectFundingSourceExpenditureUpdates.Select(x => x.CalendarYear).ToList();

            return(FirmaDateUtilities.CalculateCalendarYearRangeForExpendituresAccountingForExistingYears(existingYears, projectUpdate, FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting()));
        }