project QadFinancials > class BCreditorReport > method SetAgeingPeriod


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCreditorReport.CreditorAgeingABackwards
method BCreditorReport.CreditorAgeingAnalysisCurrent


program code (program1/bcreditorreport.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 vtDateForAgeingCalcFilter1 = ?
then assign vtDateForAgeingCalcFilter1 = today.       
/*Create the first period 'manualy' if "Within Terms = Yes"*/       
if vlInvoicesWithinTermsFilter1 
then do:
    create tAgeingPeriod1.
    assign tAgeingPeriod1.tiAgeingPeriodSeq      = 1
           tAgeingPeriod1.ttAgeingPeriodFromDate = vtDateForAgeingCalcFilter1
           tAgeingPeriod1.ttAgeingPeriodToDate   = vtDateMax1
           viSeqMin = 2.    
end. 
/*initial data*/
assign vtToDate = vtDateForAgeingCalcFilter1 - 1
       viOffset = abs(viAgeingOffsetFilter1)
       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 tAgeingPeriod1.
    assign tAgeingPeriod1.tiAgeingPeriodSeq    = viSeq.
           tAgeingPeriod1.ttAgeingPeriodToDate = vtToDate.
    case vcAgeingTypeFilter1:
        /*Calculate 'ToDate' of the next period for Ageing of type 'DAYS'*/
        when {&AGEINGTYPE-DAYS}
        then assign vtToDate = tAgeingPeriod1.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 tAgeingPeriod1.ttAgeingPeriodFromDate = if viSeq = viSeqMax then date(1,1,1) else vtToDate + 1.           
end.