project QadFinancials > class BDebtorReport > method GetAppropriatePeriodByEndOfDate


Parameters


iiCompanyIdinputinteger
itCurrentPeriodDateinputdate
iiCurrentPeriodinputinteger
oiTargetPeriodoutputinteger
otTargetPeriodDateoutputdate
oiReturnStatusoutputinteger


Internal usage


QadFinancials
method BDebtorReport.DebtorAgingHistAcroDomain


program code (program1/bdebtorreport.p)

assign oiTargetPeriod     = iicurrentPeriod
       otTargetPeriodDate = itCurrentPeriodDate.

if iiCompanyId <> 0 and
   iiCompanyId <> ? then
do:
    <Q-20 run PeriodByStartEndDateStatus (all) (Read) (NoCache)
       (input iiCompanyId, (CompanyId)
        input itCurrentPeriodDate, (Date)
        input ?, (PeriodStatus)
        input ?, (PeriodId)
        input ?, (PeriodIsPostingGLAllowed)
        output dataset tqPeriodByStartEndDateStatus) in BPeriod>
    find first tqPeriodByStartEndDateStatus
        where tqPeriodByStartEndDateStatus.tiCompany_ID = iiCompanyId no-error.

    if available tqPeriodByStartEndDateStatus then
    do:
        /* Check Period End Date */
        assign viNoOfDays1 = itCurrentPeriodDate - tqPeriodByStartEndDateStatus.ttPeriodStartDate + 1
               viNoOfDays2 = tqPeriodByStartEndDateStatus.ttPeriodEndDate - itCurrentPeriodDate.

        /* Select current period */
        if viNoOfDays2 < viNoOfDays1
        then assign oiTargetPeriod     = tqPeriodByStartEndDateStatus.tiPeriodYear * 100 + tqPeriodByStartEndDateStatus.tiPeriodPeriod
                    otTargetPeriodDate = tqPeriodByStartEndDateStatus.ttPeriodEndDate.
        /* Select previous period */
        else do:
            <Q-55 run PeriodPrevPeriodByYearPeriod (all) (Read) (NoCache)
               (input iiCompanyId, (CompanyId)
                input tqPeriodByStartEndDateStatus.tiPeriodYear, (PeriodYear)
                input tqPeriodByStartEndDateStatus.tiPeriodPeriod, (PeriodPeriod)
                output dataset tqPeriodPrevPeriodByYearPeriod) in BPeriod>
            find first tqPeriodPrevPeriodByYearPeriod no-error.
            if available tqPeriodPrevPeriodByYearPeriod then
                assign oiTargetPeriod     = tqPeriodPrevPeriodByYearPeriod.tiPeriodYear
                       otTargetPeriodDate = tqPeriodPrevPeriodByYearPeriod.ttPeriodEndDate.
        end.
    end.
end.