Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKevJoy committed Jan 20, 2025
1 parent 0bc4a03 commit fc558b7
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ComponentModel.Design;
using System.Globalization;
using System.Text;
using CsvHelper;
Expand Down Expand Up @@ -135,26 +134,26 @@ public async Task<InductionImportResult> ImportAsync(StreamReader csvReaderStrea
};
rowTransaction.AppendQuery(queryInductionPeriod);
}
//else
//{
// inductionPeriodId = lookupData.InductionPeriod.dfeta_inductionperiodId;
// var updateInduction = new UpdateInductionTransactionalQuery()
// {
// InductionId = inductionId!.Value,
// CompletionDate = DateTime.ParseExact(row.PassedDate, DATE_FORMAT, CultureInfo.InvariantCulture, DateTimeStyles.None),
// InductionStatus = lookupData.Induction!.dfeta_InductionStatus!.Value
// };
// rowTransaction.AppendQuery(updateInduction);

// var updateInductionPeriodQuery = new UpdateInductionPeriodTransactionalQuery()
// {
// InductionPeriodId = inductionPeriodId!.Value,
// AppropriateBodyId = lookupData.OrganisationId,
// InductionStartDate = lookupData.InductionPeriod.dfeta_StartDate,
// InductionEndDate = DateTime.ParseExact(row.PassedDate, DATE_FORMAT, CultureInfo.InvariantCulture, DateTimeStyles.None),
// };
// rowTransaction.AppendQuery(updateInductionPeriodQuery);
//}
else
{
inductionPeriodId = lookupData.InductionPeriod.dfeta_inductionperiodId;
var updateInduction = new UpdateInductionTransactionalQuery()
{
InductionId = inductionId!.Value,
CompletionDate = DateTime.ParseExact(row.PassedDate, DATE_FORMAT, CultureInfo.InvariantCulture, DateTimeStyles.None),
InductionStatus = lookupData.Induction!.dfeta_InductionStatus!.Value
};
rowTransaction.AppendQuery(updateInduction);

var updateInductionPeriodQuery = new UpdateInductionPeriodTransactionalQuery()
{
InductionPeriodId = inductionPeriodId!.Value,
AppropriateBodyId = lookupData.OrganisationId,
InductionStartDate = lookupData.InductionPeriod.dfeta_StartDate,
InductionEndDate = DateTime.ParseExact(row.PassedDate, DATE_FORMAT, CultureInfo.InvariantCulture, DateTimeStyles.None),
};
rowTransaction.AppendQuery(updateInductionPeriodQuery);
}

