project QadFinancials > class BBankNumber > method ValidateComponentBeforeAncestor

Description

This method is run before the standard ValidateComponent.
Runs specific validations.


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankNumber.ValidateComponent


program code (program1/bbanknumber.p)

define buffer b_sBankNumberPayCode for t_sBankNumberPayCode.

assign oiReturnStatus      = -98 
       viLocalReturnStatus = 0
       vcMessage           = "":U.

/* ==================================================================================================== */
/* FIRSTLY do some conversions                                                                          */
/* 'for each t_sBankNumber' and methods called inside this block (Conversion methods) must reside       */
/* in one segment this is because t_sBankNumber is the name of the table, not the name of a buffer and  */
/* this means we are using default buffer, which is not shared                                          */
/* ==================================================================================================== */
for each t_sBankNumber where 
         t_sBankNumber.tc_Status <> "D":U :
    /* ========================================================== */
    /* CompanySharedSet_ID is only relevant and mandatory for GL  */
    /* bank-accounts in all other cases it shouldn't be specified */
    /* ========================================================== */
    if t_sBankNumber.tcCompanyCode <> "":U and
       t_sBankNumber.tcCompanyCode <> "?":U and
       t_sBankNumber.tcCompanyCode <> ? and 
       t_sBankNumber.BankNumberParentType = {&BANKNUMBERPARENTTYPE-GL}
    then do:
        assign vcSharedSetType = {&SHAREDSETTYPECODE-GL}.
        <Q-17 run CompanySSByCompanyIDCodeSSType (all) (Read) (NoCache)
          (input ?, (CompanyId)
           input vcSharedSetType, (SharedSetType)
           input t_sBankNumber.tcCompanyCode, (CompanyCode)
           output dataset tqCompanySSByCompanyIDCodeSSType) in BCompany >
        find first tqCompanySSByCompanyIDCodeSSType where 
                   tqCompanySSByCompanyIDCodeSSType.tcCompanyCode       = t_sBankNumber.tcCompanyCode and
                   tqCompanySSByCompanyIDCodeSSType.tcSharedSetTypeCode = vcSharedSetType no-error.
        if available tqCompanySSByCompanyIDCodeSSType
        then assign t_sBankNumber.CompanySharedSet_ID = tqCompanySSByCompanyIDCodeSSType.tiCompanySharedSet_ID.
        else assign t_sBankNumber.CompanySharedSet_ID = ?.
    end.
    else assign t_sBankNumber.CompanySharedSet_ID = ?.
end. /* for each t_sBankNumber */

