Skip to content

Commit

Permalink
Merge pull request #274 from bcgov/PaymentLast45daysCheck
Browse files Browse the repository at this point in the history
Payment changes replacing last month check with 45 days check
  • Loading branch information
Prashanthi-Sivanarayana authored Nov 8, 2024
2 parents 920310f + 099ce9a commit 3ba8a68
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
14 changes: 14 additions & 0 deletions OFM.Infrastructure.WebAPI/Extensions/TimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@ public static DateTime GetLastBusinessDayOfPaymentMonth(this DateTime PaymentDat

return lastDayOfPaymentMonth;
}

public static DateTime GetFirstDayOfFollowingMonth(this DateTime PaymentDate, List<DateTime> holidays)
{
DateTime firstDayOfNextMonth = new DateTime(PaymentDate.Year, PaymentDate.Month, 1).AddMonths(1);
// Iterate backward to find the last business day of that payment month.
while (firstDayOfNextMonth.DayOfWeek == DayOfWeek.Saturday ||
firstDayOfNextMonth.DayOfWeek == DayOfWeek.Sunday ||
holidays.Exists(excludedDate => excludedDate.Date.Equals(firstDayOfNextMonth.Date)))
{
firstDayOfNextMonth = firstDayOfNextMonth.AddDays(1);
}
return firstDayOfNextMonth;
}

