@@ -45,6 +45,28 @@ public async Task<ProcessData> GetDataAsync()
45
45
}
46
46
47
47
#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
+ }
48
70
public string RateRequestUri
49
71
{
50
72
get
@@ -426,13 +448,14 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
426
448
{
427
449
var PSTZone = TimeZoneInfo . FindSystemTimeZoneById ( "Pacific Standard Time" ) ;
428
450
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 ") ;
430
452
try
431
453
{
432
454
var startTime = _timeProvider . GetTimestamp ( ) ;
433
455
_processParams = processParams ;
434
456
int businessDay = 0 ;
435
457
var entitySetName = "ccof_monthlyenrollmentreports" ;
458
+ int fiscalMonth = ( ( ( int ) _processParams . InitialEnrolmentReport . Month + 8 ) % 12 ) + 1 ;
436
459
// for Approved Parent fee
437
460
var MonthLogicalNameTemp = JsonNode . Parse ( monthLogicalNameString ) ? . AsArray ( ) ?? throw new Exception ( "Invalid JSON" ) ;
438
461
List < JsonNode > MonthLogicalNameArray = MonthLogicalNameTemp . Select ( node => node ! ) . ToList ( ) ;
@@ -456,11 +479,14 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
456
479
List < JsonNode > ApprovedParentFee = await FetchAllRecordsFromCRMAsync ( ApprovedParentFeeRequestUri ) ;
457
480
List < JsonNode > orgInfo = await FetchAllRecordsFromCRMAsync ( OrgRequestUri ) ;
458
481
List < JsonNode > facilityLicence = await FetchAllRecordsFromCRMAsync ( FacilityLicenceRequestUri ) ;
482
+ List < JsonNode > feeFloorExemptArray = await FetchAllRecordsFromCRMAsync ( FeeFloorExemptRequestUri ) ;
459
483
460
484
// Batch processing
461
485
//int batchSize = 1000;
462
486
// 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" ) ;
464
490
465
491
for ( int i = 0 ; i < _processParams . InitialEnrolmentReport . FacilityGuid . Count ( ) ; i += batchSize )
466
492
{
@@ -471,6 +497,14 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
471
497
int providerType = 100000000 ; // Group
472
498
// Fee Floor Exempt
473
499
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 ) ;
474
508
var org = orgInfo . FirstOrDefault ( node => node ? [ "accountid" ] ? . GetValue < string > ( ) == record ) ;
475
509
if ( org != null )
476
510
{
@@ -528,10 +562,10 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
528
562
? null : approvedParentfee3YK [ MonthLogicalName ] . GetValue < decimal > ( ) ,
529
563
[ "ccof_approvedparentfeeoosck" ] = ( approvedParentfeeOOSCK == null || approvedParentfeeOOSCK [ MonthLogicalName ] == null ||
530
564
approvedParentfeeOOSCK [ MonthLogicalName ] . GetValue < decimal > ( ) == 0 )
531
- ? null : approvedParentfee18to36 [ MonthLogicalName ] . GetValue < decimal > ( ) ,
565
+ ? null : approvedParentfeeOOSCK [ MonthLogicalName ] . GetValue < decimal > ( ) ,
532
566
[ "ccof_approvedparentfeeooscg" ] = ( approvedParentfeeOOSCG == null || approvedParentfeeOOSCG [ MonthLogicalName ] == null ||
533
567
approvedParentfeeOOSCG [ MonthLogicalName ] . GetValue < decimal > ( ) == 0 )
534
- ? null : approvedParentfeeOOSCK [ MonthLogicalName ] . GetValue < decimal > ( ) ,
568
+ ? null : approvedParentfeeOOSCG [ MonthLogicalName ] . GetValue < decimal > ( ) ,
535
569
[ "ccof_approvedparentfeepre" ] = ( approvedParentfeePre == null || approvedParentfeePre [ MonthLogicalName ] == null ||
536
570
approvedParentfeePre [ MonthLogicalName ] . GetValue < decimal > ( ) == 0 )
537
571
? null : approvedParentfeePre [ MonthLogicalName ] . GetValue < decimal > ( ) ,
@@ -574,7 +608,7 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
574
608
[ "ccof_reportextension" ] = new JsonObject ( )
575
609
{
576
610
// Approved Parent Fee
577
- [ "ccof_approvedparentfee0to18" ] = approvedParentFee [ "ccof_approvedparentfee18to36 " ] ? . DeepClone ( ) ,
611
+ [ "ccof_approvedparentfee0to18" ] = approvedParentFee [ "ccof_approvedparentfee0to18 " ] ? . DeepClone ( ) ,
578
612
[ "ccof_approvedparentfee18to36" ] = approvedParentFee [ "ccof_approvedparentfee18to36" ] ? . DeepClone ( ) ,
579
613
[ "ccof_approvedparentfee3yk" ] = approvedParentFee [ "ccof_approvedparentfee3yk" ] ? . DeepClone ( ) ,
580
614
[ "ccof_approvedparentfeeoosck" ] = approvedParentFee [ "ccof_approvedparentfeeoosck" ] ? . DeepClone ( ) ,
@@ -603,20 +637,20 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
603
637
} ;
604
638
createEnrolmentReportRequests . Add ( new CreateRequest ( entitySetName , EnrolmentReportToCreate ) ) ;
605
639
}
640
+ _logger . LogInformation ( CustomLogEvent . Process , TimeZoneInfo . ConvertTimeFromUtc ( DateTime . UtcNow , PSTZone ) . ToString ( "yyyy-MM-dd HH:mm:ss" ) + " Creating Draft ERs index:{index}" , i ) ;
606
641
var ERBatchResult = await _d365webapiservice . SendBatchMessageAsync ( _appUserService . AZSystemAppUser , createEnrolmentReportRequests , null ) ;
607
642
if ( ERBatchResult . Errors . Any ( ) )
608
643
{
609
644
var errorInfos = ProcessResult . Failure ( ProcessId , ERBatchResult . Errors , ERBatchResult . TotalProcessed , ERBatchResult . TotalRecords ) ;
610
645
611
646
_logger . LogError ( CustomLogEvent . Process , "Failed to Create Enrolment Report: {error}" , JsonValue . Create ( errorInfos ) ! . ToString ( ) ) ;
612
647
}
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.
615
649
}
616
650
var endtime = _timeProvider . GetTimestamp ( ) ;
617
651
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 " ) ;
620
654
return ProcessResult . Completed ( ProcessId ) . SimpleProcessResult ;
621
655
}
622
656
catch ( Exception ex )
0 commit comments