project QadFinancials > class BDebtorReport > method SetAgeingPeriod

Description

Populates AgeingPeriod table


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDebtorReport.DebtorAgeingAnalysisBackwards
method BDebtorReport.DebtorAgeingAnalysisCurrent
method BDebtorReport.DebtorAgingHistAcroDomain
method BDebtorReport.DebtorBillingAAB


program code (program1/bdebtorreport.p)

/*create 6 Ageing periods
period 0 = (AgeingDate, 01/01/9999) only used for "Within Terms = Yes"
period 1 = ((calc), AgeingDate>, 
period 2, 3 (calc, calc)
period 4 (calc, calc) if "Within Terms = No"
period 4 (calc, calc) if "Within Terms = No"
period 5 (01/01/0001, calc)*/

assign viSeqMax = 5
       viSeqMin = 1.
if vtDateForAgeingCalcFilter = ?
then assign vtDateForAgeingCalcFilter = today.       
/*Create the first period 'manualy' if "Within Terms = Yes"*/       
if vlInvoicesWithinTermsFilter 
then do:
    create tAgeingPeriod.
    assign tAgeingPeriod.tiAgeingPeriodSeq      = 1
           tAgeingPeriod.ttAgeingPeriodFromDate = vtDateForAgeingCalcFilter
           tAgeingPeriod.ttAgeingPeriodToDate   = vtDateMax
           viSeqMin = 2.    
end. 
/*initial data*/
assign vtToDate = vtDateForAgeingCalcFilter - 1
       viOffset = abs(viAgeingOffsetFilter)
       viDay    = day (vtToDate)
       viMonth  = month (vtToDate)
       viYear   = year (vtToDate).
/*check if vttodate is last of month*/
assign vtTempDate = date (viMonth, viDay + 1, viYear) no-error.
if error-status:error 
then assign vlIsLastOfMonth = true.
Else assign vlIsLastOfMonth = False.
/*calculate 'ToDate' of the next period; 'FromDate' of the current period is 'ToDate' + 1*/       
do viSeq = viSeqMin to viSeqMax:
    create tAgeingPeriod.
    assign tAgeingPeriod.tiAgeingPeriodSeq    = viSeq.
           tAgeingPeriod.ttAgeingPeriodToDate = vtToDate.
    case vcAgeingTypeFilter:
        /*Calculate 'ToDate' of the next period for Ageing of type 'DAYS'*/
        when {&AGEINGTYPE-DAYS}
        then assign vtToDate = tAgeingPeriod.ttAgeingPeriodToDate - viOffset.
        /*Calculate 'ToDate' of the next period for Ageing of type 'MONTHS'*/
        when {&AGEINGTYPE-MONTHS} 
        then do:        
            /*if last of month*/
            If vlIsLastOfMonth
            Then Assign viDay = 31.
            /*calculate month and year*/      
            assign viIndex = 0.
            do while viIndex < viOffset:
                assign viIndex = viIndex + 1 
                       viMonth = viMonth - 1.
                if viMonth = 0  
                then assign viMonth = 12
                            viYear  = viYear - 1.
                
            end.
            assign vtToDate = date (viMonth, viDay, viYear) no-error.
            if error-status:error then assign vtToDate = ?.
            /*adjust day; 
            in some cases ToDate might be invalid e.g. 30/02 or 31/04 etc.
            therefor I decrease the valus of viDay and it results in the following situation:
            if the day of 'ToDate' of the first period is 31 then 
            the 'ToDate' of second period will be 30 for April, June, September, November and
            28 (or 29) for February; 
            viIndex < 5 just to be sure that it will not be an endless loop*/
            assign viIndex = 0.
            do while (vtToDate = ? and viIndex < 5):
                assign viIndex  = viIndex + 1
                       viDay    = viDay - 1
                       vtToDate = date (viMonth, viDay, viYear) no-error.
                if error-status:error then assign vtToDate = ?.
            end.                        
        end.    
    end case.
    assign tAgeingPeriod.ttAgeingPeriodFromDate = if viSeq = viSeqMax then vtDateMin else vtToDate + 1.                                                                                              
end.