Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bcgov-hl committed Jul 23, 2024
2 parents ffe90f7 + b5930e8 commit 5c925df
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ OFM.Expense.Form = {
var currentDate = new Date();
if (startDate != null) {
if (startDate < currentDate) {
formContext.ui.setFormNotification("Start date cannot a past date.", "ERROR", "startdate");
formContext.ui.setFormNotification("Start date cannot be a past date.", "ERROR", "startdate");
// Clear end date field
formContext.getAttribute("ofm_start_date").setValue(null);
}
Expand All @@ -124,7 +124,7 @@ OFM.Expense.Form = {
}
if (endDate != null) {
if (endDate < currentDate) {
formContext.ui.setFormNotification("End date cannot a past date.", "ERROR", "enddate");
formContext.ui.setFormNotification("End date cannot be a past date.", "ERROR", "enddate");
// Clear end date field
formContext.getAttribute("ofm_end_date").setValue(null);
}
Expand Down
2 changes: 2 additions & 0 deletions OFM.Infrastructure.WebAPI/Models/Fundings/Fundings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public class SupplementaryApplication : ofm_allowance
public Guid? _ofm_summary_submittedby_value { get; set; }
[property: JsonPropertyName("app.ofm_funding_number_base")]
public string? ofm_funding_number_base { get; set; }
[property: JsonPropertyName("funding.statuscode")]
public int? fundingstatuscode { get; set; }
}

public class BusinessClosure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class P210CreateFundingNotificationProvider : ID365ProcessProvider
private string? _informationCommunicationType;
private string _contactId;


public P210CreateFundingNotificationProvider(IOptionsSnapshot<NotificationSettings> notificationSettings, ID365AppUserService appUserService, ID365WebApiService d365WebApiService, ILoggerFactory loggerFactory, TimeProvider timeProvider, IFundingRepository fundingRepository, IEmailRepository emailRepository)
{
_notificationSettings = notificationSettings.Value;
Expand Down Expand Up @@ -70,6 +71,62 @@ public string RequestUri
return requestUri;
}
}
public string AllowanceRequestUri
{
get
{
var fetchXml = $"""
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="ofm_allowance">
<attribute name="ofm_allowanceid" />
<attribute name="ofm_allowance_number" />
<attribute name="createdon" />
<attribute name="statuscode" />
<attribute name="ofm_notification_sent" />
<attribute name="ofm_application" />
<attribute name="ofm_allowance_type" />
<attribute name="ofm_monthly_amount" />
<attribute name="ofm_start_date" />
<attribute name="ofm_transport_vehicle_vin" />
<attribute name="ofm_retroactive_date" />
<attribute name="ofm_retroactive_amount" />

<filter type="and">
<filter type="or">
<condition attribute="ofm_notification_sent" operator="eq" value="0" />
<condition attribute="ofm_notification_sent" operator="null" />
</filter>
<condition attribute="statuscode" operator="in">
<value>2</value>
<value>6</value>
</condition>
</filter>
<link-entity name="ofm_application" from="ofm_applicationid" to="ofm_application" link-type="inner" alias="app">
<attribute name="ofm_contact" />
<attribute name="statuscode" />
<attribute name="ofm_summary_submittedby" />
<attribute name="ofm_funding_number_base" />
<link-entity name="contact" from="contactid" to="ofm_contact" alias= "con">
<attribute name="ofm_last_name" />
<attribute name="ofm_first_name" />
</link-entity>
<link-entity name="ofm_funding" from="ofm_application" to="ofm_applicationid" link-type="inner" alias="ar">
<filter type="and">
<condition attribute="ofm_fundingid" operator="eq" value="{_processParams.Funding.FundingId}" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
""";

var requestUri = $"""
ofm_allowances?fetchXml={WebUtility.UrlEncode(fetchXml)}
""";

return requestUri;
}
}
#endregion

public async Task<ProcessData> GetDataAsync()
Expand Down Expand Up @@ -102,6 +159,36 @@ public async Task<ProcessData> GetDataAsync()

return await Task.FromResult(new ProcessData(d365Result));
}
public async Task<ProcessData> GetDataAsyncAllowance()
{
_logger.LogDebug(CustomLogEvent.Process, "GetAllowanceDataAsync");

var response = await _d365webapiservice.SendRetrieveRequestAsync(_appUserService.AZSystemAppUser, AllowanceRequestUri);

if (!response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
_logger.LogError(CustomLogEvent.Process, "Failed to query Allowance records with the server error {responseBody}", responseBody.CleanLog());

return await Task.FromResult(new ProcessData(string.Empty));
}

var jsonObject = await response.Content.ReadFromJsonAsync<JsonObject>();

JsonNode d365Result = string.Empty;
if (jsonObject?.TryGetPropertyValue("value", out var currentValue) == true)
{
if (currentValue?.AsArray().Count == 0)
{
_logger.LogInformation(CustomLogEvent.Process, "No Allowance records found with query {requestUri}", AllowanceRequestUri.CleanLog());
}
d365Result = currentValue!;
}

_logger.LogDebug(CustomLogEvent.Process, "Query Result {queryResult}", d365Result.ToString().CleanLog());

return await Task.FromResult(new ProcessData(d365Result));
}

