project QadFinancials > class BDebtorReport > method DebtorBillingAAB

report procedure

Description

DebtorBillingAAB


Parameters


icLanguageCodeinputcharacter
tFilterinputtemp-table
dcrDebtorBillingAABoutputdataset
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program7/bdebtorreport.p)

empty temp-table tqDebtorBillingAAB.

<M-20 run GetReportLabels
   (input  'DebtorBillingAAB':U (icReportName), 
    input  icLanguageCode (icLanguageCode), 
    input  tFilter (tFilter), 
    output tqHeader (tqHeader), 
    output tqFilter (tqFilter), 
    output tqText (tqText), 
    output viFcReturnSuper (oiReturnStatus)) in BDebtorReport>
if viFcReturnSuper < 0 or oiReturnStatus  = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.

/* Get SetDataItemsBasedOnFilterTT */
<M-1 run SetDataItemsBasedOnFilterTT  (output  viFcReturnSuper (oiReturnStatus)) in BDebtorReport>
if viFcReturnSuper < 0 or oiReturnStatus  = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.

create tqFilter.
assign 
    tqFilter.ti_Sequence = 0
    tqFilter.tcBusinessFieldLabel = "icActivityCode":U
    tqFilter.tcBusinessFieldName = "SummaryByInfo":U
    tqFilter.tcParameterValue = vcSummaryByFilter.

/* Run some validations on the filter values */       
<M-80 run ValidateDateFilter
   (output vtAgingDate (otAgingDate), 
    output viFcReturnSuper (oiReturnStatus)) in BDebtorReport>
if viFcReturnSuper < 0 or oiReturnStatus  = 0
then assign oiReturnStatus = viFcReturnSuper.
    
<M-28 run ValidateAgeingFilters  (output viFcReturnSuper (oiReturnStatus)) in BDebtorReport>
if viFcReturnSuper < 0 or oiReturnStatus  = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.

/* Calculate Ageing periods */
<M-3 run SetAgeingPeriod  (output viFcReturnSuper (oiReturnStatus)) in BDebtorReport>
if viFcReturnSuper < 0 or oiReturnStatus  = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.

/* If no currency selected, set default currency to LC */
if vcReportingCurrencyFilter = ?
then assign vcReportingCurrencyFilter = {&CURRENCYTYPE-LC}.

/* Get Filter Company Id list */
<M-96 run GetMultipleCompanyIdList  (output viFcReturnSuper (oiReturnStatus)) in BDebtorReport>

