project QadFinancials > class BPosting > method CheckCrDbAmountsForRealizedProfitLossAccounts

Description

CheckCrDbAmountsForRealizedProfitLossAccounts; this method will verify whether the business-instance contains any undeleted posting that has got ane undeleted posting-line on an account of system-type 'Realised-Exch-Gain' with a debit value filled or of system-type 'Realised-Exch-Loss' with credit-value filled.
If this is the case then an error will be raised.

This method should normally only be called from within the OpenItemAdj class as this validation is only apllicable there. In other kinds of postings, it can be allowed to have the credit/debit fields filled regardless the system-type of the account.


Parameters


iiPostingIDinputintegerIf this is filled, then the check will only be performed against that posting. If this is empty, then the check will be done for all postings in the business-instance.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BOpenItemAdjustment.OIAdjCommitSub


program code (program5/bposting.p)

/* ================================================================================================================= */
    /* CheckCrDbAmountsForRealizedProfitLossAccounts; this method will verify whether the business-instance contains any */
    /* undeleted posting that has got ane undeleted posting-line on an account of system-type 'Realised-Exch-Gain' with  */
    /* a debit value filled or of system-type 'Realised-Exch-Loss' with credit-value filled.                             */
    /* If this is the case then an error will be raised.                                                                 */
    /* This method should normally only be called from within the OpenItemAdj class as this validation is only           */
    /* apllicable there. In other kinds of postings, it can be allowed to have the credit/debit fields filled regardless */
    /* the system-type of the account.                                                                                   */
    /* ================================================================================================================= */
    
    /* Exception handling */
    assign oiReturnStatus = -98.
    
    /* Loop on the postings, posting-lines: */
    /* Note: we here cannot yet test on tPostingLine.tcGLTypeCode as this will only be filled by sure in some submethod of ValidateComponent */
    /* Note: we here cannot yet use tPostingLine.Company_ID as this will only be filled later on in the flow */
    for each tPosting where 
             tPosting.tc_Status = "N":U or 
             tPosting.tc_Status = "C":U
             no-lock :
        
        /* Skip postings */
        if iiPostingID <> 0 and 
           iiPostingID <> ? and 
           iiPostingID <> tPosting.Posting_ID
        then next.
        
        /* Loop on the posting-lines: */    
        for each tPostingLine where 
                 tPostingLine.tc_ParentRowid = tPosting.tc_Rowid and
                 (tPostingLine.tc_Status = "N":U or 
                  tPostingLine.tc_Status = "C":U)
                 no-lock :
        
            /* Start query when not yet done */
            if not vlGLByGLTypeStarted
            then do :
                <Q-5 run GLByGLType
                   (Start) in BGL >
                assign vlGLByGLTypeStarted = true.
            end. /* if not vlGLByGLTypeStarted */
            
            /* Get the systemtype of the GL */
            <Q-4 run GLByGLType (all) (Read) (NoCache)
               (input tPosting.Company_ID, (CompanyId)
                input ?, (GLId)
                input tPostingLine.tcGLCode, (GLCode)
                input ?, (GLTypeCode)
                input ?, (GLIsDivisionAccount)
                output dataset tqGLByGLType) in BGL >
            find first tqGLByGLType where
                       tqGLByGLType.tcGLCode = tPostingLine.tcGLCode
                       no-error.
            if not available tqGLByGLType
            then do:
                assign vcMessage           = trim(substitute(#T-6'The GL account &1 in the posting line cannot be found based on its code and company.':255(63316)t-6#,tPostingLine.tcGLCode)) + chr(10) + 
                                             trim(substitute(#T-8'Posting: &1/&2/&3.':255(14145)T-8#,string(tPosting.PostingYear),tPosting.tcJournalCode,string(tPosting.PostingVoucher))) + chr(10) +
                                             trim(substitute(#T-7'Company ID: &1.':255(63317)t-7#,string(tPosting.Company_ID))) 
                       viLocalReturnStatus = -1.
                <M-2 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tPostingLine.tcGLCode':U (icFieldName), 
                    input  tPostingLine.tcGLCode (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tPostingLine.tc_Rowid (icRowid), 
                    input  'QadFin-6461':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPosting>
                next.
            end. /* if not available tqGLByGLType */
            
            /* Check the system-type for the realised-exchange-rate-gain/loss in combination with the value of the line */
            if tqGLByGLType.tcGLSystemTypeCode = {&GLSYSTEMTYPE-EXCHANGEREALPROFIT} and 
               ((tPostingLine.PostingLineDebitTC <> 0 and 
                 tPostingLine.PostingLineDebitTC <> ?)      Or
                (tPostingLine.PostingLineDebitLC <> 0 and 
                 tPostingLine.PostingLineDebitLC <> ?)      Or
                (tPostingLine.PostingLineDebitCC <> 0 and 
                 tPostingLine.PostingLineDebitCC <> ?))
            then do :
                assign vcMessage           = trim(substitute(#T-10'The posting line on the GL account &1 refers to the system account type &2. You cannot use this system account type in open item adjustment postings.':255(63318)t-10#,tPostingLine.tcGLCode,{&GLSYSTEMTYPE-EXCHANGEREALPROFIT-TR})) + chr(10) + 
                                             trim(substitute(#T-11'Posting: &1/&2/&3.':255(14145)T-11#,string(tPosting.PostingYear),tPosting.tcJournalCode,string(tPosting.PostingVoucher))) + chr(10) +
                                             trim(substitute(#T-12'Debit TC: &1':255(63319)T-12#,string(tPostingLine.PostingLineDebitTC))) + chr(10) + 
                                             trim(substitute(#T-13'Debit LC: &1':255(63695)T-13#,string(tPostingLine.PostingLineDebitLC))) + chr(10) + 
                                             trim(substitute(#T-14'Debit CC: &1':255(63696)T-14#,string(tPostingLine.PostingLineDebitCC)))
                       viLocalReturnStatus = -1.
                <M-9 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tPostingLine.tcGLCode':U (icFieldName), 
                    input  tPostingLine.tcGLCode (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tPostingLine.tc_Rowid (icRowid), 
                    input  'QadFin-6462':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPosting>
                next.
            end. /* if tqGLByGLType.tcGLSystemTypeCode = {&GLSYSTEMTYPE-EXCHANGEREALPROFIT} and */
            if tqGLByGLType.tcGLSystemTypeCode = {&GLSYSTEMTYPE-EXCHANGEREALLOSS} and 
               ((tPostingLine.PostingLineCreditTC <> 0 and 
                 tPostingLine.PostingLineCreditTC <> ?)      Or
                (tPostingLine.PostingLineCreditLC <> 0 and 
                 tPostingLine.PostingLineCreditLC <> ?)      Or
                (tPostingLine.PostingLineCreditCC <> 0 and 
                 tPostingLine.PostingLineCreditCC <> ?))
            then do :
                assign vcMessage           = trim(substitute(#T-22'The posting line on the GL account &1 refers to the system account type &2. You cannot use this system account type in open item adjustment postings.':255(63318)t-22#,tPostingLine.tcGLCode,{&GLSYSTEMTYPE-EXCHANGEREALLOSS-TR})) + chr(10) + 
                                             trim(substitute(#T-23'Posting: &1/&2/&3.':255(14145)T-23#,string(tPosting.PostingYear),tPosting.tcJournalCode,string(tPosting.PostingVoucher))) + chr(10) +
                                             trim(substitute(#T-24'Credit TC: &1':255(63322)T-24#,string(tPostingLine.PostingLineDebitTC))) + chr(10) + 
                                             trim(substitute(#T-25'Credit LC: &1':255(63323)T-25#,string(tPostingLine.PostingLineDebitLC))) + chr(10) + 
                                             trim(substitute(#T-26'Credit CC: &1':255(63324)T-26#,string(tPostingLine.PostingLineDebitCC)))
                       viLocalReturnStatus = -1.
                <M-21 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tPostingLine.tcGLCode':U (icFieldName), 
                    input  tPostingLine.tcGLCode (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tPostingLine.tc_Rowid (icRowid), 
                    input  'QadFin-6464':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPosting>
                next.
            end. /* if tqGLByGLType.tcGLSystemTypeCode = {&GLSYSTEMTYPE-EXCHANGEREALLOSS} and */
        
        end. /* for each postingline*/
        
    end. /* for each posting */
    
    /* Start query when not yet done */
    if vlGLByGLTypeStarted
    then do :
        <Q-27 run GLByGLType
           (Stop) in BGL >
    end. /* if not vlGLByGLTypeStarted */
    
    /* Exception handling */
    assign oiReturnStatus = viLocalReturnStatus.