R2 - zero values for future months

This commit is contained in:
Michał Zieliski
2024-07-03 13:43:57 +02:00
parent 85e7d9818b
commit d4bc74c292

View File

@@ -78,7 +78,11 @@ public class T4R2Processor
sourceCodes = ProcessHelper.ParseCodes(rawSourceCodes);
}
for (var month = 1; month <= DateTime.UtcNow.Month; month++)
List<string> lastSourceCodes = new List<string>();
for (var month = 1; month <= 12; month++)
{
if (month <= DateTime.UtcNow.Month)
{
var monthCopy = month;
var dataSource = _db.Layers.Where(x =>
@@ -90,6 +94,7 @@ public class T4R2Processor
.FirstOrDefault();
if (dataSource != null)
{
lastSourceCodes = dataSource.Records!.Select(x => x.Code!).ToList();
var news = dataSource.Records!
.Where(x => sourceCodes.Count <= 0 || sourceCodes.Contains(int.Parse(x.Code!)))
.Select(x =>
@@ -120,8 +125,30 @@ public class T4R2Processor
});
}
}
else
{
//0 values for future months
if (source.Desc1 == "FK2" || lastSourceCodes.Count <= 0) continue;
var news = lastSourceCodes
.Where(x => sourceCodes.Contains(int.Parse(x)))
.Select(x =>
{
var newRecord = new Record
{
Id = Guid.NewGuid(),
Code = x + month.ToString("D2"),
CreatedAt = DateTime.UtcNow,
ModifiedAt = DateTime.UtcNow,
Value1 = 0,
};
return newRecord;
}
).ToList();
newRecords.AddRange(news);
}
}
// year summery
// year summary
var dataSourceSum = _db.Layers.Where(x =>
x.Type == LayerType.Processed &&
!x.IsDeleted &&