project QadFinancials > class BDebtorReport > method DebtorBillingAABDrafts


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDebtorReport.DebtorBillingAAB


program code (program7/bdebtorreport.p)

/* ================================================================================ */
/* Process the tqGetDraftInvoicesforDAAB and create tqDebtorBillingAAB              */
/* ================================================================================ */
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 */

        /* tcrDebtorBillingAAB */
        create tqDebtorBillingAAB.
        assign tqDebtorBillingAAB.tcDebtorCode                 = tqGetDraftInvoicesforDAAB.tcDebtorCode
               tqDebtorBillingAAB.tcDebtorTypeCode             = tqGetDraftInvoicesforDAAB.tcDebtorTypeCode
               tqDebtorBillingAAB.tcDebtorTypeDescription      = tqGetDraftInvoicesforDAAB.tcDebtorTypeDescription
               tqDebtorBillingAAB.tdDebtorPercTurnOverCredLim  = tqGetDraftInvoicesforDAAB.tdDebtorPercTurnOverCredLim
               tqDebtorBillingAAB.tdDebtorFixedCredLimTC       = tqGetDraftInvoicesforDAAB.tdDebtorFixedCredLimTC
               
               tqDebtorBillingAAB.tiBusinessRelation_ID        = tqGetDraftInvoicesforDAAB.tiBusinessRelation_ID
               tqDebtorBillingAAB.tcBusinessRelationCode       = tqGetDraftInvoicesforDAAB.tcBusinessRelationCode
               tqDebtorBillingAAB.tcBusinessRelationName1      = tqGetDraftInvoicesforDAAB.tcBusinessRelationName1
               tqDebtorBillingAAB.tcBusinessRelationName2      = tqGetDraftInvoicesforDAAB.tcBusinessRelationName2
               tqDebtorBillingAAB.tcBusinessRelationSearchName = tqGetDraftInvoicesforDAAB.tcBusinessRelationSearchName
               tqDebtorBillingAAB.tcControlGLCode              = 'PIP'
               tqDebtorBillingAAB.tcControlGLDescription       = vcPIPDescription
               tqDebtorBillingAAB.tcCurrencyCode               = tqGetDraftInvoicesforDAAB.tcCurrencyCode
               tqDebtorBillingAAB.tcCurrencyDescription        = tqGetDraftInvoicesforDAAB.tcCurrencyDescription
               tqDebtorBillingAAB.tiCurrencyNumberOfDecimals   = tqGetDraftInvoicesforDAAB.tiCurrencyNumberOfDecimals
               tqDebtorBillingAAB.tiDInvoice_ID                = tqGetDraftInvoicesforDAAB.tiDDocument_ID
               tqDebtorBillingAAB.ttDInvoiceDate               = tqGetDraftInvoicesforDAAB.ttDDocumentCreationDate
               tqDebtorBillingAAB.tcDInvoiceDescription        = tqGetDraftInvoicesforDAAB.tcDDocumentReference
               tqDebtorBillingAAB.ttDInvoiceDueDate            = tqGetDraftInvoicesforDAAB.ttDDocumentDueDate
               tqDebtorBillingAAB.tiDInvoiceReminderCount      = ?
               tqDebtorBillingAAB.tcDInvoiceType               = tqGetDraftInvoicesforDAAB.tcDDocumentType
               tqDebtorBillingAAB.tcJournalCode                = tqGetDraftInvoicesforDAAB.tcPayFormatTypeCode
               tqDebtorBillingAAB.tiPeriodPeriod               = viPostingPeriod
               tqDebtorBillingAAB.tiPeriodYear                 = viPostingYear
               tqDebtorBillingAAB.tiPostingVoucher             = tqGetDraftInvoicesforDAAB.tiDDocumentNumber
               tqDebtorBillingAAB.tiDInvoiceVoucher            = tqGetDraftInvoicesforDAAB.tiDDocumentNumber
               
               tqDebtorBillingAAB.tcSortByFilter2              = vcSortByNameFilter
    
               tqDebtorBillingAAB.tcDivisionCode               = ''
               tqDebtorBillingAAB.tcDivisionDescription        = ''
               tqDebtorBillingAAB.tcCostCentreDescription      = ''
               tqDebtorBillingAAB.tcCostCentreCode             = ''
               tqDebtorBillingAAB.tcProjectCode                = ''
               tqDebtorBillingAAB.tcProjectDescription         = ''
    
               tqDebtorBillingAAB.tdBalanceTC                  = vdBalanceTC
               tqDebtorBillingAAB.tdBalanceXC                  = vdBalanceXC
               tqDebtorBillingAAB.tdAgeingPeriod1BalanceXC     = 0
               tqDebtorBillingAAB.tdAgeingPeriod2BalanceXC     = 0
               tqDebtorBillingAAB.tdAgeingPeriod3BalanceXC     = 0
               tqDebtorBillingAAB.tdAgeingPeriod4BalanceXC     = 0
               tqDebtorBillingAAB.tdAgeingPeriod5BalanceXC     = 0
               
               tqDebtorBillingAAB.tiDInvoiceCompany_ID         = tqGetDraftInvoicesforDAAB.tiCompany_ID
               tqDebtorBillingAAB.tcDInvoiceCompanyCode        = tqGetDraftInvoicesforDAAB.tcCompanyCode
               tqDebtorBillingAAB.tcBillGroup                  = "Non-Bill"
               tqDebtorBillingAAB.tcBillSortKey                = "9999999999999" 
               tqDebtorBillingAAB.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 tqDebtorBillingAAB.tdAgeingPeriod1BalanceXC = vdBalanceXC.
            when 2
            then assign tqDebtorBillingAAB.tdAgeingPeriod2BalanceXC = vdBalanceXC.
            when 3
            then assign tqDebtorBillingAAB.tdAgeingPeriod3BalanceXC = vdBalanceXC.
            when 4
            then assign tqDebtorBillingAAB.tdAgeingPeriod4BalanceXC = vdBalanceXC.
            when 5
            then assign tqDebtorBillingAAB.tdAgeingPeriod5BalanceXC = vdBalanceXC.
        end case.

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

end. /* for each tqGetDraftInvoicesforDAAB */