Skip to content

Commit fb8a283

Browse files
Merge pull request #97 from bcgov/BatchCreateDraftER20250917
Added FeeFloorExempt logic to Draft ER generation
2 parents 5ac95a8 + af12be7 commit fb8a283

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

.vs/CCOF/v17/.futdcache.v2

0 Bytes
Binary file not shown.

CCOF.Infrastructure.WebAPI/Services/Processes/Monthly Enrolment Report/P400GenerateMonthlyEnrolmentReport.cs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,28 @@ public async Task<ProcessData> GetDataAsync()
4545
}
4646

4747
#region Data Queries
48+
public string FeeFloorExemptRequestUri
49+
{
50+
get
51+
{
52+
var fetchXml = $$"""
53+
<fetch>
54+
<entity name="ccof_feefloorexempt">
55+
<attribute name="ccof_facility" />
56+
<attribute name="ccof_months" />
57+
<attribute name="ccof_name" />
58+
<attribute name="ccof_programyear" />
59+
<filter>
60+
<condition attribute="ccof_programyear" operator="eq" value="{{_processParams.InitialEnrolmentReport.ProgramYearId}}" />
61+
<condition attribute="statecode" operator="eq" value="0" />
62+
</filter>
63+
</entity>
64+
</fetch>
65+
""";
66+
var requestUri = $"ccof_feefloorexempts?$select=_ccof_facility_value,ccof_months,ccof_name,_ccof_programyear_value&$filter=(_ccof_programyear_value eq " + _processParams.InitialEnrolmentReport.ProgramYearId + " and statecode eq 0)";
67+
return requestUri.CleanCRLF();
68+
}
69+
}
4870
public string RateRequestUri
4971
{
5072
get
@@ -426,13 +448,14 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
426448
{
427449
var PSTZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
428450
var pstTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, PSTZone);
429-
_logger.LogInformation(CustomLogEvent.Process, pstTime.ToString("yyyy-MM-dd HH:mm:ss") + " Begin to Initial ER process");
451+
_logger.LogInformation(CustomLogEvent.Process, pstTime.ToString("yyyy-MM-dd HH:mm:ss") +" Starting Process P"+ ProcessId+" to Create Draft Monthly Enrolment Reports");
430452
try
431453
{
432454
var startTime = _timeProvider.GetTimestamp();
433455
_processParams = processParams;
434456
int businessDay = 0;
435457
var entitySetName = "ccof_monthlyenrollmentreports";
458+
int fiscalMonth = (((int)_processParams.InitialEnrolmentReport.Month + 8) % 12) + 1;
436459
// for Approved Parent fee
437460
var MonthLogicalNameTemp = JsonNode.Parse(monthLogicalNameString)?.AsArray() ?? throw new Exception("Invalid JSON");
438461
List<JsonNode> MonthLogicalNameArray = MonthLogicalNameTemp.Select(node => node!).ToList();
@@ -456,11 +479,14 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
456479
List<JsonNode> ApprovedParentFee = await FetchAllRecordsFromCRMAsync(ApprovedParentFeeRequestUri);
457480
List<JsonNode> orgInfo = await FetchAllRecordsFromCRMAsync(OrgRequestUri);
458481
List<JsonNode> facilityLicence = await FetchAllRecordsFromCRMAsync(FacilityLicenceRequestUri);
482+
List<JsonNode> feeFloorExemptArray = await FetchAllRecordsFromCRMAsync(FeeFloorExemptRequestUri);
459483

460484
// Batch processing
461485
//int batchSize = 1000;
462486
// int batchSize = 100;
463-
int batchSize = 50;
487+
// int batchSize = 50;
488+
int batchSize = 25;
489+
_logger.LogInformation("Creating Draft Monthly Enrolment Reports for " + _processParams.InitialEnrolmentReport.FacilityGuid.Count() +" Facilities");
464490

465491
for (int i = 0; i < _processParams.InitialEnrolmentReport.FacilityGuid.Count(); i += batchSize)
466492
{
@@ -471,6 +497,14 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
471497
int providerType = 100000000; // Group
472498
// Fee Floor Exempt
473499
Boolean feeFloorExempt = false;
500+
var FeeFloorExemptObject = feeFloorExemptArray.FirstOrDefault(node => node?["_ccof_facility_value"]?.GetValue<string>() == record);
501+
feeFloorExempt = FeeFloorExemptObject != null
502+
&& FeeFloorExemptObject["ccof_months"] != null
503+
&& FeeFloorExemptObject["ccof_months"]
504+
.ToString()
505+
.Split(',')
506+
.Select(v => int.Parse(v.Trim()))
507+
.Contains(fiscalMonth);
474508
var org = orgInfo.FirstOrDefault(node => node?["accountid"]?.GetValue<string>() == record);
475509
if (org != null)
476510
{
@@ -528,10 +562,10 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
528562
? null : approvedParentfee3YK[MonthLogicalName].GetValue<decimal>(),
529563
["ccof_approvedparentfeeoosck"] = (approvedParentfeeOOSCK == null || approvedParentfeeOOSCK[MonthLogicalName] == null ||
530564
approvedParentfeeOOSCK[MonthLogicalName].GetValue<decimal>() == 0)
531-
? null : approvedParentfee18to36[MonthLogicalName].GetValue<decimal>(),
565+
? null : approvedParentfeeOOSCK[MonthLogicalName].GetValue<decimal>(),
532566
["ccof_approvedparentfeeooscg"] = (approvedParentfeeOOSCG == null || approvedParentfeeOOSCG[MonthLogicalName] == null ||
533567
approvedParentfeeOOSCG[MonthLogicalName].GetValue<decimal>() == 0)
534-
? null : approvedParentfeeOOSCK[MonthLogicalName].GetValue<decimal>(),
568+
? null : approvedParentfeeOOSCG[MonthLogicalName].GetValue<decimal>(),
535569
["ccof_approvedparentfeepre"] = (approvedParentfeePre == null || approvedParentfeePre[MonthLogicalName] == null ||
536570
approvedParentfeePre[MonthLogicalName].GetValue<decimal>() == 0)
537571
? null : approvedParentfeePre[MonthLogicalName].GetValue<decimal>(),
@@ -574,7 +608,7 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
574608
["ccof_reportextension"] = new JsonObject()
575609
{
576610
// Approved Parent Fee
577-
["ccof_approvedparentfee0to18"] = approvedParentFee["ccof_approvedparentfee18to36"]?.DeepClone(),
611+
["ccof_approvedparentfee0to18"] = approvedParentFee["ccof_approvedparentfee0to18"]?.DeepClone(),
578612
["ccof_approvedparentfee18to36"] = approvedParentFee["ccof_approvedparentfee18to36"]?.DeepClone(),
579613
["ccof_approvedparentfee3yk"] = approvedParentFee["ccof_approvedparentfee3yk"]?.DeepClone(),
580614
["ccof_approvedparentfeeoosck"] = approvedParentFee["ccof_approvedparentfeeoosck"]?.DeepClone(),
@@ -603,20 +637,20 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
603637
};
604638
createEnrolmentReportRequests.Add(new CreateRequest(entitySetName, EnrolmentReportToCreate));
605639
}
640+
_logger.LogInformation(CustomLogEvent.Process, TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, PSTZone).ToString("yyyy-MM-dd HH:mm:ss") + " Creating Draft ERs index:{index}", i);
606641
var ERBatchResult = await _d365webapiservice.SendBatchMessageAsync(_appUserService.AZSystemAppUser, createEnrolmentReportRequests, null);
607642
if (ERBatchResult.Errors.Any())
608643
{
609644
var errorInfos = ProcessResult.Failure(ProcessId, ERBatchResult.Errors, ERBatchResult.TotalProcessed, ERBatchResult.TotalRecords);
610645

611646
_logger.LogError(CustomLogEvent.Process, "Failed to Create Enrolment Report: {error}", JsonValue.Create(errorInfos)!.ToString());
612647
}
613-
_logger.LogInformation(CustomLogEvent.Process, pstTime.ToString("yyyy-MM-dd HH:mm:ss") + " Create Batch process record index:{index}", i);
614-
await Task.Delay(10000); // deplay 10 seconds avoid api throtting.
648+
await Task.Delay(5000); // deplay 5 seconds avoid api throtting.
615649
}
616650
var endtime = _timeProvider.GetTimestamp();
617651
var timediff = _timeProvider.GetElapsedTime(startTime, endtime).TotalSeconds;
618-
_logger.LogInformation(CustomLogEvent.Process, pstTime.ToString("yyyy-MM-dd HH:mm:ss") + " Total time:" + Math.Round(timediff, 2) + " seconds.\r\n");
619-
_logger.LogInformation(CustomLogEvent.Process, pstTime.ToString("yyyy-MM-dd HH:mm:ss") + "End Create ER Batch process record");
652+
_logger.LogInformation(CustomLogEvent.Process, TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, PSTZone).ToString("yyyy-MM-dd HH:mm:ss") + " Total time:" + Math.Round(timediff, 2) + " seconds.\r\n");
653+
_logger.LogInformation(CustomLogEvent.Process, TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, PSTZone).ToString("yyyy-MM-dd HH:mm:ss") + " Create ER Batch process records is Complete");
620654
return ProcessResult.Completed(ProcessId).SimpleProcessResult;
621655
}
622656
catch (Exception ex)

0 commit comments

Comments
 (0)