project QadFinancials > class TConCheck > method TechnicalValidation01Posting

Description

Submethod of TechnicalValidation for checking posting


Parameters


iiCompanyIDinputinteger
iiPeriodIDinputinteger
iiSelectedYearPeriodinputinteger
itFromDateinputdate
itToDateinputdate
oiErrorNumbersoutputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method TConCheck.TechnicalValidation


program code (program1/tconcheck.p)

/* woa add checks on CrossCy and checks on PeriodMark_ID */
/* woa add a check from PostingLine --> Subledger ? */
assign oiReturnStatus = -98.

/**********************************************************************************/
/* IPR_GL_Check                                                                   */
/**********************************************************************************/
PUT STREAM sTechOut unformatted " " skip. 
PUT STREAM sTechOut unformatted vcPrefix2 + "START Validation of GL (" + STRING (itFromDate) + ")" skip.

/* =========================================== */
/* 1- do some basic checking first             */
/* =========================================== */
assign viPrevCompanyID = -1.
repeat:
    find first Posting where 
               Posting.Company_ID > viPrevCompanyID 
               no-lock no-error.
    if not available Posting 
    then leave.
    else do:
        assign viPrevCompanyID = Posting.Company_ID.
        
        if not can-find (Company of Posting)
        then do:
            for each Posting where 
                     Posting.Company_ID  = viPrevCompanyID and
                     Posting.PostingDate >= itFromDate    and
                     Posting.PostingDate <= itToDate
                     no-lock:
                assign oiErrorNumbers = oiErrorNumbers + 1.
                PUT STREAM sTechOut unformatted vcPrefix "POSTING:" + string (Posting.Posting_ID) + ";Posting(s) found with no valid company;" + string (Posting.LastModifiedDate) + ';' + Posting.lastModifiedUser skip.
            end. /* for each Posting */
        end. /* if */
                        
    end. /* else do */
end. /* repeat */    

assign viPrevCompanyID = -1.
repeat:
    find first PostingLine where 
               PostingLine.Company_ID > viPrevCompanyID
               no-lock no-error.
    if not available PostingLine 
    then leave.
    else do:
        assign viPrevCompanyID = PostingLine.Company_ID.
        
        if not can-find (Company of PostingLine)
        then do:
            for each PostingLine where 
                     PostingLine.Company_ID  = viPrevCompanyID and
                     PostingLine.PostingDate >= itFromDate    and
                     PostingLine.PostingDate <= itToDate
                     no-lock:
                assign oiErrorNumbers = oiErrorNumbers + 1.
                PUT STREAM sTechOut unformatted vcPrefix "POSTINGLINE:" + string (PostingLine.PostingLine_ID) + ";PostingLine(s) found with no valid company;" + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
            end. /* for each Posting */
        end. /* if */
                        
    end. /* else do */
end. /* repeat */ 

