project QadFinancials > class BWithholdingTax > method ValidateComponent

Description

Write here all tests on database update (new / modify / delete) that cannot be coded with a validation mask.
The type of update can be found in tc_status (N/C/D).
If you find incorrect data, you must write an entry in tFcMessages (using SetMessage) and set the return status of this method to either +1 or -1.
Return status +1 = data will still be accepted.
Return status -1 = data will not be accepted.
This method is run from SetPublicTables, before transferring the received data into the class temp-tables.


Parameters


oiReturnStatusoutputinteger


Internal usage


unused


program code (program/bwithholdingtax.p)

    
    /* ============================================================= */
    /* Avoid having NULL values in field belonging to a unique index */
    /* ============================================================= */
    for each t_sWHT where
             t_sWHT.tc_Status = "N":U or 
             t_sWHT.tc_Status = "C":U  :
        if t_sWHT.Company_ID = ?
        then assign t_sWHT.Company_ID = 0.
        if t_sWHT.CInvoiceWHT_ID = ?
        then assign t_sWHT.CInvoiceWHT_ID = 0.
        if t_sWHT.BankStateAlloc_ID = ?
        then assign t_sWHT.BankStateAlloc_ID = 0.       
        if t_sWHT.CDocumentInvoiceXref_ID = ?
        then assign t_sWHT.CDocumentInvoiceXref_ID = 0.
        if t_sWHT.OIAdjustLn_ID = ?
        then assign t_sWHT.OIAdjustLn_ID = 0.
        if t_sWHT.CACInvoice_ID = ?
        then assign t_sWHT.CACInvoice_ID = 0.
        if t_sWHT.WHTChargeType = ?
        then assign t_sWHT.WHTChargeType = "":U.
    end. /* for each t_sWHT where */
    
    
<ANCESTOR-CODE>
    
    /* ========================================================================= */
    /* Check if the _ID fields were resolved with the correct company/shared set */
    /* If not, correct them                                                      */
    /* ========================================================================= */
    for each t_sWHT where
             t_sWHT.Company_ID <> viCompanyId and
             t_sWHT.Company_ID <> 0           and
             t_sWHT.Company_ID <> ?
             break by t_sWHT.Company_ID
             on error undo, throw:
        /* If we are working in the same domain, then we have the same shared sets, */
        /* so we don't need to resolve _IDs all over again anymore                  */
        if first-of(t_sWHT.Company_ID)
        then do:
            <Q-62 run CompanyByCompanyIdCode (all) (Read) (NoCache)
               (input t_sWHT.Company_ID, (CompanyId)
                input '':U, (CompanyCode)
                output dataset tqCompanyByCompanyIdCode) in BCompany>
            find tqCompanyByCompanyIdCode where
                 tqCompanyByCompanyIdCode.tiCompany_ID = t_sWHT.Company_ID
                 no-lock no-error.
            if available tqCompanyByCompanyIdCode
            then assign viWHTDomainID = tqCompanyByCompanyIdCode.tiDomain_ID.
            else assign viWHTDomainID = ?.
        end. /* if first-of(t_sWHT.Company_ID) */
        if viDomainID = viWHTDomainID        
        then next.
        
        /* Creditor_ID */     
        <Q-20 run CreditorPrim (all) (Read) (NoCache)
           (input t_sWHT.Company_ID, (CompanyId)
            input ?, (CreditorId)
            input t_sWHT.tcCreditorCode, (CreditorCode)
            output dataset tqCreditorPrim) in BCreditor>
        find tqCreditorPrim where
             tqCreditorPrim.tcCreditorCode = t_sWHT.tcCreditorCode
             no-lock no-error.
        if available tqCreditorPrim 
        then assign t_sWHT.Creditor_ID = tqCreditorPrim.tiCreditor_ID.
        
        /* GL_ID */
        <Q-42 run GLPrim (all) (Read) (NoCache)
           (input t_sWHT.Company_ID, (CompanyId)
            input t_sWHT.tcGLCode, (GLCode)
            input ?, (GLId)
            output dataset tqGLPrim) in BGL>
        find tqGLPrim where
             tqGLPrim.tcGLCode = t_sWHT.tcGLCode
             no-lock no-error.
        if available tqGLPrim 
        then assign t_sWHT.GL_ID = tqGLPrim.tiGL_ID.            
            
        /* Division_ID */
        <Q-55 run DivisionPrim (all) (Read) (NoCache)
           (input t_sWHT.Company_ID, (CompanyId)
            input ?, (DivisionID)
            input t_sWHT.tcDivisionCode, (DivisionCode)
            output dataset tqDivisionPrim) in BDivision>
        find tqDivisionPrim where
             tqDivisionPrim.tcDivisionCode = t_sWHT.tcDivisionCode
             no-lock no-error.
        if available tqDivisionPrim 
        then assign t_sWHT.Division_ID = tqDivisionPrim.tiDivision_ID. 
                
        /* Project_ID */
        <Q-54 run ProjectPrim (all) (Read) (NoCache)
           (input t_sWHT.Company_ID, (CompanyId)
            input ?, (ProjectID)
            input t_sWHT.tcProjectCode, (ProjectCode)
            output dataset tqProjectPrim) in BProject>
        find tqProjectPrim where
             tqProjectPrim.tcProjectCode = t_sWHT.tcProjectCode
             no-lock no-error.
        if available tqProjectPrim 
        then assign t_sWHT.Project_ID = tqProjectPrim.tiProject_ID. 
                
        /* CostCentre_ID */
        <Q-92 run CostCentrePrim (all) (Read) (NoCache)
           (input t_sWHT.Company_ID, (CompanyId)
            input ?, (CostCentreID)
            input t_sWHT.tcCostCentreCode, (CostCentreCode)
            output dataset tqCostCentrePrim) in BCostCentre>
        find tqCostCentrePrim where
             tqCostCentrePrim.tcCostCentreCode = t_sWHT.tcCostCentreCode
             no-lock no-error.
        if available tqCostCentrePrim 
        then assign t_sWHT.CostCentre_ID = tqCostCentrePrim.tiCostCentre_ID.         
    end. /* for each tWHT where */
    
    /* =============================================================================================== */
    /* Table WHT holds some redundant fields: we make sure sure here that they are filled in all cases */
    /* We only do this in create mode to avoid overhead.                                               */
    /* =============================================================================================== */
    <M-30 run ValidateComponentPost  (output viFcReturnSuper (oiReturnStatus)) in BWithholdingTax>
    if viFcReturnSuper <> 0 and 
       oiReturnStatus  >= 0
    then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 
    then Return.