project QadFinancials > class BBankEntry > 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/bbankentry.p)

/* define the buffers yourself because they have to be on the t_s table iso the t table */
define buffer bBankStateLine  for t_sBankStateLine.
define buffer bBankStateAlloc for t_sBankStateAlloc.

<M-27 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper < 0 or
   oiReturnStatus  = 0
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0
then return.

<M-55 run ValidateComponentPre  (output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.    
if oiReturnStatus < 0 then return. 

/* =================================== */
/* give some db fields the right value */
/* =================================== */
<M-16 run ValidateComponentPreUpdateBankStateAlloc  (output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.    

/* BTS 3841 - JLA */
/* Removed -Debtor Collection are not allowed- validation */
/* BTS 3841 - JLA */

/* ============================================================================= */
/* Raise Error if Bank Account Number not found during Banking Entry create      */
/* ============================================================================= */

for each t_sBankState where 
         t_sBankState.tc_Status <> "D":U :
    if (t_sBankState.tcGLBankNumber = "":U  or
        t_sBankState.tcGLBankNumber = "?":U or
        t_sBankState.tcGLBankNumber = ?)    and
        t_sBankState.BankStateTransactionType = {&BANKSTATETRANSTYPE-BANK}  
    then do:    
        assign oiReturnStatus = -1
               vcMessage = trim(substitute(#T-37'This entity has not been specified in the GL Account':255(733755098)T-37#,t_sBankState.tcGLCode)).

        <M-38 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  't_sBankState.tcGLCode' (icFieldName), 
            input  t_sBankState.tcGLCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sBankState.tc_Rowid (icRowid), 
            input  'QadFin-9761':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
    end. /* IF (t_sBankState.tcGLBankNumber = "":U ... */
end. /* for each t_sBankState */  


/* ======================================================================= */
/* Deletion & Modification on Allocated Bank-States is not allowed         */
/* Deletion & Modification on Allocated Bank-State-Lines is not allowed    */
/* ======================================================================= */
for each t_sBankState where 
         t_sBankState.tc_Status = "D":U :
    find t_iBankState where 
         t_iBankState.tc_Rowid        = t_sBankState.tc_Rowid and 
         (t_iBankState.BankStateStatus = {&BANKSTATESTATUS-ALLOC} or
          t_iBankState.BankStateStatus = {&BANKSTATESTATUS-PARTALLOC})
         no-lock no-error.
    if available t_iBankState
    then do :
        assign oiReturnStatus = -1
               vcMessage      = trim(substitute(#T-33'A fully or partially allocated bank statement (&1) cannot be removed.':200(71300)T-33#,t_sBankState.BankStateNumber)).
        <M-34 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  't_sBankState.BankStateNumber':U (icFieldName), 
            input  t_sBankState.BankStateNumber (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sBankState.tc_Rowid (icRowid), 
            input  'QadFin-8678':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
    end.
end. /* for each t_sBankState */  


/* validation for  for change in year,period,date and status is not unallocated*/
for each t_sBankState where 
         t_sBankState.tc_Status = "C":U :
    find t_iBankState where 
         (t_iBankState.tc_Rowid        = t_sBankState.tc_Rowid                   and 
          t_iBankState.BankStateStatus <> {&BANKSTATESTATUS-UNALLOC})            and
          (t_iBankState.Period_ID <> t_sBankState.Period_ID                      or
          t_iBankState.BankStatePostingDate <> t_sBankState.BankStatePostingDate or
          t_iBankState.BankStateYear <> t_sBankState.BankStateYear)
         no-lock no-error.
    if available t_iBankState
    then do :
        assign oiReturnStatus = -1
               vcMessage      = trim(substitute(#T-35'Year,Period or Posting Date can only be changed for unallocated bank statements':200(733744315)T-35#)).
               
        <M-36 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sBankState.tc_Rowid (icRowid), 
            input  'QadFin-9459':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
         
    end.     
end.         



for each t_sBankStateLine where 
         t_sBankStateLine.tc_Status = "C":U or 
         t_sBankStateLine.tc_Status = "D":U :
    find t_iBankStateLine where 
         t_iBankStateLine.tc_Rowid            = t_sBankStateLine.tc_Rowid and 
         t_iBankStateLine.BankStateLineStatus = {&BANKSTATELINESTATUS-ALLOC}
         no-lock no-error.
    if available t_iBankStateLine
    then do :
        assign oiReturnStatus = -1
               vcMessage      = trim(substitute(#T-18'You cannot update or remove an allocated bank statement line (&1).':200(332)T-18#,t_sBankStateLine.BankStateLineNumber)).
        <M-2 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tBankStateLine.BankStateLineNumber':U (icFieldName), 
            input  t_sBankStateLine.BankStateLineNumber (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sBankStateLine.tc_Rowid (icRowid), 
            input  'QADFIN-655':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
    end. /* if available t_iBankStateLine */
end. /* for each t_sBankStateLine where */
if oiReturnStatus < 0 
then return.
    
/* ====================================================== */
/* only one prepay record allowed for each statement line */
/* ====================================================== */
for each t_sBankStateLine where
        (t_sBankStateLine.tc_status = "N":U or
         t_sBankStateLine.tc_status = "C":U) and
        (t_sBankStateLine.BankStateLineStatus = {&BANKSTATESTATUS-PARTALLOC} or
         t_sBankStateLine.BankStateLineStatus = {&BANKSTATESTATUS-ALLOC}) :
    find first t_sBankStateAlloc where
               t_sBankStateAlloc.tc_ParentRowid     = t_sBankStateLine.tc_Rowid and
               t_sBankStateAlloc.tc_Status          <> "D":U and
              (t_sBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-NCINV} or
               t_sBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-NDINV} or
               t_sBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-NEINV})
               no-error.
    if available t_sBankStateAlloc
    then do:
        /* only check the instance, because when it is saved, the status is changed to cinv, dinv or einv */
        find next t_sBankStateAlloc where
                   t_sBankStateAlloc.tc_ParentRowid      = t_sBankStateLine.tc_Rowid and
                   t_sBankStateAlloc.tc_Status          <> "D":U and
                  (t_sBankStateAlloc.BankStateAllocType  = {&BANKSTATEALLOCTYPE-NCINV} or
                   t_sBankStateAlloc.BankStateAllocType  = {&BANKSTATEALLOCTYPE-NDINV} or
                   t_sBankStateAlloc.BankStateAllocType  = {&BANKSTATEALLOCTYPE-NEINV})
                   no-error.
        if available t_sBankStateAlloc
        then do:
            assign vcMessage      = trim(substitute(#T-19'Only one prepayment record is allowed for each statement line.':150(333)T-19#,string(t_sBankStateLine.BankStateLineNumber)))
                   oiReturnStatus = -1.
             <M-3 run SetMessage
                (input  vcMessage (icMessage), 
                 input  '':U (icArguments), 
                 input  'tBankStateLine.BankStateLineNumber':U (icFieldName), 
                 input  string(t_sBankStateLine.BankStateLineNumber) (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  t_sBankStateLine.tc_Rowid (icRowid), 
                 input  'QADFIN-763':U (icFcMsgNumber), 
                 input  '' (icFcExplanation), 
                 input  '' (icFcIdentification), 
                 input  '' (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
        end.
    end.
end.

<Q-30 run JournalByJournalIDCodeType  (Start) in BJournal >
/* ====================================================== */
/* bank state lines with status PARTALLOC are not allowed */
/* ====================================================== */
for each t_sBankStateLine where
         t_sBankStateLine.BankStateLineStatus = {&BANKSTATELINESTATUS-PARTALLOC} and
        /* BTS 3841 - JLA */
        (t_sBankStateLine.tc_Status = "N":U  or 
         t_sBankStateLine.tc_Status = "C":U):
        /* BTS 3841 - JLA */
    <Q-28 run JournalByJournalIDCodeType (all) (Read) (NoCache)
       (input viCompanyId, (CompanyId)
        input ?, (JournalID)
        input t_sBankStateLine.tcPostingJournalCode, (JournalCode)
        input ?, (JournalTypeCode)
        output dataset tqJournalByJournalIDCodeType) in BJournal >
    find first tqJournalByJournalIDCodeType 
        where tqJournalByJournalIDCodeType.tcJournalCode = t_sBankStateLine.tcPostingJournalCode
        no-error.
    if available tqJournalByJournalIDCodeType 
    then do:
        if tqJournalByJournalIDCodeType.tcJournalTypeCode = {&JOURNALTYPE-BANKINGENTRY}
            then assign vcMessage = trim(substitute(#T-20'Bank statement lines (&2) with status '&1' are not allowed.':150(71005)T-20#,{&BANKSTATELINESTATUS-PARTALLOC-TR},string(t_sBankStateLine.BankStateLinePostingDate))).
        else if tqJournalByJournalIDCodeType.tcJournalTypeCode = {&JOURNALTYPE-CASHENTRY}
            then assign vcMessage = trim(substitute(#T-29'Petty cash lines (&2) with status '&1' are not allowed.':150(71006)T-29#,{&BANKSTATELINESTATUS-PARTALLOC-TR},string(t_sBankStateLine.BankStateLinePostingDate))).
    end. 

    assign oiReturnStatus = -1.
     <M-4 run SetMessage
        (input  vcMessage (icMessage), 
         input  '':U (icArguments), 
         input  'tBankStateLine.BankStateLineNumber':U (icFieldName), 
         input  string(t_sBankStateLine.BankStateLineNumber) (icFieldValue), 
         input  'E':U (icType), 
         input  3 (iiSeverity), 
         input  t_sBankStateLine.tc_Rowid (icRowid), 
         input  'QADFIN-853':U (icFcMsgNumber), 
         input  '' (icFcExplanation), 
         input  '' (icFcIdentification), 
         input  '' (icFcContext), 
         output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
end.
<Q-31 run JournalByJournalIDCodeType  (Stop) in BJournal >

/* modification of allocated and posted lines not allowed */
assign vlFound = false.
for each t_sBankState where
         t_sBankState.tc_Status = "C":U NO-LOCK,
    each t_sBankStateLine where
         t_sBankStateLine.tc_ParentRowid       = t_sBankState.tc_Rowid              and 
         t_sBankStateLine.BankStateLineStatus  = {&BANKSTATELINESTATUS-ALLOCPOST} no-lock:
    if t_sBankStateLine.tc_status = "C":U or  
       t_sBankStateLine.tc_status = "D":U
    then do:
        assign vlFound = true.
        leave.
    end.
    else if t_sBankStateLine.tc_status <> ? and t_sBankStateLine.tc_status <> "" and
        can-find(first t_sBankStateAlloc where 
                          t_sBankStateAlloc.tc_ParentRowid = t_sBankStateLine.tc_Rowid and
                         (t_sBankStateAlloc.tc_Status      = "C":U or
                          t_sBankStateAlloc.tc_Status      = "D":U) )
        then do:
            assign vlFound = true.
            leave.
        end.
end.
if vlFound
then do:
    assign vcMessage      = trim(substitute(#T-21'You cannot modify bank statement lines that have the status '&1'.':150(335)T-21#,{&BANKSTATELINESTATUS-ALLOCPOST-TR}))
           oiReturnStatus = -1.
    <M-7 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  'tBankStateLine.BankStateLineNumber':U (icFieldName), 
        input  string(t_sBankStateLine.BankStateLineNumber) (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  t_sBankStateLine.tc_Rowid (icRowid), 
        input  'QADFIN-1438':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
end.

if oiReturnStatus < 0
then return.

/* ====================================================================================================== */
/* BankStateAlloc.CompanyCode: functionaly speaking, this is a RKBF for field t_sBankStateAlloc.Company_ID. */
/* It was no use defining this using the std RKBF functionality because the company_ID does not get set   */
/* for other companies because the current CompanyID is passed as input parameter to the query.           */
/* Solution: write manualy the reuiqred code in method Calculate() and ValidateComponent() to convert the */
/* CompanyCode into the CompanyID and vice-versa.                                                         */
/* Updated Methods: CalculateAll & ValidateComponent                                                      */
/* ====================================================================================================== */
if can-find (first t_sBankStateAlloc)
then do :
    <Q-15 run CompanyPrim (all) (Read) (NoCache)
       (input ?, (LookupCompanyId)
        input ?, (CompanyCode)
        output dataset tqCompanyPrim) in BCompany >
    for each t_sBankStateAlloc where
             (t_sBankStateAlloc.tc_Status = "N":U or 
              t_sBankStateAlloc.tc_Status = "C":U) and 
             t_sBankStateAlloc.tcCompanyCode <> "":U and 
             t_sBankStateAlloc.tcCompanyCode <> ? :
        find tqCompanyPrim where
             tqCompanyPrim.tcCompanyCode = t_sBankStateAlloc.tcCompanyCode
             no-lock no-error.
        if available tqCompanyPrim
        then assign t_sBankStateAlloc.Company_ID = tqCompanyPrim.tiCompany_ID.
    end. /* for each t_sBankStateAlloc where */
end. /* if can-find (first t_sBankStateAlloc) */

/* ==================================================================================================== */
/* Fill up the main table ID field on the 3th and 4th level tables to improve performance on dataload   */
/* ==================================================================================================== */
for each t_sBankStateAlloc where
         t_sBankStateAlloc.tc_status <> "D":U,
    each t_sBankStateLine where
         t_sBankStateLine.tc_Rowid   = t_sBankStateAlloc.tc_ParentRowid and 
         t_sBankStateLine.tc_status <> "D":U,
    each t_sBankState where
         t_sBankState.tc_Rowid  = t_sBankStateLine.tc_ParentRowid and
         t_sBankState.tc_Status <> "D":U:
    
    if t_sBankStateAlloc.tc_status = "N":U or
       t_sBankStateAlloc.tc_status = "C":U
    then assign t_sBankStateAlloc.BankState_ID = t_sBankState.BankState_ID.

    for each t_sBankStateAllocColl where 
             t_sBankStateAllocColl.tc_ParentRowid = t_sBankStateAlloc.tc_Rowid and
            (t_sBankStateAllocColl.tc_Status  = "N":U or
             t_sBankStateAllocColl.tc_Status  = "C":U):
        assign t_sBankStateAllocColl.BankState_ID = t_sBankState.BankState_ID.
    end.

    for each t_sBankStateStageAlloc where 
             t_sBankStateStageAlloc.tc_ParentRowid = t_sBankStateAlloc.tc_Rowid and
            (t_sBankStateStageAlloc.tc_Status  = "N":U or
             t_sBankStateStageAlloc.tc_Status  = "C":U):
        assign t_sBankStateStageAlloc.BankState_ID = t_sBankState.BankState_ID.
    end.

end. /* for each t_sBankStateAlloc where */

/* validation check for exchange rate tolerance */
<M-63 run ValidateComponentPreExchRateTol  (output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper <> 0 and oiReturnStatus >= 0 
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.


<ANCESTOR-CODE>

/* check the retrun-status */
if oiReturnStatus < 0
then return.

/* Validation check for Banking Entry Posting Date against Payment Posting date */
<M-40 run ValidateComponentPost  (output viFcReturnSuper (oiReturnStatus)) in BBankEntry>

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