<Q-41 run DInvoiceStageByInvoice (Start) in BDebtorReport >
/* ============================================================== */
/* Get all the Invoices open at end of viToYearPeriodFilter       */
/* Note the aging date is not relevant here                       */
/* Query : Debtor --> Bill --> DInvoice                           */
/* ============================================================== */
do viDRCompanyIterator = 1 to viDRCompanyEntries:
    /* Get Info about Company (this method fills viDRCurrentCompany_ID) */
    <M-62 run CrossCompanyValues
       (input  viDRCompanyIterator (iiEntryNumber), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtorReport>
    
    if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.
    
    if oiReturnStatus < 0
    then return.
    
    /* Invoice in Bill */
    <M-8 run DebtorBillingInvoiceAAB
       (input  vtAgingDate (itAgingDate), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtorReport>
    /* Include non-bill invoice */
    if vlIncludeNonBillInvoiceFilter = yes /*and
       viCompanyId = viDRCurrentCompany_Id*/ then
    do:
        <M-35 run DebtorBillingNonBillInvoiceAAB
           (input  vtAgingDate (itAgingDate), 
            output viFcReturnSuper (oiReturnStatus)) in BDebtorReport>
    end.
end. /*do viDRCompanyIterator = 1 to viDRCompanyEntries*/

<Q-43 run DInvoiceStageByInvoice (Stop) in BDebtorReport >

/* ================================================== */
/* Get the Drafts                                     */
/* ================================================== */
if vlIncludeDraftsFilter = TRUE
then do:
    /* Get the Open Draft Payments */
    <Q-46 run GetDraftInvoicesforDAAB (all) (Read) (NoCache)
       (input viCompanyId, (CompanyId)
        input vcFromDebtorCodeFilter, (FromDebtorCode)
        input vcToDebtorCodeFilter, (ToDebtorCode)
        input vcCandoDebtorCodeFilter, (CandoDebtorCode)
        input vcFromBRCodeFilter, (FromBRCode)
        input vcToBRCodeFilter, (ToBRCode)
        input vcCandoBRCodeFilter, (CandoBRCode)
        input vcCurrencyCodeFilter, (CurrencyCode)
        input vtAgingDate, (AgeingDate)
        input vcCandoDContrGLCodeFilter, (CanDoGLCode)
        input vcFromDContrGLCodeFilter, (FromGLCode)
        input vcToDContrGLCodeFilter, (ToGLCode)
        input {&DOCUMENTTYPE-DRAFT}, (DDocumentDraftType)
        input vcDebtorTypeFilter, (DebtorTypeCode)
        input vcPaymentGroupFilter, (PaymentGroup)
        output dataset tqGetDraftInvoicesforDAAB) in BDebtorReport >

    <M-95 run DebtorBillingAABDrafts  (output viFcReturnSuper (oiReturnStatus)) in BDebtorReport>
    if viFcReturnSuper < 0 or oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0 then return.

end. /* if vlIncludeDraftsFilter = TRUE */

/* ===================================================== */
/* Get the Customer Address Contact Data             */
/* ===================================================== */
empty temp-table tqDebtorAddressContactInfo.

<Q-39 run AddressTypeByCode (all) (Read) (NoCache)
   (input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
    output dataset tqAddressTypeByCode) in BAddressType>

find first tqAddressTypeByCode where
           tqAddressTypeByCode.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}
           no-error.
if available tqAddressTypeByCode
then do:
    <Q-12 run DebtorAddressContactInfo (all) (Read) (NoCache)
       (input viCompanyId, (CompanyId)
        input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
        input vcCandoBRCodeFilter, (CandoBRCode)
        input vcCandoDebtorCodeFilter, (CandoDebtorCode)
        input vcFromBRCodeFilter, (FromBRCode)
        input vcFromDebtorCodeFilter, (FromDebtorCode)
        input vcToBRCodeFilter, (ToBRCode)
        input vcToDebtorCodeFilter, (ToDebtorCode)
        input tqAddressTypeByCode.tiAddressType_ID, (AddressType_ID)
        output dataset tqDebtorAddressContactInfo) in BDebtorReport>

end. /* if available tqAddressTypeByCode */

for each tqDebtorBillingAAB
         break by tqDebtorBillingAAB.tcDebtorCode:
  
/*
    /* Set Bill Group as Bill or Non-bill */
    if (tqDebtorBillingAAB.tiBill_ID <> 0 and (viDRCurrentCompany_ID = ? or viDRCurrentCompany_ID = 0)) or
         (tqDebtorBillingAAB.tiBill_ID <> 0 and viDRCurrentCompany_ID <> 0 and tqDebtorBillingAAB.tiDInvoiceCompany_ID = viDRCurrentCompany_ID)
    then assign tqDebtorBillingAAB.tcBillGroup = "Bill".
    else assign tqDebtorBillingAAB.tcBillGroup = "Non-Bill".
*/

    if first-of (tqDebtorBillingAAB.tcDebtorCode)
    then assign vdBalanceXC = 0.

    assign vdBalanceXC = vdBalanceXC + tqDebtorBillingAAB.tdBalanceXC
           tqDebtorBillingAAB.tcSortByFilter2 = vcSortByNameFilter.

    if last-of(tqDebtorBillingAAB.tcDebtorCode)
    then do:
        if vcDebtorBalanceFilter = {&DEBTORBALANCE-CREDIT} and vdBalanceXC > 0 or
           vcDebtorBalanceFilter = {&DEBTORBALANCE-DEBIT}  and vdBalanceXC < 0
        then do:
            for each bDebtorBillingAAB where
                     bDebtorBillingAAB.tcDebtorCode = tqDebtorBillingAAB.tcDebtorCode and
                     rowid(bDebtorBillingAAB) <> rowid(tqDebtorBillingAAB):
                delete bDebtorBillingAAB.
            end.
            delete tqDebtorBillingAAB.
        end.
        else do:
            assign vdCreditOnTurnOver = ?.

            /* First look for an address and a contact */
            find first tqDebtorAddressContactInfo where
                       tqDebtorAddressContactInfo.tcDebtorCode = tqDebtorBillingAAB.tcDebtorCode AND
                       tqDebtorAddressContactInfo.tcContactName > ''
                       no-error.
            if not available tqDebtorAddressContactInfo
            then do :
                /* First look for an address only */
                find first tqDebtorAddressContactInfo where
                           tqDebtorAddressContactInfo.tcDebtorCode = tqDebtorBillingAAB.tcDebtorCode
                           no-error.
            end.
        
            if available tqDebtorAddressContactInfo
            then do :
                
                for each bDebtorBillingAAB where
                         bDebtorBillingAAB.tcDebtorCode = tqDebtorBillingAAB.tcDebtorCode:

                    assign bDebtorBillingAAB.tcAddressCity        = tqDebtorAddressContactInfo.tcAddressCity
                           bDebtorBillingAAB.tcAddressFax         = tqDebtorAddressContactInfo.tcAddressFax
                           bDebtorBillingAAB.tcAddressStreet1     = tqDebtorAddressContactInfo.tcAddressStreet1
                           bDebtorBillingAAB.tcAddressStreet2     = tqDebtorAddressContactInfo.tcAddressStreet2
                           bDebtorBillingAAB.tcAddressStreet3     = tqDebtorAddressContactInfo.tcAddressStreet3
                           bDebtorBillingAAB.tcAddressTelephone   = tqDebtorAddressContactInfo.tcAddressTelephone
                           bDebtorBillingAAB.tcAddressZip         = tqDebtorAddressContactInfo.tcAddressZip
                           bDebtorBillingAAB.tcAddressState       = tqDebtorAddressContactInfo.tcAddressState
                           bDebtorBillingAAB.tiAddressFormat      = tqDebtorAddressContactInfo.tiAddressFormat
                           bDebtorBillingAAB.tcCountryDescription = tqDebtorAddressContactInfo.tcCountryDescription
                           bDebtorBillingAAB.tcContactEmail       = tqDebtorAddressContactInfo.tcContactEmail
                           bDebtorBillingAAB.tcContactName        = tqDebtorAddressContactInfo.tcContactName
                           bDebtorBillingAAB.tcContactMobile      = tqDebtorAddressContactInfo.tcContactMobilePhone
                           bDebtorBillingAAB.tcContactPhone       = tqDebtorAddressContactInfo.tcContactTelephone

                           bDebtorBillingAAB.tdDebtorFixedCredLimTC      = tqDebtorBillingAAB.tdDebtorFixedCredLimTC
                           bDebtorBillingAAB.tdDebtorPercTurnOverCredLim = tqDebtorBillingAAB.tdDebtorPercTurnOverCredLim
                           bDebtorBillingAAB.tdDebtorCreditOnTurnOver    = vdCreditOnTurnOver. 
                           
                end. /* for each bDebtorBillingAAB */
            end. /* if available tqDebtorAddressContactInfo */
        end. /* else do */
    end. /* if last-of(tqDebtorBillingAAB.tcDebtorCode) */
end. /* for each tqDebtorBillingAAB */