diff --git a/AsbCloudApp/Data/DailyReport/DailyReportDto.cs b/AsbCloudApp/Data/DailyReport/DailyReportDto.cs
index 781a6717..920aeb54 100644
--- a/AsbCloudApp/Data/DailyReport/DailyReportDto.cs
+++ b/AsbCloudApp/Data/DailyReport/DailyReportDto.cs
@@ -14,7 +14,7 @@
///
/// блок КНБК
///
- public BhaDto? Bha { get; set; } = new();
+ public BhaDto Bha { get; set; } = new();
///
/// блок безметражные работы
diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs
index ecdd7d15..807b10ca 100644
--- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs
+++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs
@@ -124,24 +124,24 @@ namespace AsbCloudInfrastructure.Services.DailyReport
ClusterName = well?.Cluster ?? "",
},
TimeBalance = await MakeTimeBalanceAsync(idWell, date, token),
- Bha = await GetPrevBhaAsync(idWell, date, token)
+ Bha = await GetPrevOrNewBhaAsync(idWell, date, token)
};
return dto;
}
- private async Task GetPrevBhaAsync(int idWell, DateTime date, CancellationToken token)
+ private async Task GetPrevOrNewBhaAsync(int idWell, DateTime date, CancellationToken token)
{
var dateOffset = date.Date;
var entity = await db.DailyReports
+ .Where(x => x.IdWell == idWell)
.OrderByDescending(x => x.StartDate)
- .FirstOrDefaultAsync(r => r.IdWell == idWell &&
- r.StartDate.Year <= dateOffset.Year &&
- r.StartDate.DayOfYear <= dateOffset.DayOfYear, token);
+ .FirstOrDefaultAsync(r => r.StartDate <= dateOffset, token);
if (entity is null)
- return null;
+ return new BhaDto();
+
var dto = Convert(entity);
- return dto?.Bha;
+ return dto.Bha;
}
private async Task MakeTimeBalanceAsync(int idWell, DateTime date, CancellationToken token)