project QadFinancials > class BAPMatching > method ValidateComponentPreTaxAbsRet

Description

ValidateComponentPreValidate: submethod of ValidateComponent


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.ValidateComponentPre


program code (program4/bapmatching.p)

/* ==================================================================================================================== */
/* Method:      ValidateComponentPreTaxAbsRet                                                                           */
/* Description: This method does some corrections of the of the Absorbed/Retained tax indication in the financial data  */
/* Problem:     The main reason for this is the way how Absorbed/Retained incidation is calculated in finance.          */
/*              Finance is using amount of absorbed/retained to decide, whether this is absorbed/retained taxes.        */
/*              But because of different rounding and calcualtion in operational, this value can be 0 and so then       */
/*              Finance can get confused about it and for the records where TaxTC is zero, it does not properly fill    */
/*              these fields in APMatchingLnTax: APMatchingLnTaxIsAbsRet, tcAbsRetTaxGLCode and tcAbsRetTaxDivisionCode */ 
/* Solution:    The solution to this problem that we implement here in this method is that for the APMatchingLnTax      */
/*              records where TaxTC is zero, we look for another APMatchingLnTax-record with the same VAT-code and      */
/*              if we find such record then we copy the content of these 3 fields into the record where TaxTC is zero   */
/* ==================================================================================================================== */
 
/* ============================= */
/* Check for record-availability */
/* ============================= */
if not available t_sAPMatching
then do :
    assign oiReturnStatus      = -1
           vcMsgAPMatching     = trim(substitute(#T-45'Internal error: no AP matching record is available.':255(56009)T-45#)).
    <M-38 run SetMessage
       (input  vcMsgAPMatching (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'S':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'qadfin-885911':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    Return.
end. /* if not available t_sAPMatching */

/* ============================================================================================== */
/* Go through all zero tax lines and get rid of the ? so we can use the fields in an index        */
/* ============================================================================================== */
for each t_sAPMatchingLnTax where 
         t_sAPMatchingLnTax.APMatchingLnTaxTaxTC = ? :
    assign t_sAPMatchingLnTax.APMatchingLnTaxTaxTC = 0.
end. /* for each t_sAPMatchingLnTax where  */
for each t_sAPMatchingLnTax where 
         t_sAPMatchingLnTax.tcAbsRetTaxGLCode = ? :
    assign t_sAPMatchingLnTax.tcAbsRetTaxGLCode = "":U.
end. /* for each t_sAPMatchingLnTax where  */

/* ========================================================================================================== */
/* Only execute following code in case there is at least one APMatchingLnTax with APMatchingLnTaxTaxTC filled */
/* Check on <0 and on >0 in stead of on <>0 as so we can use an index on that field                           */
/* ========================================================================================================== */
if can-find (first t_sAPMatchingLnTax where
                   t_sAPMatchingLnTax.APMatchingLnTaxTaxTC < 0) or
   can-find (first t_sAPMatchingLnTax where
                   t_sAPMatchingLnTax.APMatchingLnTaxTaxTC > 0)
then do :
    
    /* ============================================================================================== */
    /* Go through all zero tax lines, as there is pottentially incorrectly set absorbed retained flag */
    /* ============================================================================================== */
    for each t_sAPMatchingLnTax where
             t_sAPMatchingLnTax.APMatchingLnTaxTaxTC = 0 and 
             t_sAPMatchingLnTax.tcAbsRetTaxGLCode    = "":U,
        first t_sAPMatchingLn where
              t_sAPMatchingLn.tc_Rowid        = t_sAPMatchingLnTax.tc_ParentRowid and
              t_sAPMatchingLn.tc_ParentRowid  = t_sAPMatching.tc_Rowid and
              (t_sAPMatchingLn.tc_Status      = "N":U  or
               t_sAPMatchingLn.tc_Status      = "C":U):
        
        /* ======================================================================================================================= */
        /* Go through other non-zero  tax records of receiver matching and check, if there is the same tax used as abs/ret         */
        /* We duplicate the code ehere so we check on <0 and on >0 in stead of once on <>0 as so we can use an index on that field */
        /* ======================================================================================================================= */        
        assign vlFoundAPMatchingLnTaxRecord = False.
        for each bsAPMatchingLnTax where
                 bsAPMatchingLnTax.tcVatCode             = t_sAPMatchingLnTax.tcVatCode and
                 bsAPMatchingLnTax.APMatchingLnTaxTaxTC  <  0 and
                 bsAPMatchingLnTax.tc_Rowid              <> t_sAPMatchingLnTax.tc_Rowid,
            first bsAPMatchingLn where
                  bsAPMatchingLn.tc_Rowid      = bsAPMatchingLnTax.tc_ParentRowid and
                  bsAPMatchingLn.tc_Status    <> "D":U :
            assign vlFoundAPMatchingLnTaxRecord = True
                   t_sAPMatchingLnTax.APMatchingLnTaxIsAbsRet = bsAPMatchingLnTax.APMatchingLnTaxIsAbsRet
                   t_sAPMatchingLnTax.tcAbsRetTaxGLCode       = bsAPMatchingLnTax.tcAbsRetTaxGLCode
                   t_sAPMatchingLnTax.tcAbsRetTaxDivisionCode = bsAPMatchingLnTax.tcAbsRetTaxDivisionCode.
            leave.
        end. /* for each bsAPMatchingLn where */
        if vlFoundAPMatchingLnTaxRecord = False
        then do:
            for each bsAPMatchingLnTax where
                     bsAPMatchingLnTax.tcVatCode             = t_sAPMatchingLnTax.tcVatCode and
                     bsAPMatchingLnTax.APMatchingLnTaxTaxTC  >  0 and
                     bsAPMatchingLnTax.tc_Rowid              <> t_sAPMatchingLnTax.tc_Rowid,
                first bsAPMatchingLn where
                      bsAPMatchingLn.tc_Rowid      = bsAPMatchingLnTax.tc_ParentRowid and
                      bsAPMatchingLn.tc_Status    <> "D":U :
                assign vlFoundAPMatchingLnTaxRecord = True
                       t_sAPMatchingLnTax.APMatchingLnTaxIsAbsRet = bsAPMatchingLnTax.APMatchingLnTaxIsAbsRet
                       t_sAPMatchingLnTax.tcAbsRetTaxGLCode       = bsAPMatchingLnTax.tcAbsRetTaxGLCode
                       t_sAPMatchingLnTax.tcAbsRetTaxDivisionCode = bsAPMatchingLnTax.tcAbsRetTaxDivisionCode.
                leave.
            end. /* for each bsAPMatchingLn where */
        end. /* if vlFoundAPMatchingLnTaxRecord = False */
        
    end. /* for each t_sAPMatchingLn where */
    
end. /* if can-find (first t_sAPMatchingLnTax where */