<M-26 run IsOperationalReplicationEnabled
   (output vlReplicationEnabled (olReplicationEnabled), 
    output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
if viFcReturnSuper <> 0 and viLocalReturnStatus >=0 
then assign viLocalReturnStatus = viFcReturnSuper.

.
/* ========================================= */
/* SECONDLY do all validations               */
/* Validates all New and Changed BankNumbers */
/* ========================================= */
BANKNUMBERBLOCK:
for each t_sBankNumber where
         t_sBankNumber.tc_Status = "N":U or
         t_sBankNumber.tc_Status = "C":U or
         t_sBankNumber.tc_Status = "":U
         by t_sBankNumber.CompanySharedSet_ID
         by t_sBankNumber.ParentObject_ID 
         by t_sBankNumber.BankNumberParentType
         by t_sBankNumber.tcCompanyCode: 
    vccheck = STRING(t_sBankNumber.BankNumber + ":" + t_sBankNumber.tcBankAccFormatCode).
    /* ====================================================================================== */
    /* Retrieve the BankPayFormat based on the OwnBankNumber, PayFormatTypeCode, OwnGLAccount */
    /* ====================================================================================== */
    if (t_sBankNumber.BankPayFormat_ID = 0 or t_sBankNumber.BankPayFormat_ID = ?) and
        t_sBankNumber.tcOwnBankNumber     <> '':U and
        t_sBankNumber.tcOwnBankNumber     <> ?    and
        t_sBankNumber.tcPayFormatTypeCode <> '':U and
        t_sBankNumber.tcPayFormatTypeCode <> ?
    then do:
        if vlStartedOwnBankNumber = false
        then do:
            <Q-27 run BankNumberForOwnBankNumber  (Start) in BBankNumber >
            assign vlStartedOwnBankNumber = true.
        end.
        
        assign viGivenCompany_ID = 0.
    
        <Q-44 run CompanyPrim (all) (Read) (NoCache)
           (input ?, (LookupCompanyId)
            input t_sBankNumber.tcCompanyCode, (CompanyCode)
            output dataset tqCompanyPrim) in BCompany>
        
        find first tqCompanyPrim where 
                    tqCompanyPrim.tcCompanyCode = t_sBankNumber.tcCompanyCode no-error.

        if available tqCompanyPrim               
        then assign viGivenCompany_ID = tqCompanyPrim.tiCompany_ID.
        else assign viGivenCompany_ID = viCompanyId.
        
        
        <Q-28 run BankNumberForOwnBankNumber (first) (Read) (NoCache)
           (input viGivenCompany_ID, (CompanyId)
            input t_sBankNumber.tcOwnBankNumber, (OwnBankNumber)
            input t_sBankNumber.tcOwnGLCode, (OwnGLCode)
            input t_sBankNumber.tcPayFormatTypeCode, (PayFormatTypeCode)
            output dataset tqBankNumberForOwnBankNumber) in BBankNumber>
        find first tqBankNumberForOwnBankNumber where
                   tqBankNumberForOwnBankNumber.tcOwnBankNumber     = t_sBankNumber.tcOwnBankNumber and
                   tqBankNumberForOwnBankNumber.tcPayFormatTypeCode = t_sBankNumber.tcPayFormatTypeCode
                   no-error.
        if available tqBankNumberForOwnBankNumber
        then assign t_sBankNumber.BankPayFormat_ID = tqBankNumberForOwnBankNumber.tiBankPayFormat_ID.
        else do:
            assign vcMessage          = trim(#T-29'Bank Payment Format could not be resolved.':255(733752399)T-29#)                     + chr(10) +
                                        trim(substitute(#T-30'Own BankNumber: &1.':255(332067703)T-30#, t_sBankNumber.tcOwnBankNumber)) + chr(10) +
                                        trim(substitute(#T-31'Own GL Code: &1':255(591287700)T-31#, t_sBankNumber.tcOwnGLCode))         + chr(10) +
                                        trim(substitute(#T-32'Payment Format Type: &1':255(227650214)T-32#, t_sBankNumber.tcPayFormatTypeCode))
                   viLocalReturnStatus = -1.
            <M-33 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sBankNumber.tc_Rowid (icRowid), 
                input  'QadFin-9726':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
            leave BANKNUMBERBLOCK.
        end. /* else do: */
    end. /* if (t_sBankNumber.BankPayFormat_ID = 0 or t_sBankNumber.BankPayFormat_ID = ?) and */       

    /* Execute query only if BankPayFormat_ID <> 0 */
    if t_sBankNumber.BankPayFormat_ID <> 0 and
       t_sBankNumber.BankPayFormat_ID <> ? and
       (t_sBankNumber.tcOwnBankNumber = '':U or t_sBankNumber.tcOwnBankNumber = ?) and
       (t_sBankNumber.tcOwnGLCode     = '':U or t_sBankNumber.tcOwnGLCode     = ?)
    then do:
        <Q-35 run BankPayFormatByID (all) (Read) (NoCache)
           (input t_sBankNumber.BankPayFormat_ID, (BankPayFormatId)
            input viCompanyId, (CompanyId)
            output dataset tqBankPayFormatByID) in BBankPayFormat >
        find first tqBankPayFormatByID no-error.
        if available tqBankPayFormatByID
        then assign t_sBankNumber.tcPayFormatTypeCode              = tqBankPayFormatByID.tcPayFormatTypeCode                   
                    t_sBankNumber.tcPayFormatTypePaymentInstrument = tqBankPayFormatByID.tcPayFormatTypePayInstrument
                    t_sBankNumber.tcOwnBankNumber                  = tqBankPayFormatByID.tcBankNumber
                    t_sBankNumber.tcOwnGLCode                      = tqBankPayFormatByID.tcGLCode.
    end. /* if t_sBankNumber.BankPayFormat_ID <> 0 and */

    /* ============================================================================================ */
    /* Assign and validate the ParentObject_ID based on tcParentObjectCode and BankNumberParentType */
    /* ============================================================================================ */
    if t_sBankNumber.BankNumberParentType <> "":U and 
       t_sBankNumber.BankNumberParentType <> ?    and 
       t_sBankNumber.tcParentObjectCode   <> "":U and 
       t_sBankNumber.tcParentObjectCode   <> ?    and 
       (t_sBankNumber.ParentObject_ID = 0 or 
        t_sBankNumber.ParentObject_ID = ?)
    then do :
        <M-18 run ValidateComponentParentObject (output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
        if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0 then 
        assign viLocalReturnStatus = viFcReturnSuper.
    end. /* if */
            
    /* ==================================================== */
    /* ValCompanySharedSet - mandatory for GL bank accounts */
    /* ==================================================== */
    <M-6 run ValidateComponentCompanySS (output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
    if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0 
    then assign viLocalReturnStatus = viFcReturnSuper.
    
    /* ================================================================================ */
    /* BankNumberIsDefault : check each ParentObject_ID, BankNumberParentType only once */
    /* ================================================================================ */
    if viCompanySharedSetId <> t_sBankNumber.CompanySharedSet_ID  or 
       viParentObjectId     <> t_sBankNumber.ParentObject_ID      or
       vcParentType         <> t_sBankNumber.BankNumberParentType or
       vcBankCompanyCode    <> t_sBankNumber.tcCompanyCode
    then do:
        assign viCompanySharedSetId = t_sBankNumber.CompanySharedSet_ID
               viParentObjectId     = t_sBankNumber.ParentObject_ID
               vcParentType         = t_sBankNumber.BankNumberParentType
               vcBankCompanyCode    = t_sBankNumber.tcCompanyCode.
        <M-5 run ValidateComponentIsDefault (output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
        if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0 
        then assign viLocalReturnStatus = viFcReturnSuper.
    end. /* if viCompanySharedSetId <> t_sBankNumber.CompanySharedSet_ID or */

    /* ========== */
    /* BankNumber */
    /* ========== */
    assign vcBankNumber   = "":U
           vcBankNumberFr = "":U.
     
    /* Perform bank account section validations: mandatory, length */
    for each tBankNumberSection where tBankNumberSection.tiBankNumber_ID = t_sBankNumber.BankNumber_ID:
        if tBankNumberSection.tlBankAccFormatSectIsMandat = true and tBankNumberSection.tcSectionValue = ""
        then do:
            /* Bank Account Section is mandatory */
            assign vcMessage           =  trim(substitute(#T-22'Bank Account Section: &1 is mandatory':255(65362)T-22#, tBankNumberSection.tcBankAccFormatSectLabel))
                   viLocalReturnStatus = -1.
            <M-23 run SetMessage
               (input  vcMessage (icMessage), 
                input  '' (icArguments), 
                input  '' (icFieldName), 
                input  '' (icFieldValue), 
                input  'E' (icType), 
                input  3 (iiSeverity), 
                input  '' (icRowid), 
                input  'QadFin-7009':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
            leave BANKNUMBERBLOCK.
        end. /* if tBankNumberSection.tlBankAccFormatSectIsMandat = true and tBankNumberSection.tcSectionValue = "" */
        if tBankNumberSection.tcSectionValue <> "" and
           length(tBankNumberSection.tcSectionValue, "CHARACTER") > tBankNumberSection.tiBankAccFormatSectLength
        then do:
            /* Bank Account Section exceeds maximum length */
            assign vcMessage           = trim(substitute(#T-24'The bank account section &1 exceeds the maximum length: &2.':255(65363)T-24#,
                                               tBankNumberSection.tcBankAccFormatSectLabel,
                                               tBankNumberSectionRef.tiBankAccFormatSectLength))
                   viLocalReturnStatus = -1.
            <M-25 run SetMessage
               (input  vcMessage (icMessage), 
                input  '' (icArguments), 
                input  'tBankNumberSection.tcSectionValue' (icFieldName), 
                input  tBankNumberSection.tcSectionValue (icFieldValue), 
                input  'E' (icType), 
                input  3 (iiSeverity), 
                input  'tBankNumberSection.tc_Rowid' (icRowid), 
                input  'QadFin-7010':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBankNumber> 
            leave BANKNUMBERBLOCK.
        end. /* if tBankNumberSection.tcSectionValue <> "" and */ 
    end.

    /* Only validate the bank number if replication is enabled */
    if vlReplicationEnabled
    then do:    
        <I-20 {bFcStartAndOpenInstance
                &CLASS              = "BBankAccountFormat"}>
        if LOOKUP(vccheck,vcsource) = 0
        then do:
           <M-19 run ValBankAccount
           (input  t_sBankNumber.BankNumber (icBankAccountNumber), 
            input  t_sBankNumber.tcBankAccFormatCode (icBankAccountValidationCode), 
            output viFcReturnSuper (oiReturnStatus)) in BBankAccountFormat>
           
           if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
           then assign viLocalReturnStatus = viFcReturnSuper.
           vcsource = STRING(vcsource + vccheck + ",").
        end.   
    
        <I-21 {bFcCloseAndStopInstance
                &CLASS           = "BBankAccountFormat"}>
    end. /* if vlReplicationEnabled */
end. /* for each t_sBankNumber (BANKNUMBERBLOCK) */

/* Stop Queries */
if vlStartedOwnBankNumber = true
then do:
    <Q-34 run BankNumberForOwnBankNumber  (Start) in BBankNumber >
    assign vlStartedOwnBankNumber = false.
end. /* if vlStartedOwnBankNumber = true */

assign oiReturnStatus = viLocalReturnStatus.