public static DateTime GetFirstDayOfFollowingNextMonth(this DateTime PaymentDate, List<DateTime> holidays)
{
DateTime firstDayOfNextMonth = new DateTime(PaymentDate.Year, PaymentDate.Month, 1).AddMonths(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ private async Task<JsonObject> ProcessTransportationPayments(Application baseApp
{
if (approvedSA.ofm_allowance_type == ecc_allowance_type.Transportation)
{
if ((approvedSA.ofm_start_date.Value.Month == firstAnniversaryDate.Month && approvedSA.ofm_start_date.Value.Year == firstAnniversaryDate.Year) || (approvedSA.ofm_start_date.Value.Month == secondAnniversaryDate.Month && approvedSA.ofm_start_date.Value.Year == secondAnniversaryDate.Year) || (approvedSA.ofm_start_date.Value.Month == fundingEndDate?.Month && approvedSA.ofm_start_date.Value.Year == fundingEndDate?.Year))
if (CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value,firstAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, secondAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, fundingEndDate.Value))

{
int retroActiveMonthsCount = approvedSA.ofm_retroactive_date!.HasValue ? (approvedSA.ofm_start_date.Value.Year - approvedSA.ofm_retroactive_date!.Value.Year) * 12 + approvedSA.ofm_start_date.Value.Month - approvedSA.ofm_retroactive_date.Value.Month : 0;
decimal retroActiveAmount = retroActiveMonthsCount > 0 ? approvedSA.ofm_monthly_amount!.Value * retroActiveMonthsCount : 0;
Expand Down Expand Up @@ -484,13 +485,26 @@ private async Task<JsonObject> CreateSinglePayment(SupplementaryApplication appr
DateTime secondAnniversaryDate,
DateTime? fundingEndDate)
{
DateTime invoiceDate = ((approvedSA.ofm_start_date.Value.Month == firstAnniversaryDate.Month && approvedSA.ofm_start_date.Value.Year == firstAnniversaryDate.Year) || (approvedSA.ofm_start_date.Value.Month == secondAnniversaryDate.Month && approvedSA.ofm_start_date.Value.Year == secondAnniversaryDate.Year) || (approvedSA.ofm_start_date.Value.Month == fundingEndDate?.Month && approvedSA.ofm_start_date.Value.Year == fundingEndDate?.Year)) ? paymentDate.GetFirstDayOfFollowingNextMonth(holidaysList) : (paymentDate == approvedSA.ofm_start_date!.Value) ? paymentDate.GetLastBusinessDayOfThePreviousMonth(holidaysList) : paymentDate.GetCFSInvoiceDate(holidaysList, _BCCASApi.PayableInDays);
DateTime invoiceDate = (paymentDate == approvedSA.ofm_start_date!.Value) ? paymentDate.GetLastBusinessDayOfThePreviousMonth(holidaysList) : paymentDate.GetCFSInvoiceDate(holidaysList, _BCCASApi.PayableInDays);
DateTime invoiceReceivedDate = invoiceDate.AddBusinessDays(_BCCASApi.PayableInDays, holidaysList);
DateTime effectiveDate = invoiceDate;
//this applies if supplementary application is submitted within last 45 days to last 30 days.

if ((CheckSubmissionIsWithinLastMonth(approvedSA.ofm_submittedon.Value, firstAnniversaryDate) || CheckSubmissionIsWithinLastMonth(approvedSA.ofm_submittedon.Value, secondAnniversaryDate) || CheckSubmissionIsWithinLastMonth(approvedSA.ofm_submittedon.Value, fundingEndDate.Value)))
{
invoiceReceivedDate = paymentDate.GetFirstDayOfFollowingNextMonth(holidaysList);
invoiceDate = invoiceReceivedDate.GetCFSInvoiceDate(holidaysList, _BCCASApi.PayableInDays);
effectiveDate = invoiceDate;
}
else if ((CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, firstAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, secondAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, fundingEndDate.Value)))
{
invoiceReceivedDate = paymentDate.GetFirstDayOfFollowingMonth(holidaysList);
invoiceDate = invoiceReceivedDate.GetCFSInvoiceDate(holidaysList, _BCCASApi.PayableInDays);
effectiveDate = invoiceDate;
}


if (approvedSA.ofm_retroactive_date is not null && !(approvedSA.ofm_start_date.Value.Month == firstAnniversaryDate.Month && approvedSA.ofm_start_date.Value.Year == firstAnniversaryDate.Year) || (approvedSA.ofm_start_date.Value.Month == secondAnniversaryDate.Month && approvedSA.ofm_start_date.Value.Year == secondAnniversaryDate.Year) || (approvedSA.ofm_start_date.Value.Month == fundingEndDate?.Month && approvedSA.ofm_start_date.Value.Year == fundingEndDate?.Year))
if (approvedSA.ofm_retroactive_date is not null && !(CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, firstAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, secondAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, fundingEndDate.Value)))
{
// Date calculation logic is different for mid-year supp application. Overriding regular date logic above
// Invoice received date is always the last business date of previous month except for first payment of the First funding year, it is 5 business day after the last business day of the last month.
Expand All @@ -499,7 +513,7 @@ private async Task<JsonObject> CreateSinglePayment(SupplementaryApplication appr
effectiveDate = invoiceDate;
}

Guid fiscalYear = invoiceDate.AddMonths(-1).MatchFiscalYear(fiscalYears);
Guid fiscalYear = paymentDate.MatchFiscalYear(fiscalYears);

var payload = new JsonObject()
{
Expand Down Expand Up @@ -551,13 +565,25 @@ private async Task<JsonObject> CreatePaymentsInBatch(Application baseApplication
for (DateTime paymentDate = startDate; paymentDate <= endDate; paymentDate = paymentDate.AddMonths(1))
{

DateTime invoiceDate = ((approvedSA.ofm_start_date.Value.Month == firstAnniversaryDate.Month && approvedSA.ofm_start_date.Value.Year == firstAnniversaryDate.Year) || (approvedSA.ofm_start_date.Value.Month == secondAnniversaryDate.Month && approvedSA.ofm_start_date.Value.Year == secondAnniversaryDate.Year) || (approvedSA.ofm_start_date.Value.Month == fundingEndDate?.Month && approvedSA.ofm_start_date.Value.Year == fundingEndDate?.Year)) ? paymentDate.GetFirstDayOfFollowingNextMonth(holidaysList) : (paymentDate == startDate) ? startDate.GetLastBusinessDayOfThePreviousMonth(holidaysList) : paymentDate.GetCFSInvoiceDate(holidaysList, _BCCASApi.PayableInDays);
DateTime invoiceDate = (paymentDate == startDate) ? startDate.GetLastBusinessDayOfThePreviousMonth(holidaysList) : paymentDate.GetCFSInvoiceDate(holidaysList, _BCCASApi.PayableInDays);
DateTime invoiceReceivedDate = invoiceDate.AddBusinessDays(_BCCASApi.PayableInDays, holidaysList);
DateTime effectiveDate = invoiceDate;

//this applies if supplementary application is submitted within 45 days.
if ((CheckSubmissionIsWithinLastMonth(approvedSA.ofm_submittedon.Value, firstAnniversaryDate) || CheckSubmissionIsWithinLastMonth(approvedSA.ofm_submittedon.Value, secondAnniversaryDate) || CheckSubmissionIsWithinLastMonth(approvedSA.ofm_submittedon.Value, fundingEndDate.Value)))
{
invoiceReceivedDate = paymentDate.GetFirstDayOfFollowingNextMonth(holidaysList);
invoiceDate = invoiceReceivedDate.GetCFSInvoiceDate(holidaysList, _BCCASApi.PayableInDays);
effectiveDate = invoiceDate;
}else if ((CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, firstAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, secondAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, fundingEndDate.Value)))
{
invoiceReceivedDate = paymentDate.GetFirstDayOfFollowingMonth(holidaysList);
invoiceDate = invoiceReceivedDate.GetCFSInvoiceDate(holidaysList, _BCCASApi.PayableInDays);
effectiveDate = invoiceDate;
}


if (approvedSA.ofm_retroactive_date is not null && !(approvedSA.ofm_start_date.Value.Month == firstAnniversaryDate.Month && approvedSA.ofm_start_date.Value.Year == firstAnniversaryDate.Year) || (approvedSA.ofm_start_date.Value.Month == secondAnniversaryDate.Month && approvedSA.ofm_start_date.Value.Year == secondAnniversaryDate.Year) || (approvedSA.ofm_start_date.Value.Month == fundingEndDate?.Month && approvedSA.ofm_start_date.Value.Year == fundingEndDate?.Year))
if (approvedSA.ofm_retroactive_date is not null && !(CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, firstAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, secondAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, fundingEndDate.Value)))
{
// Date calculation logic is different for mid-year supp application. Overriding regular date logic above
// Invoice received date is always the last business date of previous month except for first payment of the First funding year, it is 5 business day after the last business day of the last month.
Expand All @@ -566,7 +592,7 @@ private async Task<JsonObject> CreatePaymentsInBatch(Application baseApplication
effectiveDate = invoiceDate;
}

Guid? fiscalYear = invoiceDate.AddMonths(-1).MatchFiscalYear(fiscalYears);
Guid? fiscalYear = startDate.MatchFiscalYear(fiscalYears);
var paymentToCreate = new JsonObject()
{
{ "ofm_invoice_line_number", nextLineNumber++ },
Expand Down Expand Up @@ -614,5 +640,20 @@ private async Task<int> GetNextInvoiceLineNumber()

return await Task.FromResult(nextLineNumber);
}

private static bool CheckSubmissionIsWithinLast45days(DateTime submittedDate, DateTime anniversayDate)
{
DateTime temp = anniversayDate.AddMonths(-1);
DateTime cutoffDate = new DateTime(temp.Year, temp.Month, 15, 0, 0, 0).ToUTC();

return submittedDate >= cutoffDate;
}

private static bool CheckSubmissionIsWithinLastMonth(DateTime submittedDate, DateTime anniversayDate)
{
DateTime temp = submittedDate.ToUniversalTime();

return temp.Year == anniversayDate.Year && temp.Month == anniversayDate.Month;
}
}
}

0 comments on commit 3ba8a68

Please sign in to comment.