/* ========================================================================== */
/* 2- Go trough each Posting/PostingLine                                      */
/* ========================================================================== */
for each company where company.company_id = iiCompanyID,
    first companyProperty of company no-lock,
    first Domains of Company no-lock,
    first DomainProperty of Domains no-lock:   
    
     /* Get sharedset of the company */
    for each companysharedset no-lock where companysharedset.company_id = company.company_id,
        each sharedset of companysharedset no-lock:
        if sharedsettype = {&SHAREDSETTYPE-GL} then
            assign viGLShareSetID = sharedset.sharedset_id.
        if sharedsettype = {&SHAREDSETTYPE-DIVISION} then
            assign viDivisionSharedSetID = sharedset.sharedset_id.
        if sharedsettype = {&SHAREDSETTYPE-COSTCENTRE} then
            assign viCostCenterSharedSetID = sharedset.sharedset_id.
        if sharedsettype = {&SHAREDSETTYPE-PROJECT} then 
            assign viProjectSharedSetID = sharedset.sharedset_id.
        if sharedsettype = {&SHAREDSETTYPE-JOURNAL}  then
            assign viJournalSharedSetID = sharedset.sharedset_id.
        if sharedsettype = {&SHAREDSETTYPE-CREDITOR}  then
            assign viCreditorSharedSetID = sharedset.sharedset_id.
    end. /* end each companysharedset */   

    /* Check if all postingline has a regular posting ref */
    for each PostingLine of company no-lock where
             PostingLine.PostingDate >= itFromDate and
             PostingLine.PostingDate <= itToDate    
             break by PostingLine.Posting_ID :
    
        if first-of (PostingLine.Posting_ID)
        then do : 
            if not can-find (first Posting of PostingLine)
            then do :
               PUT STREAM sTechOut unformatted vcPrefix "PostingLine;" + string (PostingLine.PostingLine_ID) + ";PostingLine without Posting found;" + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip. 
               assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
        end. 
    end. /* FOR each postingline */
    
    assign viPrevPeriodID    = 0.

    /* ======================================================================== */
    /* Go trough each Posting                                                   */
    /* ======================================================================== */
    for each Posting of Company no-lock where
             Posting.PostingDate >= itFromDate and
             Posting.PostingDate <= itToDate :

        /* Check Journal */
        assign vcJournalCode = ''.
        find first Journal where
                   Journal.Journal_id = Posting.Journal_ID no-lock no-error.            
        if not available Journal or journal.sharedset_id <> viJournalSharedSetID
        then do: 
            PUT STREAM sTechOut unformatted vcPrefix "Posting;" + string (Posting.Posting_ID) +  ";No or wrong Journal was used;" + string (Posting.LastModifiedDate) + ';' + Posting.lastModifiedUser skip.
            assign oiErrorNumbers = oiErrorNumbers + 1.
        end.
        else if available Journal
        then do:
            assign vcJournalCode = Journal.JournalCode.
        end.

        /* Check Period */
        if viPrevPeriodID <> 0 or viPrevPeriodID <> Posting.Period_ID
        then do:
            find period of Posting no-lock no-error. 
            if not available Period
            then do:
                PUT STREAM sTechOut unformatted vcPrefix "POSTING;" + string (Posting.Posting_ID) + ";Period not found;" + string (Posting.LastModifiedDate) + ';' + Posting.lastModifiedUser skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
            assign viPrevPeriodID       = Period.Period_ID
                   vidbPeriodYear       = Period.PeriodYear
                   vidbPeriodPeriod     = period.PeriodPeriod
                   vidbPeriodYearPeriod = Period.PeriodYearperiod
                   vtdbPeriodStartDate  = Period.PeriodStartDate
                   vtdbPeriodEndDate    = Period.PeriodEndDate.                .
        end.

        if Posting.PostingYear       <> vidbPeriodYear      or
           Posting.PostingPeriod     <> vidbPeriodPeriod    or
           Posting.PostingYearPeriod <> vidbPeriodYearPeriod
        then do:
            PUT STREAM sTechOut unformatted vcPrefix "POSTING;" + string (Posting.Posting_ID) + ";Mismatch in Period between POSTING and Period table;" +
                       string (Posting.LastModifiedDate) + ";" + Posting.LastModifiedUser skip.
            assign oiErrorNumbers = oiErrorNumbers + 1.
        end.

        if Posting.PostingDate < vtdbPeriodStartDate or
           Posting.PostingDate > vtdbPeriodEndDate
        then do :
            PUT STREAM sTechOut unformatted vcPrefix  "POSTING;" + string (Posting.Posting_ID) + ";Mismatch Posting Start/End : " +
                            string (Period.PeriodYearperiod) + ' * ' + string (Period.PeriodStartDate)  + ' * ' + string (Period.PeriodEndDate) + ' * ' + string (Posting.PostingDate) + ';' +
                            string (Posting.LastModifiedDate) + ";" + Posting.LastModifiedUser skip.
            assign oiErrorNumbers = oiErrorNumbers + 1.                
        end.

        /* ======================================================================== */
        /* Go trough each PostingLine                                               */
        /* ======================================================================== */
        assign vdBalanceLC = 0 
               vdBalanceCC = 0.
        
        for each PostingLine of Posting no-lock :
        
            assign vdBalanceLC = vdBalanceLC + PostingLine.PostingLineDebitLC - PostingLine.PostingLineCreditLC
                   vdBalanceCC = vdBalanceCC + PostingLine.PostingLineDebitCC - PostingLine.PostingLineCreditCC.

            /* Check GL */
            assign vlGLIsProjectAccount    = ?
                   vlGLIsCostcentreAccount = ?
                   vlGLIsDivisionAccount   = ?.

            find first GL where
                       GL.GL_id = PostingLine.GL_ID no-lock no-error.           

            if not available GL or gl.sharedset_id <> viGLShareSetID
            then do:
                PUT STREAM sTechOut unformatted vcPrefix "POSTINGLine;" + string (PostingLine.PostingLine_ID) +  ";No or wrong GL was used;" + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
            else if available GL
            then do:
                assign vlGLIsProjectAccount    = Gl.GLIsProjectAccount
                       vlGLIsCostcentreAccount = gl.GLIsCostcentreAccount
                       vlGLIsDivisionAccount   = GL.GLIsDivisionAccount.
            end.

            /* Check PostingLine.Company_ID */
            if PostingLine.Company_ID <> Posting.Company_ID
            then do:
                PUT STREAM sTechOut unformatted vcPrefix  "POSTING;" + string (Posting.Posting_ID) + ";Mismatch between PostingLine.Company_ID and Posting.Company_ID: " +
                                string (PostingLine.Company_ID) + ' * ' + string (Posting.Company_ID)
                               + ";" + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.

            /* Check PostingLine.Period_ID */
            if PostingLine.Period_ID <> Posting.Period_ID
            then do:
                PUT STREAM sTechOut unformatted vcPrefix  "POSTING;" + string (Posting.Posting_ID) + ";Mismatch between PostingLine.Period_ID and Posting.Period_ID: " +
                                string (PostingLine.Period_ID) + ' * ' + string (Posting.Period_ID)
                               + ";" + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.

            /* Check PostingLine.PostingYearPeriod */
            if PostingLine.PostingYearPeriod <> Posting.PostingYearPeriod
            then do: 
                PUT STREAM sTechOut unformatted vcPrefix  "POSTING;" + string (Posting.Posting_ID) + ";Mismatch between PostingLine.PostingYearPeriod and Posting.PostingYearPeriod: " +
                                string (PostingLine.PostingYearPeriod) + ' * ' + string (Posting.PostingYearPeriod)
                                + ";" + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.

            /* Check PostingLine.PostingDate */
            if PostingLine.PostingDate <> Posting.PostingDate
            then do: 
                PUT STREAM sTechOut unformatted vcPrefix  "POSTING;" + string (Posting.Posting_ID) + ";Mismatch between PostingLine.PostingDate and Posting.PostingDate: " +
                                string (PostingLine.PostingDate) + ' * ' + string (Posting.PostingDate)
                                + ";" + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.

            /* Check PostingLine.Currency_ID */
            if PostingLine.Currency_ID = 0 or PostingLine.Currency_ID = ?
            then do:
                PUT STREAM sTechOut unformatted vcPrefix  "PostingLine;" + string (PostingLine.PostingLine_ID) + ";PostingLine without currency specified;" + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
            else
            /* Check consistency in TC vs LC */
            /* This test is skipped for exchange rate accounts, rounding and autobalance account and reval postings */
            if PostingLine.Currency_ID = CompanyProperty.currency_id     and
               GL.GLSystemType         <> 'ROUND'                        and 
               GL.GLSystemType         <> 'AUTOBALANCE'                  and
               GL.GLSystemType         <> 'EXCHANGEUNREALPROFIT'         and 
               GL.GLSystemType         <> 'EXCHANGEUNREALLOSS'           and 
               GL.GLSystemType         <> 'EXCHANGEREALPROFIT'           and 
               GL.GLSystemType         <> 'EXCHANGEREALLOSS'             and
               available Journal and not (Journal.JournalTypeCode begins 'REVAL')                
            then do :
               if PostingLine.PostingLineDebitTC <> PostingLine.PostingLineDebitLC
               then do: 
                   PUT STREAM sTechOut unformatted vcPrefix  "PostingLine;" + string (PostingLine.PostingLine_ID) +  ";PostingLine in LC but TC <> LC (debit): "
                                   + vcJournalCode + ' * ' + string (PostingLine.PostingLineDebitTC) + ' * ' + string (PostingLine.PostingLineDebitLC) + ';' +
                                   string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                   assign oiErrorNumbers = oiErrorNumbers + 1.
               end.

               if PostingLine.PostingLineCreditTC <> PostingLine.PostingLineCreditLC
               then do:
                   PUT STREAM sTechOut unformatted vcPrefix  "PostingLine;" + string (PostingLine.PostingLine_ID) +  ";PostingLine in LC but TC <> LC (credit): "
                                   + vcJournalCode + ' * ' + string (PostingLine.PostingLineCreditTC) + ' * ' + string (PostingLine.PostingLineCreditLC) + ';'
                                   + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                   assign oiErrorNumbers = oiErrorNumbers + 1.
               end.
            end.

            /* Check consistency in TC vs SC */
            if DomainProperty.StatutoryCurrency_ID = PostingLine.Currency_ID and 
               GL.GLSystemType         <> 'ROUND'                        and 
               GL.GLSystemType         <> 'AUTOBALANCE'                  and
               GL.GLSystemType         <> 'EXCHANGEUNREALPROFIT'         and 
               GL.GLSystemType         <> 'EXCHANGEUNREALLOSS'           and 
               GL.GLSystemType         <> 'EXCHANGEREALPROFIT'           and 
               GL.GLSystemType         <> 'EXCHANGEREALLOSS'             and
               available Journal and not (Journal.JournalTypeCode begins 'REVAL')  
            then do:
                if PostingLine.PostingLineDebitTC <> PostingLine.PostingLineDebitCC
                then do: 
                    PUT STREAM sTechOut unformatted vcPrefix  "PostingLine;" + string (PostingLine.PostingLine_ID) +  ";PostingLine Currency is same as Statutory Currency but TC amount <> CC amount(debit): "
                                   + vcJournalCode + ' * ' + string (PostingLine.PostingLineDebitTC) + ' * ' + string (PostingLine.PostingLineDebitCC) + ';' +
                                   string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                end.

                if PostingLine.PostingLineCreditTC <> PostingLine.PostingLineCreditCC
                then do:
                    PUT STREAM sTechOut unformatted vcPrefix  "PostingLine;" + string (PostingLine.PostingLine_ID) +  ";PostingLine Currency is same as Statutory Currency but TC amount <> CC amount (credit): "
                                   + vcJournalCode + ' * ' + string (PostingLine.PostingLineCreditTC) + ' * ' + string (PostingLine.PostingLineCreditCC) + ';'
                                   + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                end.
            end.

            /* Check consistency in BC SC */
            if DomainProperty.DomainPropertyIsStatutory = false and
               DomainProperty.StatutoryCurrency_ID = CompanyProperty.currency_id     and
               GL.GLSystemType                     <> 'ROUND'                        and 
               GL.GLSystemType                     <> 'AUTOBALANCE':U                and
               GL.GLSystemType                     <> 'EXCHANGEUNREALPROFIT'         and 
               GL.GLSystemType                     <> 'EXCHANGEUNREALLOSS'           and 
               GL.GLSystemType                     <> 'EXCHANGEREALPROFIT'           and 
               GL.GLSystemType                     <> 'EXCHANGEREALLOSS'             and
               available Journal and not (Journal.JournalTypeCode begins 'REVAL')
            then do:

                if PostingLine.PostingLineDebitCC  <> PostingLine.PostingLineDebitLC
                then do:
                     PUT STREAM sTechOut unformatted vcPrefix "POSTINGLine;" + string (PostingLine.PostingLine_ID) + 
                          ";SC is disabled but the debit values in SC are different from BC : " +
                          string (PostingLine.PostingLineDebitLC) + ' * ' + string (PostingLine.PostingLineDebitCC) +
                          ";" + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser
                           skip.
                      assign oiErrorNumbers = oiErrorNumbers + 1.
                end.
                
                if PostingLine.PostingLineCreditCC  <> PostingLine.PostingLineCreditLC 
                then do:
                     PUT STREAM sTechOut unformatted vcPrefix "POSTINGLine;" + string (PostingLine.PostingLine_ID) + 
                         ";SC is disabled but the credit values in SC are different from BC : " +
                         string (PostingLine.PostingLineCreditLC) + ' * ' + string (PostingLine.PostingLineCreditCC) +
                         ";" + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser  
                         skip.
                      assign oiErrorNumbers = oiErrorNumbers + 1.
                 end.
            
            end. /* Check consistency in BC SC  */

            /* Check Division */
            if PostingLine.Division_ID <> 0 and PostingLine.Division_ID <> ?
            then do:
                find first Division where
                           Division.Division_id = PostingLine.Division_ID no-lock no-error.
                if not available Division or Division.sharedset_id <> viDivisionSharedSetID
                then do: 
                    PUT STREAM sTechOut unformatted vcPrefix "PostingLine;" + string (PostingLine.PostingLine_ID) +  ";No or wrong Division was used;" + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                end.
            end.

            /* Check  Gl.GLIsDivisionAccount */
            if not vlGLIsDivisionAccount AND PostingLine.Division_ID > 0
            then do :
                PUT STREAM sTechOut unformatted vcPrefix  "PostingLine;" + string (PostingLine.PostingLine_ID) + ";Transactions on sub-accounts found on account which is disabled for sub-accounts; " +
                               string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.

            /* Check CostCentre */
            if PostingLine.CostCentre_ID <> 0 and PostingLine.CostCentre_ID <> ?
            then do:
                find first CostCentre where
                           CostCentre.CostCentre_id = PostingLine.CostCentre_ID no-lock no-error.
                if not available CostCentre or CostCentre.sharedset_id <> viCostCenterSharedSetID
                then do: 
                    PUT STREAM sTechOut unformatted vcPrefix "PostingLine;" + string (PostingLine.PostingLine_ID) +  ";No or wrong CostCentre was used;" + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                end.
            end.     

            if not vlGLIsCostcentreAccount AND PostingLine.Costcentre_ID > 0
            then do :
                PUT STREAM sTechOut unformatted vcPrefix "PostingLine;" + string (PostingLine.PostingLine_ID) + ";Transactions on costcentres found on account which is disabled for costcentres; " +
                               string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.

            /* Check Project */
            if PostingLine.Project_ID <> 0 and PostingLine.Project_ID <> ?
            then do:
                find first qaddb.Project where
                           qaddb.Project.Project_id = PostingLine.Project_ID no-lock no-error.
                if not available qaddb.Project or qaddb.Project.sharedset_id <> viProjectSharedSetID
                then do: 
                    PUT STREAM sTechOut unformatted vcPrefix "PostingLine;" + string (PostingLine.PostingLine_ID) +  ";No or wrong Project was used;" + string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                end.
            end.     
     
            if not vlGLIsProjectAccount AND PostingLine.project_ID > 0
            then do :
                PUT STREAM sTechOut unformatted vcPrefix + "PostingLine;" + string (PostingLine.PostingLine_ID) + ";Transactions on projects found on account which is disabled for projects; " +
                               string (PostingLine.LastModifiedDate) + ';' + PostingLine.lastModifiedUser skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
        
        end. /* for each PostingLine of Posting no-lock */

        if vdBalanceLC <> 0
        then do:
            PUT STREAM sTechOut unformatted vcPrefix "POSTING;" + string (Posting.Posting_ID) + ";Posting not in balance for LC amounts;" + string (Posting.LastModifiedDate) + ';' + Posting.lastModifiedUser skip.
            assign oiErrorNumbers = oiErrorNumbers + 1.
        end.

        if vdBalanceCC <> 0
        then do: 
            PUT STREAM sTechOut unformatted vcPrefix "POSTING;" + string (Posting.Posting_ID) + ";Posting not in balance for CC amounts;" + string (Posting.LastModifiedDate) + ';' + Posting.lastModifiedUser skip.
            assign oiErrorNumbers = oiErrorNumbers + 1.
        end.
        
        /* ======================================================================== */
        /* Check  Unmarked Transactions                                                  */
        /* ======================================================================== */
        if Posting.PeriodMarK_ID = 0 or Posting.PeriodMarK_ID = ? 
        then do:
            PUT STREAM sTechOut unformatted vcPrefix "POSTING;" + string (Posting.Posting_ID) + ";Unmarked Transaction;" + string (Posting.LastModifiedDate) + ';' + Posting.lastModifiedUser skip.
            assign oiErrorNumbers = oiErrorNumbers + 1
                   vlIsHasUnmarkedTransaction = yes.
        end. /* end if Posting.PeriodMarK_ID = 0 or Posting.PeriodMarK_ID = ?*/
      
    end. /* for each Posting of Company */
    if not vlIsHasUnmarkedTransaction 
    then do:
        PUT STREAM sTechOut unformatted vcPrefix "No unmarked transactions were found for the selected GL period." skip.
    end.

end. /* for each company */

PUT STREAM sTechOut unformatted vcPrefix2 + "END Validation GL." skip.

if oiReturnStatus = -98
then assign oiReturnStatus = 0.