project QadFinancials > class BBankEntry > method ValidateComponentPre

Description

Validate if the banknumber isn't already in db, if so, then get a new one

Assign the BankStateAlllocCCRate BankStateAllocScale BankStateAllocCollCCRate BankStateAllocCollCCSCale and calculate the BankStateAllocDifferenceCC BankStateAllocCollDiffCC


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankEntry.ValidateComponent


program code (program4/bbankentry.p)

/* validate if bankstatenumber doesn't already exist, if so, get a new number */
    /* necessary for automatically creation of banking entries */
    for each t_sbankstate where
             t_sBankState.tc_Status = "N":U
             no-lock :
        /* In banking import file process, tBankState exists multiple records.*/
        find first tBankState where tBankState.tc_Rowid = t_sBankState.tc_Rowid no-error.
        <M-96 run GetBankStateID
           (input  tBankState.Company_ID (iiCompanyID), 
            input  tBankState.tcGLCode (icGLCode), 
            input  tBankState.BankStateYear (iiBankStateYear), 
            input  tBankState.BankStateNumber (icBankStateNumber), 
            output viBankState_ID (oiBankStateID), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry> 

        if viBankState_ID <> 0 /* one or many */
        then do:
            <M-86 run GetNewBankStateNumber
               (input  t_sBankState.Company_ID (iiCompanyID), 
                input  ? (iiBankGLID), 
                input  t_sBankState.tcGLCode (icBankGLCode), 
                input  t_sBankState.BankStateYear (iiBankStateYear), 
                output t_sBankState.BankStateNumber (ocNewBankStateNumber), 
                output viFcReturnSuper (oiReturnStatus)) in BBankEntry>

            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
            then assign oiReturnStatus = viFcReturnSuper.    

            assign oiReturnStatus = (if oiReturnStatus < 0 then oiReturnStatus else +1)   /* warning */
                   vcMessage      = trim(substitute(#T-40'The bank state number already exists. A new number (&1) has been determined and saved.':200(63821)T-40#, t_sBankState.BankStateNumber)).
            <M-56 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tBankState.BankStateNumber':U (icFieldName), 
                input  t_sBankState.BankStateNumber (icFieldValue), 
                input  'W' (icType), 
                input  3 (iiSeverity), 
                input  t_sBankState.tc_Rowid (icRowid), 
                input  'QadFin-536314':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
        end.
    end. /* for each t_sbankstate */
    
    for each t_sBankState     where
        t_sBankState.tc_Status <> "D":U,
    each t_sBankStateLine where
         t_sBankStateLine.tc_ParentRowid = t_sBankState.tc_Rowid and
         t_sBankStateLine.tc_Status <> "D":U,
    each t_sBankStateAlloc where
         t_sBankStateAlloc.tc_ParentRowid     = t_sBankStateLine.tc_Rowid        and
         (t_sBankStateAlloc.tc_Status          = "N":U or
          t_sBankStateAlloc.tc_Status          = "C":U)                        and
         ((t_sBankStateAlloc.CInvoice_ID        <> 0    and
           t_sBankStateAlloc.CInvoice_ID        <> ?)                        or
          t_sBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-NCINV} or
          (t_sBankStateAlloc.DInvoice_ID      <> 0 and
           t_sBankStateAlloc.DInvoice_ID      <> ?)                          or
          t_sBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-NDINV} or
          t_sBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-DEDUCTIONINV} or
          t_sBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-CCOLL} or
          t_sBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-DCOLL}):                
        
        if vlDomainIsStatutory = false
        then assign t_sBankStateAlloc.BankStateAllocCCRate = t_sBankStateAlloc.BankStateAllocBankRate
                    t_sBankStateAlloc.BankStateAllocCCScale= t_sBankStateAlloc.BankStateAllocBankRteScale.
        else do:
            if vcCompanyCC = t_sBankStateAlloc.tcDocCurrencyCode            
            then assign t_sBankStateAlloc.tdDocCCExchangeRate      = 1
                        t_sBankStateAlloc.tdDocCCExchangeRateScale = 1.
                                
            if vcCompanyCC = t_sBankState.tcCurrencyCode
            then assign t_sBankStateAlloc.BankStateAllocCCRate     = 1
                        t_sBankStateAlloc.BankStateAllocCCScale    = 1.                    
            else do:
                <M-49 run GetExchangeRate
                   (input  t_sBankState.Company_ID (iiCompanyID), 
                    input  ? (iiFromCurrencyID), 
                    input  t_sBankState.tcCurrencyCode (icFromCurrencyCode), 
                    input  viCompanyCCId (iiToCurrencyID), 
                    input  ? (icToCurrencyCode), 
                    input  ? (iiExchangeRateTypeID), 
                    input  {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode), 
                    input  t_sBankStateLine.BankStateLineValueDate (itValidityDate), 
                    output vdCCExchangeRate (odExchangeRate), 
                    output vdCCExchangeRateScale (odExchangeScaleFactor), 
                    output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                 
               if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
               then assign oiReturnStatus = viFcReturnSuper.
               if viFcReturnSuper < 0
               then return.
    
               assign t_sBankStateAlloc.BankStateAllocCCRate  = vdCCExchangeRate
                      t_sBankStateAlloc.BankStateAllocCCScale = vdCCExchangeRateSCale.    
            end.
        end.
                                                                                      
        if t_sBankStateAlloc.BankStateAllocType <> {&BANKSTATEALLOCTYPE-CCOLL} and
           t_sBankStateAlloc.BankStateAllocType <> {&BANKSTATEALLOCTYPE-DCOLL}            
        then assign t_sBankStateAlloc.tdBankStateAllocBankAmountCC = if vlDomainIsStatutory
                                                                    then <M-77 RoundAmount
                                                                            (input  t_sBankStateAlloc.BankStateAllocBankAmountTC * t_sBankStateAlloc.BankStateAllocCCRate * t_sBankStateAlloc.BankStateAllocCCScale (idUnroundedAmount), 
                                                                             input  viCompanyCCId (iiCurrencyID), 
                                                                             input  vcCompanyCC (icCurrencyCode)) in BBankEntry>
                                                                    else t_sBankStateAlloc.BankStateAllocBankAmountLC
                    t_sBankStateAlloc.tdBankStateAllocBankDiscCC  = if vlDomainIsStatutory
                                                                    then <M-30 RoundAmount
                                                                            (input  t_sBankStateAlloc.BankStateAllocBankDiscTC * t_sBankStateAlloc.BankStateAllocCCRate * t_sBankStateAlloc.BankStateAllocCCScale (idUnroundedAmount), 
                                                                             input  viCompanyCCId (iiCurrencyID), 
                                                                             input  vcCompanyCC (icCurrencyCode)) in BBankEntry>
                                                                    else t_sBankStateAlloc.BankStateAllocBankDiscLC
                    t_sBankStateAlloc.BankStateAllocWHTAmtCC      = if vlDomainIsStatutory
                                                                    then <M-69 RoundAmount
                                                                            (input  t_sBankStateAlloc.BankStateAllocWHTAmtTC * t_sBankStateAlloc.BankStateAllocWHTCCRate * t_sBankStateAlloc.BankStateAllocWHTCCScale (idUnroundedAmount), 
                                                                             input  viCompanyCCId (iiCurrencyID), 
                                                                             input  vcCompanyCC (icCurrencyCode)) in BBankEntry>
                                                                    else t_sBankStateAlloc.BankStateAllocWHTAmtLC
                    vdBankStateAllocPaidAmountTC                  = t_sBankStateAlloc.BankStateAllocBankAmountTC - t_sBankStateAlloc.tdBankStateAllocBankWhtAmtTC                    
                    vdBankStateAllocPaidAmountLC                  = <M-23 RoundAmount
                                                                       (input  vdBankStateAllocPaidAmountTC * t_sBankStateAlloc.BankStateAllocBankRate * t_sBankStateAlloc.BankStateAllocBankRteScale (idUnroundedAmount), 
                                                                        input  viCompanyLCId (iiCurrencyID), 
                                                                        input  vcCompanyLC (icCurrencyCode)) in BBankEntry>
                    vdBankStateAllocPaidAmountCC                  = if vlDomainIsStatutory
                                                                    then <M-70 RoundAmount
                                                                            (input  vdBankStateAllocPaidAmountTC * t_sBankStateAlloc.BankStateAllocCCRate * t_sBankStateAlloc.BankStateAllocCCScale (idUnroundedAmount), 
                                                                             input  viCompanyCCId (iiCurrencyID), 
                                                                             input  vcCompanyCC (icCurrencyCode)) in BBankEntry>                                                                             
                                                                    else vdBankStateAllocPaidAmountLC.
                                      
        if (t_sBankStateAlloc.CInvoice_ID <> 0 and
            t_sBankStateAlloc.CInvoice_ID <> ?)    or
           (t_sBankStateAlloc.DInvoice_ID <> 0 and
            t_sBankStateAlloc.DInvoice_ID <> ?)    or
            t_sBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-NCINV} or
            t_SBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-NDINV} or
            t_SBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-DEDUCTIONINV}
        then do:
            if t_sBankStateAlloc.Company_ID = viCompanyId and
               t_sBankStateAlloc.BankStateAllocType <> {&BANKSTATEALLOCTYPE-NCINV} and
               t_SBankStateAlloc.BankStateAllocType <> {&BANKSTATEALLOCTYPE-NDINV} and
               t_SBankStateAlloc.BankStateAllocType <> {&BANKSTATEALLOCTYPE-DEDUCTIONINV}
            then do:
                /* Base Currency */                
                assign vdBankStateAllocAmountLC = <M-1 RoundAmount
                                                     (input  (t_sBankStateAlloc.BankStateAllocAmountTC - t_sBankStateAlloc.BankStateAllocWHTAmtTC) * t_sBankStateAlloc.tdDocExchangeRate * t_sBankStateAlloc.tdDocExchangeRateScale (idUnroundedAmount), 
                                                      input  viCompanyLCId (iiCurrencyID), 
                                                      input  vcCompanyLC (icCurrencyCode)) in BBankEntry>.
                <M-20 run GetGLForCurrencyReferenceLC
                   (input  t_sBankStateAlloc.tcAllocAmountCrDt (icAllocationCrDt), 
                    input  vdBankStateAllocAmountLC (idAllocationAmountLCForDocCurr), 
                    input  vdBankStateAllocPaidAmountLC (idAllocationAmountLCForBankCurr), 
                    output t_sBankStateAlloc.tcCurrencyDifferenceGLCode (ocGLCode), 
                    input  viCompanyId (iiCompanyId), 
                    output t_sBankStateAlloc.BankStateAllocDifferenceLC (odBankStateAllocDifferenceLC), 
                    output t_sBankStateAlloc.tcCurrDifferenceCrDt (ocCurrDifferenceCrDt), 
                    output viFcReturnSuper (oiReturnStatus)) in BBankEntry>             
            
                /* Statutory Currency */
                if vlDomainIsStatutory = false
                then assign t_sBankStateAlloc.tcCCCurrencyDifferenceGLCode = t_sBankStateAlloc.tcCurrencyDifferenceGLCode
                            t_sBankStateAlloc.BankStateAllocDifferenceCC   = t_sBankStateAlloc.BankStateAllocDifferenceLC
                            t_sBankStateAlloc.tcCCCurrDifferenceCrDt       = t_sBankStateAlloc.tcCurrDifferenceCrDt.
                else do:
                    assign vdBankStateAllocAmountCC = <M-32 RoundAmount
                                                         (input  (t_sBankStateAlloc.BankStateAllocAmountTC - t_sBankStateAlloc.BankStateAllocWHTAmtTC) * t_sBankStateAlloc.tdDocCCExchangeRate * t_sBankStateAlloc.tdDocCCExchangeRateScale (idUnroundedAmount), 
                                                          input  viCompanyCCId (iiCurrencyID), 
                                                          input  vcCompanyCC (icCurrencyCode)) in BBankEntry>.
                    <M-10 run GetGLForCurrencyReferenceLC
                       (input  t_sBankStateAlloc.tcAllocAmountCrDt (icAllocationCrDt), 
                        input  vdBankStateAllocAmountCC (idAllocationAmountLCForDocCurr), 
                        input  vdBankStateAllocPaidAmountCC (idAllocationAmountLCForBankCurr), 
                        output t_sBankStateAlloc.tcCCCurrencyDifferenceGLCode (ocGLCode), 
                        input  viCompanyId (iiCompanyId), 
                        output t_sBankStateAlloc.BankStateAllocDifferenceCC (odBankStateAllocDifferenceLC), 
                        output t_sBankStateAlloc.tcCCCurrDifferenceCrDt (ocCurrDifferenceCrDt), 
                        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>                    
                end.                        
            end.
            else do:
                if not vlDomainIsStatutory
                then do:
                    /* MIZ FIN-2314 Get CC Exchange rate from invoice itself */
                    assign vdCCExchangeRate      = t_sBankStateAlloc.tdDocExchangeRate
                           vdCCExchangeRateScale = t_sBankStateAlloc.tdDocExchangeRateScale.
                end.
                else do:
                     <M-47 run GetExchangeRate
                        (input  t_sBankState.Company_ID (iiCompanyID), 
                         input  ? (iiFromCurrencyID), 
                         input  t_sBankStateAlloc.tcDocCurrencyCode (icFromCurrencyCode), 
                         input  viCompanyCCId (iiToCurrencyID), 
                         input  ? (icToCurrencyCode), 
                         input  ? (iiExchangeRateTypeID), 
                         input  {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode), 
                         input  t_sBankStateAlloc.ttDocInvDate (itValidityDate), 
                         output vdCCExchangeRate (odExchangeRate), 
                         output vdCCExchangeRateScale (odExchangeScaleFactor), 
                         output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                    
                    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
                    then assign oiReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0
                    then return.
                end.
                
                /* first subtract the wht from it, to see if you have a difference */
                assign vdBankStateAllocAmountCC = t_sBankStateAlloc.BankStateAllocAmountTC - t_sBankStateAlloc.tdBankStateAllocBankWhtAmtTC
                       vdBankStateAllocAmountCC = <M-98 RoundAmount
                                                     (input  vdBankStateAllocAmountCC * vdCCExchangeRate * vdCCExchangeRateScale (idUnroundedAmount), 
                                                      input  viCompanyCCId (iiCurrencyID), 
                                                      input  vcCompanyCC (icCurrencyCode)) in BBankEntry>.
                       
                <M-93 run GetGLForCurrencyReferenceLC
                   (input  t_sBankStateAlloc.tcAllocAmountCrDt (icAllocationCrDt), 
                    input  vdBankStateAllocAmountCC (idAllocationAmountLCForDocCurr), 
                    input  vdBankStateAllocPaidAmountCC (idAllocationAmountLCForBankCurr), 
                    output t_sBankStateAlloc.tcCCCurrencyDifferenceGLCode (ocGLCode), 
                    input  viCompanyId (iiCompanyId), 
                    output t_sBankStateAlloc.BankStateAllocDifferenceCC (odBankStateAllocDifferenceLC), 
                    output t_sBankStateAlloc.tcCCCurrDifferenceCrDt (ocCurrDifferenceCrDt), 
                    output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
            end.
           
        end.
        if t_sBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-CCOLL} or
           t_sBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-DCOLL}
        then do:
            for each t_sBankStateAllocColl where
                     t_sBankStateAllocColl.tc_ParentRowid  = t_sBankStateAlloc.tc_Rowid and
                     t_sBankStateAllocColl.tlDocIsBounced <> true:
                if vcCompanyCC = t_sBankStateAllocColl.tcDocCurrencyCode
                then assign t_sBankStateAllocColl.BankStateAllocCollCCRate = 1
                            t_sBankStateAllocColl.BankStateAllocCollCCScale= 1.
                else if vlDomainIsStatutory = false
                then assign t_sBankStateAllocColl.BankStateAllocCollCCRate= t_sBankStateAlloc.BankStateAllocBankRate
                            t_sBankStateAllocColl.BankStateAllocCollCCScale= t_sBankStateAlloc.BankStateAllocBankRteScale.
                else if vcCompanyCC = t_sBankState.tcCurrencyCode
                then assign t_sBankStateAllocColl.BankStateAllocCollCCRate = 1
                            t_sBankStateAllocColl.BankStateAllocCollCCScale= 1.                               
                else do:
                     <M-38 run GetExchangeRate
                        (input  t_sBankState.Company_ID (iiCompanyID), 
                         input  ? (iiFromCurrencyID), 
                         input  t_sBankStateAllocColl.tcDocCurrencyCode (icFromCurrencyCode), 
                         input  viCompanyCCId (iiToCurrencyID), 
                         input  ? (icToCurrencyCode), 
                         input  ? (iiExchangeRateTypeID), 
                         input  {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode), 
                         input  t_sBankStateLine.BankStateLineValueDate (itValidityDate), 
                         output vdCCExchangeRate (odExchangeRate), 
                         output vdCCExchangeRateScale (odExchangeScaleFactor), 
                         output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
                    then assign oiReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0
                    then return.
                    
                    assign t_sBankStateAllocColl.BankStateAllocCollCCRate = vdCCExchangeRate
                           t_sBankStateAllocColl.BankStateAllocCollCCScale= vdCCExchangeRateScale.
                end.
                
                if vlDomainIsStatutory 
                then do:
                    if vcCompanyCC = t_sBankState.tcCurrencyCode
                    then
                        vdBankCCAmount = <M-34 RoundAmount
                                            (input  t_sBankStateAllocColl.BankStateAllocCollBankAmTC * t_sBankStateAllocColl.BankStateAllocCollCCRate * t_sBankStateAllocColl.BankStateAllocCollCCScale (idUnroundedAmount), 
                                             input  viCompanyCCId (iiCurrencyID), 
                                             input  vcCompanyCC (icCurrencyCode)) in BBankEntry>.
                    else
                        vdBankCCAmount = <M-15 RoundAmount
                                            (input  t_sBankStateAllocColl.tdDocAmount * t_sBankStateAllocColl.BankStateAllocCollCCRate * t_sBankStateAllocColl.BankStateAllocCollCCScale (idUnroundedAmount), 
                                             input  viCompanyCCId (iiCurrencyID), 
                                             input  vcCompanyCC (icCurrencyCode)) in BBankEntry> .
                end.                

                assign vdBankStateAllocCollAmtCC    = /*if vlDomainIsStatutory 
                                                      then */
                                                       <M-45 RoundAmount
                                                          (input  t_sBankStateAllocColl.tdDocAmount * t_sBankStateAllocColl.tdDocCCExchangeRate * t_sBankStateAllocColl.tdDocCCExchangeRateScale (idUnroundedAmount), 
                                                           input  viCompanyCCId (iiCurrencyID), 
                                                           input  vcCompanyCC (icCurrencyCode)) in BBankEntry>
                                                     /* else t_sBankStateAllocColl.BankStateAllocCollBankAmLC     */
                       vdBankStateAllocCollBankAmtCC = if vlDomainIsStatutory 
                                                then vdBankCCAmount                                                    
                                                else t_sBankStateAllocColl.BankStateAllocCollBankAmLC
                       t_sBankStateAlloc.tdBankStateAllocBankAmountCC = t_sBankStateAlloc.tdBankStateAllocBankAmountCC + vdBankStateAllocCollBankAmtCC.
                       
                        
                <M-5 run GetGLForCurrencyReferenceLC
                   (input  t_sBankStateAlloc.tcAllocAmountCrDt (icAllocationCrDt), 
                    input  vdBankStateAllocCollAmtCC (idAllocationAmountLCForDocCurr), 
                    input  vdBankStateAllocCollBankAmtCC (idAllocationAmountLCForBankCurr), 
                    output t_sBankStateAllocColl.tcCCCurrencyDifferenceGLCode (ocGLCode), 
                    input  viCompanyId (iiCompanyId), 
                    output t_sBankStateAllocColl.BankStateAllocCollDiffCC (odBankStateAllocDifferenceLC), 
                    output t_sBankStateAllocColl.tcCCCurrDifferenceCrDt (ocCurrDifferenceCrDt), 
                    output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                
            end.
              
        end.
    end. 
    
    
    
    
   /* ================================================================================ */
   /* Validate GL Period and Approved for Supplier/Customer Invoice Allocation         */
   /* ================================================================================ */

    
    for each t_sBankState     where 
             t_sBankState.tc_Status <> "D":U, 
        each t_sBankStateLine where 
             t_sBankStateLine.tc_ParentRowid = t_sBankState.tc_Rowid and 
            t_sBankStateLine.tc_Status <> "D":U: 
                     
           if t_sBankStateLine.BankStateLineValueDate <> ?
            then do:
                 <Q-89 run PeriodByPeriodStartEndDate (all) (Read) (NoCache)
                    (input viCompanyId, (CompanyId)
                     input t_sBankStateLine.BankStateLineValueDate, (Date)
                     input ?, (PeriodId)
                     input ?, (PeriodYear)
                     input ?, (PeriodPeriod)
                     output dataset tqPeriodByPeriodStartEndDate) in BPeriod>
                 
                 find first tqPeriodByPeriodStartEndDate where
                     tqPeriodByPeriodStartEndDate.ttPeriodStartDate <= t_sBankStateLine.BankStateLineValueDate and
                     tqPeriodByPeriodStartEndDate.ttPeriodEndDate   >= t_sBankStateLine.BankStateLineValueDate
                     no-error.
                      
                /* Period must be open */
                if not available tqPeriodByPeriodStartEndDate
                then do:
                       assign vcMessage =  trim(#T-71'Period does not exist for date selected':255(834087923)T-71#)
                              oiReturnStatus = -1. 
                    <M-27 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  't_sBankStateLine.BankStateLineValueDate':U (icFieldName), 
                        input  t_sBankStateLine.BankStateLineValueDate (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  t_sBankStateLine.tc_RowID (icRowid), 
                        input  'qadfin-698909':U (icFcMsgNumber), 
                        input  '':U (icFcExplanation), 
                        input  '':U (icFcIdentification), 
                        input  '':U (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>                
                end.
                else if tqPeriodByPeriodStartEndDate.tcPeriodStatus <> {&PERIODSTATUS-OPEN}
                then do: 
                     assign vcMessage = trim(#T-88'Period is not open for date selected':255(119422205)T-88#)
                            oiReturnStatus = -1 . 
                    <M-78 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  't_sBankStateLine.BankStateLineValueDate':U (icFieldName), 
                        input  t_sBankStateLine.BankStateLineValueDate (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  t_sBankStateLine.tc_RowID (icRowid), 
                        input  'qadfin-934808':U (icFcMsgNumber), 
                        input  '':U (icFcExplanation), 
                        input  '':U (icFcIdentification), 
                        input  '':U (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                     
                end.
            end. /*if t_sBankStateLine.BankStateLineValueDate <> ? */
     
           find first t_sBankStateAlloc where 
                 t_sBankStateAlloc.tc_ParentRowid       = t_sBankStateLine.tc_Rowid        and 
                 (t_sBankStateAlloc.tc_Status           = "N":U or  t_sBankStateAlloc.tc_Status   = "C":U) and 
                 ((t_sBankStateAlloc.CInvoice_ID        <> 0    and t_sBankStateAlloc.CInvoice_ID <> ?) or 
                   t_sBankStateAlloc.BankStateAllocType  = {&BANKSTATEALLOCTYPE-NCINV}) 
           no-error. 
           
           if not available t_sBankStateAlloc 
           then do:
                find first t_sBankStateAlloc where
                     t_sBankStateAlloc.tc_ParentRowid       = t_sBankStateLine.tc_Rowid                        and
                     (t_sBankStateAlloc.tc_Status           = "N":U or  t_sBankStateAlloc.tc_Status   = "C":U) and
                     ((t_sBankStateAlloc.DInvoice_ID        <> 0    and t_sBankStateAlloc.DInvoice_ID <> ?)    or
                       t_sBankStateAlloc.BankStateAllocType  = {&BANKSTATEALLOCTYPE-NDINV} or 
                       t_sBankStateAlloc.BankStateAllocType  = {&BANKSTATEALLOCTYPE-DEDUCTIONINV})
                no-error.
           end.    

           if available t_sBankStateAlloc 
           then do: 
               <Q-66 run ReasonByIdCode (all) (Read) (NoCache)
                  (input ?, (ReasonId)
                   input t_sBankStateAlloc.tcReasonCode, (ReasonCode)
                   output dataset tqReasonByIdCode) in BReason>
               
               find first tqReasonByIdCode where
                          tqReasonByIdCode.tcReasonCode = t_sBankStateAlloc.tcReasonCode no-error.

               if available tqReasonByIdCode
               then do:
                   if not tqReasonByIdCode.tlReasonIsInvoiceApproved
                   then do:
                       /* Invoice is not approved give warning  */
                       vcMessage = trim(substitute(#T-76'The Invoice  &1  that you have selected for allocation has a status  &2. This indicates the Invoice is not approved':255(127705806)T-76#, t_sBankStateAlloc.tcDocNumberReference, t_sBankStateAlloc.tcReasonCode)).
                       <M-57 run SetMessage
                          (input  vcMessage (icMessage), 
                           input  '':U (icArguments), 
                           input  '':U (icFieldName), 
                           input  t_sBankStateAlloc.tcDocNumberReference (icFieldValue), 
                           input  'W':U (icType), 
                           input  3 (iiSeverity), 
                           input  t_sBankStateAlloc.tc_RowID (icRowid), 
                           input  'qadfin-673968':U (icFcMsgNumber), 
                           input  '':U (icFcExplanation), 
                           input  '':U (icFcIdentification), 
                           input  '':U (icFcContext), 
                           output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                       oiReturnStatus = +1.
                   end. /* if not tqReasonByIdCode.tlReasonIsInvoiceApproved */
               end. /* if available tqReasonByIdCode */

                    <Q-55 run PeriodByStartEndDate (all) (Read) (NoCache)
                       (input t_sBankStateLine.Company_ID, (CompanyId)
                        input t_sBankStateLine.BankStateLinePostingDate, (Date)
                        output dataset tqPeriodByStartEndDate) in BPeriod>
     
                  find first tqPeriodByStartEndDate where 
                    tqPeriodByStartEndDate.ttPeriodStartDate         <= t_sBankStateLine.BankStateLinePostingDate and 
                    tqPeriodByStartEndDate.ttPeriodEndDate           >= t_sBankStateLine.BankStateLinePostingDate and 
                    tqPeriodByStartEndDate.tcPeriodStatus             = {&PERIODSTATUS-OPEN}                  /*  and 
                    tqPeriodByStartEndDate.tlPeriodIsPostingPurchAllow = true                                   */
                no-error. 
                if available tqPeriodByStartEndDate 
                then do: 
                      if((t_sBankStateAlloc.CInvoice_ID        <> 0    and t_sBankStateAlloc.CInvoice_ID <> ?) or
                         t_sBankStateAlloc.BankStateAllocType  = {&BANKSTATEALLOCTYPE-NCINV})                 and
                         tqPeriodByStartEndDate.tlPeriodIsPostingPurchAllow = false
                      then do:  
                          <M-68 run SetMessage
                             (input  trim(#T-58'This GL period is closed for purchase transactions.':250(16607)T-58#) (icMessage), 
                              input  '':U (icArguments), 
                              input  '':U (icFieldName), 
                              input  t_sBankStateLine.BankStateLinePostingDate (icFieldValue), 
                              input  'E':U (icType), 
                              input  3 (iiSeverity), 
                              input  t_sBankStateLine.tc_RowID (icRowid), 
                              input  'qadfin-819792':U (icFcMsgNumber), 
                              input  '':U (icFcExplanation), 
                              input  '':U (icFcIdentification), 
                              input  '':U (icFcContext), 
                              output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                           assign oiReturnStatus = -1. 
                        end.

                      if((t_sBankStateAlloc.DInvoice_ID        <> 0    and t_sBankStateAlloc.DInvoice_ID <> ?) or
                          t_sBankStateAlloc.BankStateAllocType  = {&BANKSTATEALLOCTYPE-NDINV} or 
                          t_sBankStateAlloc.BankStateAllocType  = {&BANKSTATEALLOCTYPE-DEDUCTIONINV})                  and
                          tqPeriodByStartEndDate.tlPeriodIsPostingSalesAllow = false
                      then do:   
                         <M-87 run SetMessage
                            (input  trim(#T-67'This GL period is closed for sales transactions.':250(16608)T-67#) (icMessage), 
                             input  '':U (icArguments), 
                             input  '':U (icFieldName), 
                             input  t_sBankStateLine.BankStateLinePostingDate (icFieldValue), 
                             input  'E':U (icType), 
                             input  3 (iiSeverity), 
                             input  t_sBankStateLine.tc_RowID (icRowid), 
                             input  'qadfin-75787':U (icFcMsgNumber), 
                             input  '':U (icFcExplanation), 
                             input  '':U (icFcIdentification), 
                             input  '':U (icFcContext), 
                             output oiReturnStatus (oiReturnStatus)) in BBankEntry>
                             assign oiReturnStatus = -1.
                        end.                   
    
               end. /* if available tqPeriodByStartEndDate */ 
     
            end. /* if available t_sBankStateAlloc */

    end. /* for each t_sBankState  */