ACF Library

CalcDueDateInvoice

Back to List

Description: Calculate due date of an invoice, ensuring it is not on weekends or holidays.

FileMaker Prototype:

Set Variable [$res; ACF_Run("CalcDueDateInvoice"; date_invoicedate;  int_days)]

Category: FINANCE

Dependencies

  • NonBusinessHolidays: Calculate number of holidays that fell on regular working days between two dates.

Function source:

function CalcDueDateInvoice ( date invoicedate, int days )
   date duedate = invoicedate + days; 
   int nbh, Year;
   int dow;
   repeat
      dow = string(duedate, "%w"); 
      dow = ((dow==0)?7:dow); 
      if ( dow > 5 ) then
         duedate = duedate + (7-dow+1); // Move to next Monday
         dow = 1; 
      end if

      Year = string ( duedate, "%Y"); 
      nbh = NonBusinessHolidays (Year, duedate, duedate, false);
      if ( nbh > 0 ) then
         duedate = duedate + 1; 
         dow += 1; 
         dow = ((dow>7)?1:dow); 
      end if
   until (nbh == 0 && dow < 6); 
   return string(duedate); 
end

The CalcDueDateInvoice function calculates an invoice’s due date by adding a specified number of days to the invoice date. If the calculated due date lands on a non-banking day, the function adjusts it to the next available banking day. This ensures that invoices originally scheduled on non-banking dates are accurately rescheduled without changing valid due dates unnecessarily.

Dependencies

The following dependencies must be defined before this function (found in the library):

  • NonBusinessHolidays

Example

Set Variable [$res; ACF_Run("CalcDueDateInvoice"; "14/03/2024"; 14)]

For this example, adding 14 days to the invoice date results in an initial due date of "28/03/2024." However, this date falls on Maundy Thursday, followed by Good Friday, Saturday, Easter Sunday, Easter Monday, and Labor Day on 01/05/2024. The next available banking day is "02/05/2024," which becomes the adjusted due date returned by this function.

Back to List