project QadFinancials > class BDebtorReport > method DebtorAgeingAnalysisBackwardsDrafts


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDebtorReport.DebtorAgeingAnalysisBackwards


program code (program7/bdebtorreport.p)

/* ================================================================================ */
/* Process the tqGetDraftInvoicesforDAAB and create tqDebtorAgeingAnalysisBackwards */
/* ================================================================================ */
assign vcPIPDescription = {&GLTYPECODE-DDOC-TR}.
for each tqGetDraftInvoicesforDAAB 
    break by tqGetDraftInvoicesforDAAB.tiDDocument_ID:
    
    if first-of(tqGetDraftInvoicesforDAAB.tiDDocument_ID)
    then do:
         /* If "Within terms = no", skip all drafts that aren't due yet */
         assign vlSkip = vlInvoicesWithinTermsFilter = false and tqGetDraftInvoicesforDAAB.ttDDocumentDueDate >= vtDateForAgeingCalcFilter
               vdBalanceCC = 0
               vdBalanceLC = 0
               vdBalanceTC = 0
               viPostingYear   = trunc (tqGetDraftInvoicesforDAAB.tiPostingYearPeriod / 100,0) 
               viPostingPeriod = tqGetDraftInvoicesforDAAB.tiPostingYearPeriod mod 100 
               vtPostingDate   = tqGetDraftInvoicesforDAAB.ttPostingDate. 
    end.

    if vlSkip
    then next.

    /* Calcualate the balance of the draft DDocument --> DDocumentPostingLine --> PostingLine */
    assign vdBalanceCC = vdBalanceCC + tqGetDraftInvoicesforDAAB.tdPostingLineDebitCC - tqGetDraftInvoicesforDAAB.tdPostingLineCreditCC
           vdBalanceLC = vdBalanceLC + tqGetDraftInvoicesforDAAB.tdPostingLineDebitLC - tqGetDraftInvoicesforDAAB.tdPostingLineCreditLC
           vdBalanceTC = vdBalanceTC + tqGetDraftInvoicesforDAAB.tdPostingLineDebitTC - tqGetDraftInvoicesforDAAB.tdPostingLineCreditTC.

    /* calculate the Year Period and PostingDate as this is not kept in DDocument */
    if tqGetDraftInvoicesforDAAB.ttPostingDate < vtPostingDate
    then assign viPostingYear   = trunc (tqGetDraftInvoicesforDAAB.tiPostingYearPeriod / 100,0)
                viPostingPeriod = tqGetDraftInvoicesforDAAB.tiPostingYearPeriod mod 100
                vtPostingDate   = tqGetDraftInvoicesforDAAB.ttPostingDate.

    /* create the cr result set */
    if last-of (tqGetDraftInvoicesforDAAB.tiDDocument_ID) and
       (vdBalanceCC <> 0 or vdBalanceLC <> 0 or vdBalanceTC <> 0)
    then do:
        
        case vcReportingCurrencyFilter:
            when {&CURRENCYTYPE-CC}
            then assign vdBalanceXC   = vdBalanceCC
                        vdOriginal1XC = vdOriginal1CC.
            when {&CURRENCYTYPE-LC}
            then assign vdBalanceXC   = vdBalanceLC
                        vdOriginal1XC = vdOriginal1LC.
            when {&CURRENCYTYPE-TC}
            then assign vdBalanceXC   = vdBalanceTC
                        vdOriginal1XC = vdOriginal1TC.
        end. /* case */
        
        /* tcrDebtorAgeingAnalysisBackwards */
        create tqDebtorAgeingAnalysisBackwards.
        assign tqDebtorAgeingAnalysisBackwards.tcDebtorCode                 = tqGetDraftInvoicesforDAAB.tcDebtorCode
               tqDebtorAgeingAnalysisBackwards.tcDebtorTypeCode             = tqGetDraftInvoicesforDAAB.tcDebtorTypeCode
               tqDebtorAgeingAnalysisBackwards.tcDebtorTypeDescription      = tqGetDraftInvoicesforDAAB.tcDebtorTypeDescription
               tqDebtorAgeingAnalysisBackwards.tdDebtorPercTurnOverCredLim  = tqGetDraftInvoicesforDAAB.tdDebtorPercTurnOverCredLim
               tqDebtorAgeingAnalysisBackwards.tdDebtorFixedCredLimTC       = tqGetDraftInvoicesforDAAB.tdDebtorFixedCredLimTC

               tqDebtorAgeingAnalysisBackwards.tiBusinessRelation_ID        = tqGetDraftInvoicesforDAAB.tiBusinessRelation_ID
               tqDebtorAgeingAnalysisBackwards.tcBusinessRelationCode       = tqGetDraftInvoicesforDAAB.tcBusinessRelationCode
               tqDebtorAgeingAnalysisBackwards.tcBusinessRelationName1      = tqGetDraftInvoicesforDAAB.tcBusinessRelationName1
               tqDebtorAgeingAnalysisBackwards.tcBusinessRelationName2      = tqGetDraftInvoicesforDAAB.tcBusinessRelationName2
               tqDebtorAgeingAnalysisBackwards.tcBusinessRelationSearchName = tqGetDraftInvoicesforDAAB.tcBusinessRelationSearchName
               tqDebtorAgeingAnalysisBackwards.tcControlGLCode              = 'PIP'
               tqDebtorAgeingAnalysisBackwards.tcControlGLDescription       = vcPIPDescription
               tqDebtorAgeingAnalysisBackwards.tcCurrencyCode               = tqGetDraftInvoicesforDAAB.tcCurrencyCode
               tqDebtorAgeingAnalysisBackwards.tcCurrencyDescription        = tqGetDraftInvoicesforDAAB.tcCurrencyDescription
               tqDebtorAgeingAnalysisBackwards.tiCurrencyNumberOfDecimals   = tqGetDraftInvoicesforDAAB.tiCurrencyNumberOfDecimals
               tqDebtorAgeingAnalysisBackwards.tiDInvoice_ID                = tqGetDraftInvoicesforDAAB.tiDDocument_ID
               tqDebtorAgeingAnalysisBackwards.ttDInvoiceDate               = tqGetDraftInvoicesforDAAB.ttDDocumentCreationDate
               tqDebtorAgeingAnalysisBackwards.tcDInvoiceDescription        = tqGetDraftInvoicesforDAAB.tcDDocumentReference
               tqDebtorAgeingAnalysisBackwards.ttDInvoiceDueDate            = tqGetDraftInvoicesforDAAB.ttDDocumentDueDate
               tqDebtorAgeingAnalysisBackwards.tiDInvoiceReminderCount      = ?
               tqDebtorAgeingAnalysisBackwards.tcDInvoiceType               = tqGetDraftInvoicesforDAAB.tcDDocumentType
               tqDebtorAgeingAnalysisBackwards.tcJournalCode                = tqGetDraftInvoicesforDAAB.tcPayFormatTypeCode
               tqDebtorAgeingAnalysisBackwards.tiPeriodPeriod               = viPostingPeriod
               tqDebtorAgeingAnalysisBackwards.tiPeriodYear                 = viPostingYear
               tqDebtorAgeingAnalysisBackwards.tiPostingVoucher             = tqGetDraftInvoicesforDAAB.tiDDocumentNumber
               tqDebtorAgeingAnalysisBackwards.tiDInvoiceVoucher            = tqGetDraftInvoicesforDAAB.tiDDocumentNumber
               
               tqDebtorAgeingAnalysisBackwards.tcSortByFilter2              = vcSortByNameFilter
    
               tqDebtorAgeingAnalysisBackwards.tcDivisionCode               = ''
               tqDebtorAgeingAnalysisBackwards.tcDivisionDescription        = ''
               tqDebtorAgeingAnalysisBackwards.tcCostCentreDescription      = ''
               tqDebtorAgeingAnalysisBackwards.tcCostCentreCode             = ''
               tqDebtorAgeingAnalysisBackwards.tcProjectCode                = ''
               tqDebtorAgeingAnalysisBackwards.tcProjectDescription         = ''
    
               tqDebtorAgeingAnalysisBackwards.tdBalanceTC                  = vdBalanceTC
               tqDebtorAgeingAnalysisBackwards.tdBalanceXC                  = vdBalanceXC
               tqDebtorAgeingAnalysisBackwards.tdAgeingPeriod1BalanceXC     = 0
               tqDebtorAgeingAnalysisBackwards.tdAgeingPeriod2BalanceXC     = 0
               tqDebtorAgeingAnalysisBackwards.tdAgeingPeriod3BalanceXC     = 0
               tqDebtorAgeingAnalysisBackwards.tdAgeingPeriod4BalanceXC     = 0
               tqDebtorAgeingAnalysisBackwards.tdAgeingPeriod5BalanceXC     = 0
               tqDebtorAgeingAnalysisBackwards.tcDebtorCurrency             = tqGetDraftInvoicesforDAAB.tcDebtorCurrency.
        
        find first tAgeingPeriod where
                   tAgeingPeriod.ttAgeingPeriodFromDate <= tqGetDraftInvoicesforDAAB.ttDDocumentDueDate and
                   tAgeingPeriod.ttAgeingPeriodToDate   >= tqGetDraftInvoicesforDAAB.ttDDocumentDueDate no-error.
        if available tAgeingPeriod
        then case tAgeingPeriod.tiAgeingPeriodSeq:
            when 1
            then assign tqDebtorAgeingAnalysisBackwards.tdAgeingPeriod1BalanceXC = vdBalanceXC.
            when 2
            then assign tqDebtorAgeingAnalysisBackwards.tdAgeingPeriod2BalanceXC = vdBalanceXC.
            when 3
            then assign tqDebtorAgeingAnalysisBackwards.tdAgeingPeriod3BalanceXC = vdBalanceXC.
            when 4
            then assign tqDebtorAgeingAnalysisBackwards.tdAgeingPeriod4BalanceXC = vdBalanceXC.
            when 5
            then assign tqDebtorAgeingAnalysisBackwards.tdAgeingPeriod5BalanceXC = vdBalanceXC.
        end case.

    end. /* if last-of (tqGetDraftInvoicesforDAAB.tiDDocument_ID) */

end. /* for each tqGetDraftInvoicesforDAAB */