project QadFinancials > class BCreditorReport > method CreditorAccountsSummary

report procedure


Parameters


icLanguageCodeinputcharacter
tFilterinputtemp-table
dcrCreditorAccountsSummaryoutputdataset
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program7/bcreditorreport.p)

empty temp-table tqCreditorAccountsSummary.

<M-10 run GetReportLabels (input  'CreditorAccountsSummary':U (icReportName), 
                           input  icLanguageCode (icLanguageCode), 
                           input  tFilter (tFilter), 
                           output tqHeader (tqHeader), 
                           output tqFilter (tqFilter), 
                           output tqText (tqText), 
                           output oiReturnStatus (oiReturnStatus)) in BCreditorReport>
if oiReturnStatus <> 0
then return.

/*assign tFilter*/
<M-5 run SetDataItemsBasedOnFilterTT (output viFcReturnSuper (oiReturnStatus)) in BCreditorReport>

if vlCheckHistoryFilterCR = ? or vlCheckHistoryFilterCR
then do:   
    <Q-11 assign vlFcQueryRecordsAvailable = QCInvoiceMovementAll (NoCache)
       (input viCompanyId, (CompanyId)
        input ?, (DaemonId)) in BQCInvoiceMovement >
    if vlFcQueryRecordsAvailable = true or
       vlFcQueryRecordsAvailable = ?
    then do:              
        <M-12 run SetMessage
           (input  #T-13'Run the Balance daemon to update the supplier balances.':70(65167)t-13# (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-3441':U (icFcMsgNumber), 
            input  #T-14'There are still transactions in the Balance daemon queue. Run to Balance daemon to process the queue or data inconsistencies could occur.':150(65166)t-14# (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output oiReturnStatus (oiReturnStatus)) in BCreditorReport>                                              
        assign oiReturnStatus = -1.
        return.
    end.
end. /* if vlCheckHistoryFilterCR = ? or vlCheckHistoryFilterCR */ 

/* get base currency code and pass it to UI through tqFilter */ /* ddl 10132-2713 */
<Q-17 run CompanyPropertyByIdCode (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input ?, (CompanyPropertyId)
    input ?, (BusinessRelationId)
    input ?, (CurrencyId)
    input ?, (CompanyPropertyCode)
    input ?, (CompanyCode)
    input ?, (BusinessRelationCode)
    input ?, (CurrencyCode)
    output dataset tqCompanyPropertyByIdCode) in BCompanyProperty >

find first tqCompanyPropertyByIdCode no-lock no-error.
if available tqCompanyPropertyByIdCode
then do:
    create tqFilter.
    assign tqFilter.ti_Sequence          = 0
           tqFilter.tcBusinessFieldLabel = 'icActivityCode':U
           tqFilter.tcBusinessFieldName  = 'BaseCurr':U
           tqFilter.tcParameterValue     = tqCompanyPropertyByIdCode.tcCurrencyCode.
end.

if vcSummaryByFilter1 <> '':U and
   vcSummaryByFilter1 <> ?
then do:
    create tqFilter.
    assign 
        tqFilter.ti_Sequence = 0
        tqFilter.tcBusinessFieldLabel = "icActivityCode":U
        tqFilter.tcBusinessFieldName = "SummaryByFilter":U
        tqFilter.tcParameterValue = vcSummaryByFilter1.
end.

/* ===================================================================================*/ 
/* Check Period Input paramters and give a default value if needed.                    */
/* =================================================================================== */
assign viYearPeriodFrom = viFromAccYearFilter1 * 100 + viFromAccPeriodFilter1
       viYearPeriodTill = viToAccYearFilter1 * 100 + viToAccPeriodFilter1.
if viYearPeriodFrom = 0 then assign viYearPeriodFrom = 1.
if viYearPeriodTill = 0 then assign viYearPeriodTill = 999999.


/* =================================================================================== */
/* Get all The Movements for the selection criteria between Period from and PeriodTill */
/* Note that when a CHist record is found, it means there are activities done, even    */
/* when the debit and/or credit amount is 0 (CHist is a summary)                       */
/* =================================================================================== */ 
<Q-61 run CreditorMovementsSummary (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input vcCandoCreditorCodeFilter1, (CandoCreditorCode)
    input vcCandoBRCodeFilter1, (CandoBRCode)
    input vcFromBRCodeFilter1, (FromBRCode)
    input vcFromCreditorCodeFilter1, (FromCreditorCode)
    input viYearPeriodTill, (ToAccYearPeriod)
    input vcToBRCodeFilter1, (ToBRCode)
    input vcToCreditorCodeFilter1, (ToCreditorCode)
    input viYearPeriodFrom, (FromAccYearPeriod)
    input vcToCContrGLCodeFilter1, (ToGLCode)
    input vcFromCContrGLCodeFilter1, (FromGLCode)
    input vcCandoCContrGLCodeFilter1, (CanDoGLCode)
    output dataset tqCreditorMovementsSummary) in BCreditorReport >
    
/* =================================================================================== */
/* Get all The Balance at the beginning of the From Period                             */               
/* =================================================================================== */ 

<Q-35 run CreditorBalanceSummary (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input vcCandoCreditorCodeFilter1, (CandoCreditorCode)
    input vcCandoBRCodeFilter1, (CandoBRCode)
    input vcFromBRCodeFilter1, (FromBRCode)
    input vcFromCreditorCodeFilter1, (FromCreditorCode)
    input viYearPeriodfrom - 1, (AccYearPeriod)
    input vcToBRCodeFilter1, (ToBRCode)
    input vcToCreditorCodeFilter1, (ToCreditorCode)
    input vcFromCContrGLCodeFilter1, (FromGLCode)
    input vcToCContrGLCodeFilter1, (ToGLCode)
    input vcCandoCContrGLCodeFilter1, (CandoGLCode)
    output dataset tqCreditorBalanceSummary) in BCreditorReport >    

/* =================================================================================== */
/* Build up the result set which contains both the movements and the closing balance   */
/* =================================================================================== */
/* ***************************/
/* Merge the Opening Balance */
/* ***************************/
for each tqCreditorBalanceSummary :

    /* In case there is a 0 balance, we skip it */
    if tqCreditorBalanceSummary.tdCHistBalanceLC = 0 and
       tqCreditorBalanceSummary.tdCHistBalanceTC = 0
    then next.

    find tqCreditorAccountsSummary where    
         tqCreditorAccountsSummary.tcCreditorCode   = tqCreditorBalanceSummary.tcCreditorCode   and
         tqCreditorAccountsSummary.tcGLCode         = tqCreditorBalanceSummary.tcGLCode         and         
         tqCreditorAccountsSummary.tcCurrencyCode   = tqCreditorBalanceSummary.tcCurrencyCode   and
         tqCreditorAccountsSummary.tcCostCentreCode = tqCreditorBalanceSummary.tcCostCentreCode and
         tqCreditorAccountsSummary.tcProjectCode    = tqCreditorBalanceSummary.tcProjectCode    and
         tqCreditorAccountsSummary.tcDivisionCode   = tqCreditorBalanceSummary.tcDivisionCode   and
         tqCreditorAccountsSummary.tcJournalCode    = tqCreditorBalanceSummary.tcJournalCode   
         no-error.
    if not available tqCreditorAccountsSummary 
    then do :
        create tqCreditorAccountsSummary.
        buffer-copy tqCreditorBalanceSummary to tqCreditorAccountsSummary.
        assign tqCreditorAccountsSummary.tdCreditorCreditLC  = 0
               tqCreditorAccountsSummary.tdCreditorCreditTC  = 0
               tqCreditorAccountsSummary.tdCreditorDebitLC   = 0
               tqCreditorAccountsSummary.tdCreditorDebitTC   = 0
               tqCreditorAccountsSummary.tdSumBeforePeriodLC = 0
               tqCreditorAccountsSummary.tdSumBeforePeriodTC = 0.
    end. /*if not available tqCreditorAccountsSummary */
    
    assign tqCreditorAccountsSummary.tdSumBeforePeriodLC = tqCreditorAccountsSummary.tdSumBeforePeriodLC +
                                                           tqCreditorBalanceSummary.tdCHistBalanceLC
           tqCreditorAccountsSummary.tdSumBeforePeriodTC = tqCreditorAccountsSummary.tdSumBeforePeriodTC +
                                                           tqCreditorBalanceSummary.tdCHistBalanceTC.             
end. /* for each tqCreditorBalanceSummary : */


/* ***********************************************************************************************/
/* In case only Activity is selected, remove all the records which do not have a Movement linked */
/* ***********************************************************************************************/
if vcCreditorBalanceFilter1 = "ACTIVITY"
then do :
    for each tqCreditorAccountsSummary:        

        find tqCreditorMovementsSummary where
             tqCreditorMovementsSummary.tcCreditorCode   = tqCreditorAccountsSummary.tcCreditorCode   and
             tqCreditorMovementsSummary.tcGLCode         = tqCreditorAccountsSummary.tcGLCode         and
             tqCreditorMovementsSummary.tcCurrencyCode   = tqCreditorAccountsSummary.tcCurrencyCode   and
             tqCreditorMovementsSummary.tcJournalCode    = tqCreditorAccountsSummary.tcJournalCode    and
             tqCreditorMovementsSummary.tcDivisionCode   = tqCreditorAccountsSummary.tcDivisionCode   and
             tqCreditorMovementsSummary.tcCostCentreCode = tqCreditorAccountsSummary.tcCostCentreCode and
             tqCreditorMovementsSummary.tcProjectCode    = tqCreditorAccountsSummary.tcProjectCode
             no-error.
             
         if not available tqCreditorMovementsSummary 
         then delete tqCreditorAccountsSummary.
         
    end. /* for each tqCreditorAccountsSummary */
end.


/* *********************/
/* Merge the Movements */
/* *********************/
for each tqCreditorMovementsSummary :

    find tqCreditorAccountsSummary where    
         tqCreditorAccountsSummary.tcCreditorCode   = tqCreditorMovementsSummary.tcCreditorCode   and
         tqCreditorAccountsSummary.tcGLCode         = tqCreditorMovementsSummary.tcGLCode         and         
         tqCreditorAccountsSummary.tcCurrencyCode   = tqCreditorMovementsSummary.tcCurrencyCode   and
         tqCreditorAccountsSummary.tcCostCentreCode = tqCreditorMovementsSummary.tcCostCentreCode and
         tqCreditorAccountsSummary.tcProjectCode    = tqCreditorMovementsSummary.tcProjectCode    and
         tqCreditorAccountsSummary.tcDivisionCode   = tqCreditorMovementsSummary.tcDivisionCode   and
         tqCreditorAccountsSummary.tcJournalCode    = tqCreditorMovementsSummary.tcJournalCode   
         no-error.
    if not available tqCreditorAccountsSummary 
    then do :    
        create tqCreditorAccountsSummary.
        buffer-copy tqCreditorMovementsSummary to tqCreditorAccountsSummary.
        assign tqCreditorAccountsSummary.tdCreditorCreditLC  = 0
               tqCreditorAccountsSummary.tdCreditorCreditTC  = 0
               tqCreditorAccountsSummary.tdCreditorDebitLC   = 0
               tqCreditorAccountsSummary.tdCreditorDebitTC   = 0
               tqCreditorAccountsSummary.tdSumBeforePeriodLC = 0
               tqCreditorAccountsSummary.tdSumBeforePeriodTC = 0.
    end. /*if not available tqCreditorAccountsSummary*/
    
    assign tqCreditorAccountsSummary.tdCreditorCreditLC = tqCreditorAccountsSummary.tdCreditorCreditLC + tqCreditorMovementsSummary.tdCHistMovementCreditLC
           tqCreditorAccountsSummary.tdCreditorCreditTC = tqCreditorAccountsSummary.tdCreditorCreditTC + tqCreditorMovementsSummary.tdCHistMovementCreditTC    
           tqCreditorAccountsSummary.tdCreditorDebitLC  = tqCreditorAccountsSummary.tdCreditorDebitLC + tqCreditorMovementsSummary.tdCHistMovementDebitLC
           tqCreditorAccountsSummary.tdCreditorDebitTC  = tqCreditorAccountsSummary.tdCreditorDebitTC + tqCreditorMovementsSummary.tdCHistMovementDebitTC.

end. /* for each tqCreditorMovementsSummary */


/* ========================================== */
/* Check the criteria and remove where needed */
/* ========================================== */
for each tqCreditorAccountsSummary :

    /* Remove in case the end-balance is not a credit balance */
    if vcCreditorBalanceFilter1 = {&CREDITORBALANCE-CREDIT}
    then do:
        if (tqCreditorAccountsSummary.tdSumBeforePeriodLC + tqCreditorAccountsSummary.tdCreditorDebitLC - tqCreditorAccountsSummary.tdCreditorCreditLC >= 0) and
           (tqCreditorAccountsSummary.tdSumBeforePeriodTC + tqCreditorAccountsSummary.tdCreditorDebitTC - tqCreditorAccountsSummary.tdCreditorCreditTC >= 0)
        then delete tqCreditorAccountsSummary.
    end.
    else
    /* Remove in case the end-balance is not a debit balance */    
    if vcCreditorBalanceFilter1 = {&CREDITORBALANCE-DEBIT}
    then do :
        if (tqCreditorAccountsSummary.tdSumBeforePeriodLC + tqCreditorAccountsSummary.tdCreditorDebitLC - tqCreditorAccountsSummary.tdCreditorCreditLC <= 0) and
           (tqCreditorAccountsSummary.tdSumBeforePeriodTC + tqCreditorAccountsSummary.tdCreditorDebitTC - tqCreditorAccountsSummary.tdCreditorCreditTC <= 0)
        then delete tqCreditorAccountsSummary.    
    end.
    else
    /* Remove in case the end-balance is 0 */
    if vcCreditorBalanceFilter1 = {&CREDITORBALANCE-BALANCE}
    then do :
        if (tqCreditorAccountsSummary.tdSumBeforePeriodLC + tqCreditorAccountsSummary.tdCreditorDebitLC - tqCreditorAccountsSummary.tdCreditorCreditLC = 0) and
           (tqCreditorAccountsSummary.tdSumBeforePeriodTC + tqCreditorAccountsSummary.tdCreditorDebitTC - tqCreditorAccountsSummary.tdCreditorCreditTC = 0)
        then delete tqCreditorAccountsSummary.    
    end.
    else
    /* Remove in case closing = 0 and no activity */
    if vcCreditorBalanceFilter1 = "ACTIVITY-" + {&CREDITORBALANCE-BALANCE} or
       vcCreditorBalanceFilter1 = {&CREDITORBALANCE-ALL}
    then do :
        /* do nothing */
    end.    
end.  /*for each tqCreditorAccountsSummary */