Skip to content

Commit

Permalink
Adding new logic to pay following month from last 45 day to last 30 day
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyiwang-cgi committed Nov 8, 2024
1 parent d5571f2 commit 099ce9a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 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 @@ -488,15 +488,23 @@ private async Task<JsonObject> CreateSinglePayment(SupplementaryApplication appr
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 45 days.
if ((CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, firstAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, secondAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, fundingEndDate.Value)))
//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;
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 && !(CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, firstAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, secondAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, fundingEndDate.Value)))

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 Down Expand Up @@ -560,14 +568,21 @@ private async Task<JsonObject> CreatePaymentsInBatch(Application baseApplication
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 ((CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, firstAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, secondAnniversaryDate) || CheckSubmissionIsWithinLast45days(approvedSA.ofm_submittedon.Value, fundingEndDate.Value)))
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 && !(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
Expand Down Expand Up @@ -628,9 +643,17 @@ private async Task<int> GetNextInvoiceLineNumber()

private static bool CheckSubmissionIsWithinLast45days(DateTime submittedDate, DateTime anniversayDate)
{
DateTime cutoffDate = anniversayDate.AddDays(-45);
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 099ce9a

Please sign in to comment.