Codeunit 358 - DateFilterCalc

This codeunit is a good example of how well designed and well written code has long term utility. Except for code changes required by NAV structural changes, this codeunit has changed very little since it originated in NAV (Navision) V3.00 in 2001. That doesn't mean it is out of date; it means it was well thought out and complete from its beginning.

Codeunit 358 contains two functions we can use in our code to create filters based on the Accounting Period Calendar. The first is CreateFiscalYearFilter. If we are calling this from an object that has Codeunit 358 defined as a Global variable named DateFilterCalc, our call would use the following syntax:

DateFilterCalc,CreateFiscalYearFilter
(Filter,Name,BaseDate,NextStep)

The calling parameters are Filter (text, length 30), Name (text, length 30), BaseDate (date), and NextStep (integer).
The second such function is CreateAccountingPeriodFilter that has the following syntax:

DateFilterCalc.CreateAccountingPeriodFilter
(Filter,Name,BaseDate,NextStep)

The calling parameters are Filter (text, length 30), Name (text, length 30), BaseDate (date), and NextStep (integer).

In the following code screenshot from Page 151 - Customer Statistics, we can see how NAV calls these functions. Page 152 - Vendor Statistics, Page 223 - Resource Statistics, and a number of other Master table statistics pages also use this set of functions:

As shown in the next code screenshot, NAV uses the filters stored in the CustDateFilter array to constrain the calculation of a series of FlowFields for the Customers Statistics page:

When one of these functions is called, the Filter and Name parameters are updated within the function so we can use them as return parameters, allowing the function to return a workable filter and a name for that filter. The filter is calculated from the BaseDate and NextStep we supply.

The returned filter is supplied back in the format of a range filter string, 'startdate..enddate' (for example, 01/01/16..12/31/16). If we call CreateFiscalYearFilter, the Filter parameter will be for the range of a fiscal year, as defined by the system's AccountingPeriod table. If we call CreateAccountingPeriodFilter, the Filter parameter will be for the range of a fiscal period, as defined by the same table.

The dates of the Period or Year filter returned are tied to the BaseDate parameter, which can be any legal date. The NextStep parameter says which period or year to use, depending on which function is called. A NextStep=0 says, use the period or year containing the BaseDate, NextStep=1 says use the next period or year into the future, and NextStep=-2 says use the period or year before last (go back two periods or years).

The Name value returned is also derived from the Accounting Period table. If the call is to the CreateAccountingPeriodFilter, then Name will contain the appropriate Accounting Period Name. If the call is to the CreateFiscalYearFilter, then Name will contain 'Fiscal Year yyyy', where yyyy will be the four-digit numeric year.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.79.59