//soft validation errors can be appended to the IntegrationTransactionRecord Failure message
foreach (var validationMessage in validationFailures.ValidationFailures)
Expand Down Expand Up @@ -262,17 +261,22 @@ public async Task<InductionImportLookupData> GetLookupDataAsync(EwcWalesInductio

if (ind?.InductionPeriods?.Length > 0)
{
var periods = ind?.InductionPeriods.Where(x => !x.dfeta_EndDate.HasValue).ToList();
var periods = ind?.InductionPeriods.ToList();
if (periods?.Count() == 1)
{
{
inductionPeriodMatchStatus = InductionPeriodLookupResult.OneMatch;
inductionPeriod = periods.First();
}
else if(periods?.Count() > 1)
else if (periods?.Count() > 1)
{
inductionPeriodMatchStatus = InductionPeriodLookupResult.MultipleMatchesFound;
inductionPeriod = null;
}
else
{
inductionPeriodMatchStatus = InductionPeriodLookupResult.NoMatch;
inductionPeriod = null;
}
}

hasActiveAlerts = _dbContext.Alerts.Where(x => x.PersonId == contact.Id && x.IsOpen).Count() > 0;
Expand Down Expand Up @@ -401,11 +405,26 @@ public async Task<InductionImportLookupData> GetLookupDataAsync(EwcWalesInductio
}
}

// Error If:
// Matched InductionPeriod already has an end date
// Matched InductionPeriod is associated with a different AB
if (lookups.InductionPeriod != null)
{
if (lookups.InductionPeriod.dfeta_EndDate.HasValue)
{
errors.Add($"Unable to update induction period that has an end date.");
}
else if (lookups.InductionPeriod.dfeta_AppropriateBodyId?.Id != lookups.OrganisationId)
{
errors.Add($"Teacher is claimed by another Appropriate Body.");
}
}

return (validationFailures, errors);
}
public async Task<(OrganisationLookupResult, Guid? OrganisationId)> FindMatchingOrganisationsRecordAsync(string OrgNumber)
{
var query = new FindActiveOrganisationsByLaSchoolCodeQuery(OrgNumber);
var query = new FindActiveOrganisationsByAccountNumberQuery(OrgNumber);
var results = await _crmQueryDispatcher.ExecuteQueryAsync(query);

if (results.Length == 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ComponentModel.Design;
using System.Globalization;
using System.Text;
using CsvHelper;
Expand Down Expand Up @@ -135,26 +134,26 @@ public async Task<InductionImportResult> ImportAsync(StreamReader csvReaderStrea
};
rowTransaction.AppendQuery(queryInductionPeriod);
}
//else
//{
// inductionPeriodId = lookupData.InductionPeriod.dfeta_inductionperiodId;
// var updateInduction = new UpdateInductionTransactionalQuery()
// {
// InductionId = inductionId!.Value,
// CompletionDate = DateTime.ParseExact(row.PassedDate, DATE_FORMAT, CultureInfo.InvariantCulture, DateTimeStyles.None),
// InductionStatus = lookupData.Induction!.dfeta_InductionStatus!.Value
// };
// rowTransaction.AppendQuery(updateInduction);

// var updateInductionPeriodQuery = new UpdateInductionPeriodTransactionalQuery()
// {
// InductionPeriodId = inductionPeriodId!.Value,
// AppropriateBodyId = lookupData.OrganisationId,
// InductionStartDate = lookupData.InductionPeriod.dfeta_StartDate,
// InductionEndDate = DateTime.ParseExact(row.PassedDate, DATE_FORMAT, CultureInfo.InvariantCulture, DateTimeStyles.None),
// };
// rowTransaction.AppendQuery(updateInductionPeriodQuery);
//}
else
{
inductionPeriodId = lookupData.InductionPeriod.dfeta_inductionperiodId;
var updateInduction = new UpdateInductionTransactionalQuery()
{
InductionId = inductionId!.Value,
CompletionDate = DateTime.ParseExact(row.PassedDate, DATE_FORMAT, CultureInfo.InvariantCulture, DateTimeStyles.None),
InductionStatus = lookupData.Induction!.dfeta_InductionStatus!.Value
};
rowTransaction.AppendQuery(updateInduction);

var updateInductionPeriodQuery = new UpdateInductionPeriodTransactionalQuery()
{
InductionPeriodId = inductionPeriodId!.Value,
AppropriateBodyId = lookupData.OrganisationId,
InductionStartDate = lookupData.InductionPeriod.dfeta_StartDate,
InductionEndDate = DateTime.ParseExact(row.PassedDate, DATE_FORMAT, CultureInfo.InvariantCulture, DateTimeStyles.None),
};
rowTransaction.AppendQuery(updateInductionPeriodQuery);
}

//soft validation errors can be appended to the IntegrationTransactionRecord Failure message
foreach (var validationMessage in validationFailures.ValidationFailures)
Expand Down Expand Up @@ -262,17 +261,22 @@ public async Task<InductionImportLookupData> GetLookupDataAsync(EwcWalesInductio

if (ind?.InductionPeriods?.Length > 0)
{
var periods = ind?.InductionPeriods.Where(x => !x.dfeta_EndDate.HasValue).ToList();
var periods = ind?.InductionPeriods.ToList();
if (periods?.Count() == 1)
{
{
inductionPeriodMatchStatus = InductionPeriodLookupResult.OneMatch;
inductionPeriod = periods.First();
}
else if(periods?.Count() > 1)
else if (periods?.Count() > 1)
{
inductionPeriodMatchStatus = InductionPeriodLookupResult.MultipleMatchesFound;
inductionPeriod = null;
}
else
{
inductionPeriodMatchStatus = InductionPeriodLookupResult.NoMatch;
inductionPeriod = null;
}
}

hasActiveAlerts = _dbContext.Alerts.Where(x => x.PersonId == contact.Id && x.IsOpen).Count() > 0;
Expand Down Expand Up @@ -401,11 +405,26 @@ public async Task<InductionImportLookupData> GetLookupDataAsync(EwcWalesInductio
}
}

// Error If:
// Matched InductionPeriod already has an end date
// Matched InductionPeriod is associated with a different AB
if (lookups.InductionPeriod != null)
{
if (lookups.InductionPeriod.dfeta_EndDate.HasValue)
{
errors.Add($"Unable to update induction period that has an end date.");
}
else if (lookups.InductionPeriod.dfeta_AppropriateBodyId?.Id != lookups.OrganisationId)
{
errors.Add($"Teacher is claimed by another Appropriate Body.");
}
}

return (validationFailures, errors);
}
public async Task<(OrganisationLookupResult, Guid? OrganisationId)> FindMatchingOrganisationsRecordAsync(string OrgNumber)
{
var query = new FindActiveOrganisationsByLaSchoolCodeQuery(OrgNumber);
var query = new FindActiveOrganisationsByAccountNumberQuery(OrgNumber);
var results = await _crmQueryDispatcher.ExecuteQueryAsync(query);

if (results.Length == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,18 +565,16 @@ public async Task EwcWalesImportJobInduction_ImportsInductionFileSuccessfully()
var expectedDuplicateRowCount = 0;
var expectedFailureRowCount = 0;
var accountNumber = "9999";
var lascoolcode = "54321";
var startDate = DateTime.ParseExact("17/09/2014", "dd/MM/yyyy", CultureInfo.InvariantCulture);
var passDate = DateTime.ParseExact("28/09/2017", "dd/MM/yyyy", CultureInfo.InvariantCulture);
var account = await TestData.CreateAccountAsync(x =>
{
x.WithName("SomeName");
x.WithAccountNumber(accountNumber);
x.WithLaSchoolCode(lascoolcode);
});
var person = await TestData.CreatePersonAsync(x => x.WithTrn());
var trn = person.Trn;
var csvContent = $"REFERENCE_NO,FIRST_NAME,LAST_NAME,DATE_OF_BIRTH,START_DATE,PASS_DATE,FAIL_DATE,EMPLOYER_NAME,EMPLOYER_CODE,IND_STATUS_NAME\r\n{trn},{person.FirstName},{person.LastName},{person.DateOfBirth.ToString("dd/MM/yyyy")},{startDate.ToString("dd/MM/yyyy")},{passDate.ToString("dd/MM/yyyy")},,{account.Name},{lascoolcode},Pass\r\n";
var csvContent = $"REFERENCE_NO,FIRST_NAME,LAST_NAME,DATE_OF_BIRTH,START_DATE,PASS_DATE,FAIL_DATE,EMPLOYER_NAME,EMPLOYER_CODE,IND_STATUS_NAME\r\n{trn},{person.FirstName},{person.LastName},{person.DateOfBirth.ToString("dd/MM/yyyy")},{startDate.ToString("dd/MM/yyyy")},{passDate.ToString("dd/MM/yyyy")},,{account.Name},{accountNumber},Pass\r\n";
var csvBytes = Encoding.UTF8.GetBytes(csvContent);
var stream = new MemoryStream(csvBytes);
var reader = new StreamReader(stream);
Expand Down Expand Up @@ -789,12 +787,10 @@ public async Task EwcWalesImportJobInduction_UpdatesExistingInduction()
{
// Arrange
var accountNumber = "678910";
var laschoolcode = "555";
var account = await TestData.CreateAccountAsync(x =>
{
x.WithName("SomeName");
x.WithAccountNumber(accountNumber);
x.WithLaSchoolCode(laschoolcode);
});
var expectedTotalRowCount = 1;
var expectedSuccessCount = 1;
Expand All @@ -805,17 +801,18 @@ public async Task EwcWalesImportJobInduction_UpdatesExistingInduction()
var person = await TestData.CreatePersonAsync(x =>
{
x.WithTrn();
x.WithDqtInduction(dfeta_InductionStatus.RequiredtoComplete,
null, startDate.ToDateOnlyWithDqtBstFix(isLocalTime: false),
completedDate: passDate.ToDateOnlyWithDqtBstFix(isLocalTime: false),
x.WithDqtInduction(inductionStatus: dfeta_InductionStatus.RequiredtoComplete,
inductionExemptionReason: null,
startDate.ToDateOnlyWithDqtBstFix(isLocalTime: false),
completedDate: null,
inductionPeriodStartDate: startDate.ToDateOnlyWithDqtBstFix(isLocalTime: false),
inductionPeriodEndDate: passDate.ToDateOnlyWithDqtBstFix(isLocalTime: false),
inductionPeriodEndDate: null,
appropriateBodyOrgId: account.Id);
});
var trn = person.Trn;
var updatedStartDate = DateTime.ParseExact("17/09/2019", "dd/MM/yyyy", CultureInfo.InvariantCulture);
var updatedPassDate = DateTime.ParseExact("28/09/2020", "dd/MM/yyyy", CultureInfo.InvariantCulture);
var csvContent = $"REFERENCE_NO,FIRST_NAME,LAST_NAME,DATE_OF_BIRTH,START_DATE,PASS_DATE,FAIL_DATE,EMPLOYER_NAME,EMPLOYER_CODE,IND_STATUS_NAME\r\n{trn},{person.FirstName},{person.LastName},{person.DateOfBirth.ToString("dd/MM/yyyy")},{updatedStartDate.ToString("dd/MM/yyyy")},{updatedPassDate.ToString("dd/MM/yyyy")},,,{account.dfeta_LASchoolCode},Pass\r\n";
var csvContent = $"REFERENCE_NO,FIRST_NAME,LAST_NAME,DATE_OF_BIRTH,START_DATE,PASS_DATE,FAIL_DATE,EMPLOYER_NAME,EMPLOYER_CODE,IND_STATUS_NAME\r\n{trn},{person.FirstName},{person.LastName},{person.DateOfBirth.ToString("dd/MM/yyyy")},{updatedStartDate.ToString("dd/MM/yyyy")},{updatedPassDate.ToString("dd/MM/yyyy")},,,{accountNumber},Pass\r\n";
var csvBytes = Encoding.UTF8.GetBytes(csvContent);
var stream = new MemoryStream(csvBytes);
var reader = new StreamReader(stream);
Expand Down
Loading

0 comments on commit fc558b7

Please sign in to comment.