public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService, ID365WebApiService d365WebApiService, ProcessParameter processParams)
{
Expand All @@ -115,11 +202,11 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
Funding? _funding = await _fundingRepository?.GetFundingByIdAsync(new Guid(processParams.Funding!.FundingId!));
var expenseOfficer = _funding.ofm_application?._ofm_expense_authority_value;
var primaryContact = _funding.ofm_application?._ofm_contact_value;
// Provider FA Approver
// Provider FA Approver

int statusReason = (int)_funding!.statuscode; // funding status
_logger.LogInformation("Got the Status", statusReason);

var startTime = _timeProvider.GetTimestamp();

#region Create the funding email notifications
Expand All @@ -130,13 +217,13 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
_logger.LogInformation("Entered if FASignaturePending", statusReason);
// Get template details to create emails.
var localDataTemplate = await _emailRepository.GetTemplateDataAsync(_notificationSettings.EmailTemplates.First(t => t.TemplateNumber == 210).TemplateNumber);


var serializedDataTemplate = JsonSerializer.Deserialize<List<D365Template>>(localDataTemplate.Data.ToString());
_logger.LogInformation("Got the Template", serializedDataTemplate.Count);
var hyperlink = _notificationSettings.FundingUrl + _funding.Id;
var hyperlinkFATab = _notificationSettings.FundingTabUrl;
_logger.LogInformation("Got the hyperlink", hyperlink +hyperlinkFATab);
_logger.LogInformation("Got the hyperlink", hyperlink + hyperlinkFATab);
var templateobj = serializedDataTemplate?.FirstOrDefault();
string? subject = templateobj?.title;
string? emaildescription = templateobj?.safehtml;
Expand Down Expand Up @@ -191,10 +278,30 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
recipientsList.Add((Guid)providerApprover);
await _emailRepository.CreateAndUpdateEmail(subject, emaildescription, recipientsList, _processParams.Notification.SenderId, _informationCommunicationType, appUserService, d365WebApiService, 210);
}
var localDataAllowance = await GetDataAsyncAllowance();
var deserializedDataAllowance = JsonSerializer.Deserialize<List<SupplementaryApplication>>(localDataAllowance.Data.ToString());
if (deserializedDataAllowance == null || deserializedDataAllowance.Count == 0)
{
_logger.LogInformation("No records returned from FetchXml", deserializedDataAllowance.Count);
return ProcessResult.Completed(ProcessId).SimpleProcessResult;
}
foreach (var allowance in deserializedDataAllowance)
{
bool emailCreated = await _emailRepository.CreateAllowanceEmail(allowance, _processParams.Notification.SenderId, _informationCommunicationType, ProcessId, d365WebApiService);
}
#endregion Create the Supp email notifications






}
return ProcessResult.Failure(ProcessId, new String[] { "Upsert action failed" }, 0, 0).SimpleProcessResult;

return ProcessResult.Completed(ProcessId).SimpleProcessResult;

#endregion
}
}
}



Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Options;
using ECC.Core.DataContext;
using Microsoft.Extensions.Options;
using OFM.Infrastructure.WebAPI.Extensions;
using OFM.Infrastructure.WebAPI.Models;
using OFM.Infrastructure.WebAPI.Models.Fundings;
Expand Down Expand Up @@ -74,6 +75,12 @@ public string RequestUri
<attribute name="ofm_last_name" />
<attribute name="ofm_first_name" />
</link-entity>
<link-entity name="ofm_funding" from="ofm_application" to="ofm_applicationid" link-type="inner" alias="funding" >
<attribute name="statuscode" />
<filter>
<condition attribute="ofm_version_number" operator="eq" value="0" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
Expand Down Expand Up @@ -136,6 +143,7 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
}
try
{
if(deserializedData.First().fundingstatuscode == (int)ofm_funding_StatusCode.Active)
await _emailRepository.CreateAllowanceEmail(deserializedData.First(), _processParams.Notification.SenderId, _informationCommunicationType, ProcessId, d365WebApiService);
}
catch (Exception ex)
Expand Down

0 comments on commit 5c925df

Please sign in to comment.