Skip to content

Commit

Permalink
Update Monthly Amount on Supplementary
Browse files Browse the repository at this point in the history
  • Loading branch information
bcgov-hl committed Jul 17, 2024
1 parent 782d2dd commit ea78d80
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ private dynamic RawFTEsData
get
{
var actionsLog = _fundingResult.ActionsLog;
//var first = actionsLog.FirstOrDefault();
//var licenceDetails = first["LicenceDetails"];
//var deserilized = JsonSerializer.Deserialize<List<LicenceDetail>>(licenceDetails.ToJsonString());

var rawFTEs = actionsLog.GroupBy(act => act.LicenceType).Select(sdd => new
{
//sdd.First().Step,
Expand Down Expand Up @@ -126,10 +122,6 @@ private dynamic AdjustedFTEsData
get
{
var actionsLog = _fundingResult.ActionsLog;
//var first = actionsLog.FirstOrDefault();
//var licenceDetails = first["LicenceDetails"];
//var deserilized = JsonSerializer.Deserialize<List<LicenceDetail>>(licenceDetails.ToJsonString());

var adjustedFTEs = actionsLog.GroupBy(act => act.LicenceType).Select(ld => new
{
//sdd.First().Step,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OFM.Infrastructure.WebAPI.Extensions;
using ECC.Core.DataContext;
using OFM.Infrastructure.WebAPI.Extensions;
using OFM.Infrastructure.WebAPI.Models.Fundings;
using OFM.Infrastructure.WebAPI.Services.AppUsers;
using OFM.Infrastructure.WebAPI.Services.D365WebApi;
Expand Down Expand Up @@ -194,6 +195,7 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
#region Step 2: Calculate Allowance

decimal calculatedFundingAmount = 0.0M;
decimal calculatedMonthlyAmount = 0.0M;
/*
Support Needs Programming = 1
Indigenous Programming = 2
Expand Down Expand Up @@ -234,16 +236,16 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
case 3:
//if lease = Yes

int numberOfMonths = (supplementary.ofm_end_date.Year - supplementary.ofm_start_date.Year) * 12 + supplementary.ofm_end_date.Month - supplementary.ofm_start_date.Month + 1;
int numberOfMonths = (supplementary.ofm_end_date.Value.Year - supplementary.ofm_start_date.Value.Year) * 12 + supplementary.ofm_end_date.Value.Month - supplementary.ofm_start_date.Value.Month + 1;

if (supplementary.ofm_transport_monthly_lease is not null)
{
calculatedFundingAmount += (decimal)supplementary.ofm_transport_monthly_lease * numberOfMonths;
}

var monthlyKMCost = (supplementary.ofm_transport_estimated_yearly_km ?? 0) * (decimal)supplementary.ofm_supplementary_schedule?.ofm_transport_reimbursement_rate_per_km * numberOfMonths;
calculatedMonthlyAmount = (supplementary.ofm_transport_estimated_yearly_km ?? 0) * (decimal)supplementary.ofm_supplementary_schedule?.ofm_transport_reimbursement_rate_per_km;

calculatedFundingAmount += monthlyKMCost;
calculatedFundingAmount = calculatedMonthlyAmount * numberOfMonths;

break;
}
Expand All @@ -254,12 +256,13 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
#region Step 4: Post-Calculation

//Update the supplemental record

var updateSupplementalUrl = @$"ofm_allowances({supplementary.ofm_allowanceid})";
var updateContent = new
var updateContent = new JsonObject()
{
ofm_funding_amount = calculatedFundingAmount
{ ofm_allowance.Fields.ofm_funding_amount, calculatedFundingAmount },
{ ofm_allowance.Fields.ofm_monthly_amount, calculatedMonthlyAmount }
};

var requestBody = JsonSerializer.Serialize(updateContent);
var response = await _d365webapiservice.SendPatchRequestAsync(_appUserService.AZSystemAppUser, updateSupplementalUrl, requestBody);

Expand Down

0 comments on commit ea78d80

Please sign in to comment.