public void WhenRangeTwoWeeks_ExpectListOfDaysExcludingWeekends() { // arrange var sut = new ReportingPeriod { Start = DateTime.Parse("2018-07-01"), End = DateTime.Parse("2018-07-15"), Weekends = new List <DayOfWeek> { DayOfWeek.Saturday, DayOfWeek.Sunday } }; // act var actual = sut.Generate_Dates_For_Range(); // assert var expected = new List <DateTime> { DateTime.Parse("2018-07-02"), DateTime.Parse("2018-07-03"), DateTime.Parse("2018-07-04"), DateTime.Parse("2018-07-05"), DateTime.Parse("2018-07-06"), DateTime.Parse("2018-07-09"), DateTime.Parse("2018-07-10"), DateTime.Parse("2018-07-11"), DateTime.Parse("2018-07-12"), DateTime.Parse("2018-07-13") }; actual.Should().BeEquivalentTo(expected); }
public static Report CreateCdcReport( HedwigContext context, ReportingPeriod reportingPeriod = null, Organization organization = null, string submittedAt = null ) { reportingPeriod = reportingPeriod ?? ReportingPeriodHelper.CreateReportingPeriod(context, type: FundingSource.CDC); organization = organization ?? OrganizationHelper.CreateOrganization(context); var report = new CdcReport { ReportingPeriodId = reportingPeriod.Id, OrganizationId = organization.Id }; if (submittedAt != null) { report.SubmittedAt = DateTime.Parse(submittedAt); } context.Reports.Add(report); context.SaveChanges(); return(report); }
public SourceControlAnalysis Build() { if (NotValidGitRepository(_repoPath)) { throw new Exception($"Invalid path [{_repoPath}]"); } var repository = new Repository(_repoPath); if (InvalidBranchName(repository)) { throw new Exception($"Invalid branch [{_branch}]"); } var reportRange = new ReportingPeriod { Start = _start, End = _end, HoursPerWeek = _workWeekHours, DaysPerWeek = _workingDaysPerWeek, Weekends = _weekends }; if (_isEntireHistory) { MakeRangeEntireHistory(repository, reportRange); } var aliasMapping = new Aliases(_aliasMapping); var context = CreateSourceControlContext(reportRange); return(new SourceControlAnalysis(repository, aliasMapping, context)); }
/// <summary> /// Gets a list of the currently displayed Result Types /// </summary> /// <param name="showDeleted">Default to show deleted Result Types as well</param> /// <returns>List of DisplayResultTypes</returns> public List <DisplayResultType> GetDisplayedResultTypes(bool showDeleted = true) { List <DisplayResultType> returnList = new List <DisplayResultType>(); SetCheckBox(ShowDeleted, showDeleted); ScrollToBottom(); foreach (SnapshotElementScope row in browser.FindAllXPath("//tr[contains(@ng-repeat, 'resultTypes')]")) { DisplayResultType addItem = new DisplayResultType() { Name = row.FindXPath("td[1]").Text.Trim(), UoM = row.FindXPath("td[2]").Text.Trim(), IsDefault = row.FindXPath("td[4]/input").Selected, Edit = new HpgElement(row.FindXPath("td[5]").FindButton("Edit")), Delete = new HpgElement(row.FindXPath("td[5]").FindButton("Delete")), UndoDelete = new HpgElement(row.FindXPath("td[5]").FindButton("Undo Delete")) }; string cellText = row.FindXPath("td[3]").Text.Trim(); //Reporting Period addItem.ReportingPeriod = ReportingPeriod.None; if (!string.IsNullOrEmpty(cellText)) { ReportingPeriod pOut = new ReportingPeriod(); if (ReportingPeriod.TryParse(cellText, true, out pOut)) { addItem.ReportingPeriod = pOut; } } returnList.Add(addItem); } return(returnList); }
private static double CalculateRepositoryAverageWorkingDaysPerWeek(ReportingPeriod reportingPeriod) { var percentDaysWorked = 0.64; // note: based on gitprime's stat of 3.2 for 5 day work week as a global average var repoAvg = (reportingPeriod.DaysPerWeek * percentDaysWorked); return(repoAvg); }
public async Task <Result <IndicatorResponse> > Handle(SubmitIndicatorResultsCommand request, CancellationToken cancellationToken) { using (var transaction = _airUnitOfWork.BeginTransaction(IsolationLevel.ReadCommitted)) { try { var reportingPeriod = new ReportingPeriod(request.ReportingFormId, request.ReportingDate, request.CreatedBy); await _airUnitOfWork.Repository <ReportingPeriod>().AddAsync(reportingPeriod); var indicatorResults = request.IndicatorResults.Select(x => new IndicatorResult(reportingPeriod.Id, x.Id, x.ResultText, x.ResultNumeric, request.CreatedBy)); await _airUnitOfWork.Repository <IndicatorResult>().AddRangeAsync(indicatorResults); await _airUnitOfWork.SaveAsync(); transaction.Commit(); return(Result <IndicatorResponse> .Valid(new IndicatorResponse() { Message = "Indicator results added succesfully", ReportingFormId = request.ReportingFormId })); } catch (Exception ex) { _logger.Error(ex, $"An error occured while submitting indicator results for period {request.ReportingDate} and ReportId {request.ReportingFormId}"); transaction.Rollback(); return(Result <IndicatorResponse> .Invalid("An error occured while submittig indicator results")); } } }
public static Funding CreateFunding( HedwigContext context, FundingSource source = FundingSource.CDC, Enrollment enrollment = null, ReportingPeriod firstReportingPeriod = null, ReportingPeriod lastReportingPeriod = null, FundingSpace fundingSpace = null ) { enrollment = enrollment ?? EnrollmentHelper.CreateEnrollment(context); fundingSpace = fundingSpace ?? FundingSpaceHelper.CreateFundingSpace(context, enrollment.Site.OrganizationId); var funding = new Funding { EnrollmentId = enrollment.Id, Source = source, FirstReportingPeriodId = firstReportingPeriod != null ? firstReportingPeriod.Id : null as int?, LastReportingPeriodId = lastReportingPeriod != null ? lastReportingPeriod.Id : null as int?, FundingSpaceId = fundingSpace != null ? fundingSpace.Id : null as int? }; context.Fundings.Add(funding); context.SaveChanges(); return(funding); }
public void GetReportingPreviousTerm_Quarterly_ReturnsExpectedResult(ReportingTerm reportingTerm) { var year = 2019; var reportingPeriod = new ReportingPeriod(ReportingFrequency.Quarterly, reportingTerm, year); var reportingPeriodOfPreviousTerm = reportingPeriod.GetReportingPeriodOfPreviousTerm(); if (reportingTerm == ReportingTerm.Two) { reportingPeriodOfPreviousTerm.Year.Should().Be(year - 1); reportingPeriodOfPreviousTerm.ReportingTerm.Should().Be(ReportingTerm.One); return; } if (reportingTerm == ReportingTerm.One) { reportingPeriodOfPreviousTerm.Year.Should().Be(year); var previousReportingTerInt = (int)reportingPeriodOfPreviousTerm.ReportingTerm; previousReportingTerInt.Should().Be(4); return; } else { reportingPeriodOfPreviousTerm.Year.Should().Be(year); var reportingTermInt = (int)reportingTerm; var previousReportingTerInt = (int)reportingPeriodOfPreviousTerm.ReportingTerm; previousReportingTerInt.Should().Be(reportingTermInt - 1); } }
public async Task <IActionResult> PutReportingPeriod([FromRoute] int id, [FromBody] ReportingPeriod reportingPeriod) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != reportingPeriod.Id) { return(BadRequest()); } _context.Entry(reportingPeriod).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReportingPeriodExists(id)) { return(NotFound()); } else { throw; } } return(Ok(reportingPeriod)); }
public void GetReportingNextTerm_Monthly_ReturnsExpectedResult(ReportingTerm reportingTerm) { var year = 2019; var reportingPeriod = new ReportingPeriod(ReportingFrequency.Monthly, reportingTerm, year); var reportingPeriodOfNextTerm = reportingPeriod.GetReportingPeriodOfNextTerm(); if (reportingTerm == ReportingTerm.Twelve) { reportingPeriodOfNextTerm.Year.Should().Be(year); reportingPeriodOfNextTerm.ReportingTerm.Should().Be(ReportingTerm.One); return; } if (reportingTerm == ReportingTerm.Three) { reportingPeriodOfNextTerm.Year.Should().Be(year + 1); var nextReportingTerInt = (int)reportingPeriodOfNextTerm.ReportingTerm; nextReportingTerInt.Should().Be(4); return; } else { reportingPeriodOfNextTerm.Year.Should().Be(year); var reportingTermInt = (int)reportingTerm; var nextReportingTerInt = (int)reportingPeriodOfNextTerm.ReportingTerm; nextReportingTerInt.Should().Be(reportingTermInt + 1); } }
private static IReadOnlyList <Datapoint <T> > AddDatapointsWithGapLikely <T>( IReadOnlyList <Datapoint <T> > datapoints, ReportingPeriod reportingPeriod, TimeComparison timeComparison) { var result = new List <Datapoint <T> >(); var adjacentReportingPeriod = GetAdjacentBoundedReportingPeriod(reportingPeriod, timeComparison); // Most likely will result in a gap in the timeseries and also possibly datapoints in different granularity. var adjacentDatapoints = adjacentReportingPeriod .GetUnitsWithin() .Select(_ => _.ToReportingPeriod()) .Select(_ => new Datapoint <T>(_, A.Dummy <T>())) .ToList(); if (timeComparison == TimeComparison.After) { result.AddRange(datapoints); result.AddRange(adjacentDatapoints); } else { result.AddRange(adjacentDatapoints); result.AddRange(datapoints); } return(result); }
private static ReportingPeriod GetAdjacentBoundedReportingPeriod( ReportingPeriod reportingPeriod, TimeComparison timeComparison) { ReportingPeriod result; if (timeComparison == TimeComparison.After) { result = A.Dummy <ReportingPeriod>() .Whose(_ => (!_.HasComponentWithUnboundedGranularity()) && (_.GetUnitOfTimeKind() == reportingPeriod.GetUnitOfTimeKind()) && (_.Start.ToMostGranular().Start > reportingPeriod.End.ToMostGranular().End)); } else if (timeComparison == TimeComparison.Before) { result = A.Dummy <ReportingPeriod>() .Whose(_ => (!_.HasComponentWithUnboundedGranularity()) && (_.GetUnitOfTimeKind() == reportingPeriod.GetUnitOfTimeKind()) && (_.End.ToMostGranular().End < reportingPeriod.Start.ToMostGranular().Start)); } else { throw new NotSupportedException(Invariant($"This {nameof(TimeComparison)} is not supported: {timeComparison}.")); } return(result); }
public CentralReport GetLastSubmittedCentralReport(int organizationId, ReportingPeriod reportingPeriod, int pastTermCycle = 1) { var reportingPeriodOfPreviousTerm1 = reportingPeriod.GetReportingPeriodOfPreviousTerm(); var reportIds = _session.Query <Report>() .Where(o => o.Organization.OrganizationType == OrganizationType.State && o.Organization.Id == organizationId && o.ReportStatus == ReportStatus.Submitted && o.ReportingPeriod.EndDate < reportingPeriod.StartDate && o.ReportingPeriod.StartDate >= reportingPeriodOfPreviousTerm1.StartDate) .OrderByDescending(o => o.ReportingPeriod.EndDate) .Select(o => o.Id) .ToArray(); var centralReports = _session.Query <CentralReport>() .Where(r => reportIds.Contains(r.Id)).ToArray(); if (centralReports.Length == 0 && pastTermCycle <= 3) { return(GetLastSubmittedCentralReport(organizationId, reportingPeriodOfPreviousTerm1, pastTermCycle + 1)); } return(centralReports.FirstOrDefault()); }
private void MakeRangeEntireHistory(Repository repository, ReportingPeriod reportRange) { var commits = GetCommitsForSelectedBranch(repository); reportRange.Start = GetFirstCommit(commits); reportRange.End = GetLastCommit(commits); }
public bool HasCdcReportForOrganizationAndReportingPeriod(int orgId, ReportingPeriod period) { return(_context.Reports .OfType <CdcReport>() .Where(report => report.OrganizationId == orgId) .Where(report => report.ReportingPeriodId == period.Id) .FirstOrDefault() != null); }
public static UnitReport[] GetSubmittedReports(UnitReport[] unitReports, ReportingPeriod reportingPeriod) { return(unitReports.Where(o => o.ReportStatus == ReportStatus.Submitted && o.ReportingPeriod.EndDate <= reportingPeriod.EndDate && o.ReportingPeriod.StartDate >= reportingPeriod.StartDate).ToArray()); }
/// <summary> /// Initializes a new instance of the <see cref="ReportingPeriodWrapper"/> class. /// </summary> /// <param name="start">The start of the reporting period.</param> /// <param name="end">The end of the reporting period.</param> protected ReportingPeriodWrapper( UnitOfTime start, UnitOfTime end) { var reportingPeriod = new ReportingPeriod(start, end); this.ReportingPeriod = reportingPeriod; }
public void Should_Initalize_Weekends() { // arrange // act var sut = new ReportingPeriod(); // assert sut.Weekends.Should().NotBeNull(); }
private void GetStartEndDateForReportingPeriod(ReportingPeriod reportingPeriod, out ExDateTime startDateTime, out ExDateTime endDateTime) { startDateTime = ExDateTime.MinValue; endDateTime = ExDateTime.MaxValue; ExDateTime date = ExDateTime.UtcNow.Date; switch (reportingPeriod) { case ReportingPeriod.Today: startDateTime = date; endDateTime = startDateTime.Add(TimeSpan.FromDays(1.0)).Subtract(TimeSpan.FromMinutes(1.0)); return; case ReportingPeriod.Yesterday: startDateTime = date.Subtract(TimeSpan.FromDays(1.0)); endDateTime = startDateTime.AddDays(1.0).Subtract(TimeSpan.FromMinutes(1.0)); return; case ReportingPeriod.LastWeek: startDateTime = date.Subtract(TimeSpan.FromDays((double)(7 + date.DayOfWeek))); endDateTime = date.Subtract(TimeSpan.FromDays((double)date.DayOfWeek)).Subtract(TimeSpan.FromMinutes(1.0)); return; case ReportingPeriod.LastMonth: startDateTime = GetAvailabilityReport <TIdentity> .SubtractMonths(date, 1); endDateTime = GetAvailabilityReport <TIdentity> .GetLastMonthLastDate(date); return; case ReportingPeriod.Last3Months: startDateTime = GetAvailabilityReport <TIdentity> .SubtractMonths(date, 3); endDateTime = GetAvailabilityReport <TIdentity> .GetLastMonthLastDate(date); return; case ReportingPeriod.Last6Months: startDateTime = GetAvailabilityReport <TIdentity> .SubtractMonths(date, 6); endDateTime = GetAvailabilityReport <TIdentity> .GetLastMonthLastDate(date); return; case ReportingPeriod.Last12Months: startDateTime = GetAvailabilityReport <TIdentity> .SubtractMonths(date, 12); endDateTime = GetAvailabilityReport <TIdentity> .GetLastMonthLastDate(date); return; default: base.WriteError(new ArgumentException(Strings.InvalidReportingPeriod), (ErrorCategory)1000, null); return; } }
public void CreateNewUnitPlan_SavesCorrectlyWhenLastYearSubmitted(ReportingFrequency reportingFrequency) { DateTimeDbTestExtensions.SetUtcNowToRandomDate(); var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s => { var organizationType = OrganizationType.Unit; var description = DataProvider.Get <string>(); var year = 2019; var reportingTerm = ReportingTerm.One; var organization = new TestObjectBuilder <Organization>() .SetArgument(o => o.OrganizationType, organizationType) .SetArgument(o => o.ReportingFrequency, reportingFrequency) .BuildAndPersist(s); OrganizationReference organizationRef = organization; var reportingPeriod = new ReportingPeriod(reportingFrequency, reportingTerm, year); var expected = new UnitReportBuilder() .SetDescription(description) .SetOrganization(organization) .SetReportingPeriod(new ReportingPeriod(reportingFrequency, reportingTerm, year)) .SetReportData(ReportData.Default()) .Build(); return(new { description, organizationRef, reportingPeriod, expected }); }); var result = Endpoint.Act(AssemblySetupFixture.EndpointTestContainer, c => { var unitReport = c.GetInstance <UnitReportFactory>() .CreateNewUnitPlan(testParams.description, testParams.organizationRef, testParams.reportingPeriod.ReportingTerm, testParams.reportingPeriod.Year, reportingFrequency); return(new { unitReport }); }); result.unitReport.Should().NotBeNull(); result.unitReport.Should().BeEquivalentTo(testParams.expected, e => e.Excluding(p => p.Id)); }
private string GetDescription() { var reportingPeriod = new ReportingPeriod(ReportingFrequency, ReportingTerm, Year); var monthStart = reportingPeriod.StartDate.ToString("MMM"); var monthEnd = reportingPeriod.EndDate.ToString("MMM"); var description = $"{reportingPeriod.StartDate.Year}_{monthStart}-{reportingPeriod.EndDate.Year}_{monthEnd}_{OrganizationType.Central}_{Organization.Description}"; return(description); }
private decimal GetStopTime(decimal hours, ReportingPeriod reportingPeriod) { if (hours <= 0) { hours = 8m; } var calculator = new ReportCalculator( Storage, reportingPeriod,
public Report CreateNewReport(string description, OrganizationReference organizationRef, ReportingTerm reportingTerm, int year) { var organization = _session.Query <Organization>().Single(o => o.Id == organizationRef.Id); var reportingPeriod = new ReportingPeriod(organization.ReportingFrequency, reportingTerm, year); var report = new Report(description, organization, reportingPeriod, null); _session.Save(report); return(report); }
/// <summary> /// Changes the Edit Result Type fields to the specified ResultType /// </summary> /// <param name="resultType"></param> public void EditResult(ResultType resultType) { Name.Type(resultType.Name); UoM.Type(resultType.UoM); SetCheckBox(IsDefault, resultType.IsDefault); ReportingPeriod.SelectListOptionByText(resultType.ReportingPeriod.ToString()); System.Threading.Thread.Sleep(1000); //give it a couple seconds to catch up SaveButton.Click(); System.Threading.Thread.Sleep(1000); //give it a couple seconds to save }
public static UnitReport GetLastSubmittedReport(UnitReport[] unitReports, ReportingPeriod reportingPeriod) { return(unitReports.Where(o => o.ReportStatus == ReportStatus.Submitted && o.ReportingPeriod.EndDate <= reportingPeriod.EndDate && o.ReportingPeriod.StartDate >= reportingPeriod.StartDate).OrderByDescending(o => o.ReportingPeriod.EndDate) .Select(o => o) .FirstOrDefault()); }
public ActionResult Create(ReportingPeriod reportingPeriod) { //1 для первого дня, т.к есть только год и месяц var currentDate = new DateTime(reportingPeriod.Year, reportingPeriod.Month, 1); var firstDayOnNextMonth = new DateTime(currentDate.Year, currentDate.AddMonths(1).Month, 1); DateTime firstDayPlusTwoMonths = firstDayOnNextMonth.AddMonths(2); DateTime lastDayNextMonth = firstDayPlusTwoMonths.AddDays(-1); DateTime endOfLastDayNextMonth = firstDayPlusTwoMonths.AddTicks(-1); if (reportingPeriod.NewTSRecordsAllowedUntilDate == new DateTime()) { //Если указан декабрь if (currentDate.Month == 12) { reportingPeriod.NewTSRecordsAllowedUntilDate = new DateTime(currentDate.AddYears(1).Year, currentDate.AddMonths(1).Month, 3); } else { reportingPeriod.NewTSRecordsAllowedUntilDate = new DateTime(currentDate.Year, currentDate.AddMonths(1).Month, 3); } } else { var setValue = reportingPeriod.NewTSRecordsAllowedUntilDate; //Если указан не тот год или отчитаться на следующий год //if (DateTime.Now.Year != setValue.Year || currentDate.AddMonths(1).Year != DateTime.Now.Year) // ModelState.AddModelError("NewTSRecordsAllowedUntilDate", "Вы не можете указать дату окончания в декабре на январь или указан не тот год"); if (setValue < firstDayOnNextMonth) { ModelState.AddModelError("NewTSRecordsAllowedUntilDate", "Вам надо указать дату включительно " + "от первого числа следующего месяца"); } } if (reportingPeriod.TSRecordsEditApproveAllowedUntilDate <= firstDayOnNextMonth) { ModelState.AddModelError("TSRecordsEditApproveAllowedUntilDate", "Дата полного закрытия должна быть не раньше первого числа следующего месяца."); } if (reportingPeriod.TSRecordsEditApproveAllowedUntilDate <= reportingPeriod.NewTSRecordsAllowedUntilDate) { ModelState.AddModelError("TSRecordsEditApproveAllowedUntilDate", "Дата полного закрытия не должна быть меньше или равна дате закрытия месяца."); } ModelState.Clear(); if (ModelState.IsValid) { _reportingPeriodService.Add(reportingPeriod); return(RedirectToAction("Index")); } SetViewBag(reportingPeriod); return(View(reportingPeriod)); }
private ReportingPeriod GetDefaultPeriodSettings() { var wk = WeekDTO.CreateWithWeekContaining(DateTime.Now); var ps = new ReportingPeriod() { Start = wk.WeekStart, End = wk.WeekEnd }; return(ps); }
public static int NumberOfWeeks(this ReportingPeriod reportingPeriod) { var reportingPeriodEnd = reportingPeriod.PeriodEnd; var modifiedReportingPeriodEnd = reportingPeriodEnd.AddDays(1); var reportingPeriodStart = reportingPeriod.PeriodStart; var difference = reportingPeriodEnd.Subtract(reportingPeriodStart); var differenceInDays = difference.TotalDays; var differenceInWeeks = differenceInDays / 7; return((int)Math.Ceiling(differenceInWeeks)); }
public async Task <IActionResult> PostReportingPeriod([FromBody] ReportingPeriod reportingPeriod) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.ReportingPeriods.Add(reportingPeriod); await _context.SaveChangesAsync(); return(CreatedAtAction("GetReportingPeriod", new { id = reportingPeriod.Id }, reportingPeriod)); }
private AnalysisContext CreateSourceControlContext(ReportingPeriod reportRange) { var context = new AnalysisContext { ReportRange = reportRange, Branch = Branch.Create(_branch), IgnorePatterns = _ignorePatterns, IgnoreComments = _ignoreComments }; return(context); }
public void SetValues(SchoolPeriod schoolPeriod, ReportingPeriod reportingPeriod, School school, SchoolDistrict district) { SetValue(CommonPlacholder.DistrictName, district.Name); SetValue(CommonPlacholder.PeriodName, reportingPeriod.Name); SetValue(CommonPlacholder.SchoolName, school.Name); }