project QadFinancials > class BDPaymentSelection > 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/bdpaymentselection.p)

        
    
    <M-9 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
    if viFcReturnSuper < 0 or oiReturnStatus = 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 then return.
    
    /* ======================================================================================================================= */
    /* Backwards-compatibility: Make sure some new mandatory fields get a default value in case they are still unknown         */
    /* This is needed as older callers may still use and interface that does not hold these fields although they are mandatory */
    /* This is about these fields: tDPaySel.DPaySelStatus and tDPaySel.DPaySelIsDocPerDueDate                                  */
    /* ======================================================================================================================= */
    for each t_sDPaySel where
             t_sDPaySel.tc_Status = "N":U or 
             t_sDPaySel.tc_Status = "C":U  :
        if t_sDPaySel.DPaySelStatus = ?
        then assign t_sDPaySel.DPaySelStatus = {&DOCUMENTSTATUS-INIT}.
        if t_sDPaySel.DPaySelIsDocPerDueDate = ?
        then assign t_sDPaySel.DPaySelIsDocPerDueDate = false.    
    end. /* for each t_sDPaySel where */
    
    /* ======================================================================================================================= */
    /* Backwards-compatibility: Make sure some new mandatory fields get a default value in case they are still unknown         */
    /* This is needed as older callers may still use and interface that does not hold these fields although they are mandatory */
    /* This is about these fields: tDPaySel.DPaySelStatus and tDPaySel.DPaySelIsDocPerDueDate                                  */
    /* ======================================================================================================================= */
    for each t_sDPaySel where
             t_sDPaySel.tc_Status = "N":U or 
             t_sDPaySel.tc_Status = "C":U  :
        if t_sDPaySel.DPaySelStatus = ?
        then assign t_sDPaySel.DPaySelStatus = {&DOCUMENTSTATUS-INIT}.
        if t_sDPaySel.DPaySelIsDocPerDueDate = ?
        then assign t_sDPaySel.DPaySelIsDocPerDueDate = false.    
    end. /* for each t_sDPaySel where */
    
    /* ================================================================================== */
    /* Assign DPaySelID on DPaySelLineStg and on DPaySelPayRef to improve the performance */
    /* of dataload by using the OverridePrimary construction for reading the data from db */ 
    /* ================================================================================== */
    for each t_sDPaySel where 
             t_sDPaySel.tc_Status <> "D":U ,
        each t_sDPaySelLine where 
             t_sDPaySelLine.tc_ParentRowid = t_sDPaySel.tc_Rowid and 
             t_sDPaySelLine.tc_Status <> "D":U :
        for each t_sDPaySelLineStg where 
                 t_sDPaySelLineStg.tc_ParentRowid   = t_sDPaySelLine.tc_Rowid and  
                 t_sDPaySelLineStg.DPaySel_ID      <> t_sDPaySel.DPaySel_ID and 
                 (t_sDPaySelLineStg.tc_Status = "N":U or 
                  t_sDPaySelLineStg.tc_Status = "C":U) :
            assign t_sDPaySelLineStg.DPaySel_ID = t_sDPaySel.DPaySel_ID.
        end. /* for each t_sDPaySelLineStg where  */
        for each t_sDPaySelPayRef where 
                 t_sDPaySelPayRef.tc_ParentRowid   = t_sDPaySelLine.tc_Rowid and  
                 t_sDPaySelPayRef.DPaySel_ID      <> t_sDPaySel.DPaySel_ID and 
                 (t_sDPaySelPayRef.tc_Status = "N":U or 
                  t_sDPaySelPayRef.tc_Status = "C":U) :
            assign t_sDPaySelPayRef.DPaySel_ID = t_sDPaySel.DPaySel_ID.
        end. /* for each t_sDPaySelPayRef where  */
    end. /* for each t_sDPaySel */
    
    /* ================================== */
    /* Call submethod before ancestor-tag */
    /* ================================== */
    <M-60 run ValidateComponentPre  (output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
    if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0
    then return.
    



<ANCESTOR-CODE>


    
    
    for each t_sDPaySel where
             t_sDPaySel.tc_Status = "N":U:
    
        /* DPaySelCode */
        if t_sDPaySel.DPaySelCode = "":U or
           t_sDPaySel.DPaySelCode = ?
        then do:
            <M-50 run SetMessage
               (input  trim(#T-59'You must enter the customer payment selection code.':250(57366)T-59#) (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-845195':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
    
            assign oiReturnStatus = -1.        
        end. /*  if t_sDPaySel.DPaySelCode = "":U */
        else do:
            <Q-98 assign vlFcQueryRecordsAvailable = DPaySelPrim (NoCache)
               (input viCompanyId, (CompanyId)
                input ?, (DPaySelId)
                input t_sDPaySel.DPaySelCode, (DPaySelCode)) in BDPaymentSelection>
    
            if vlFcQueryRecordsAvailable <> false
            then do:
                assign vcMessage = trim(substitute(#T-7'A customer payment selection for code &1 already exists.':250(57365)T-7#, t_sDPaySel.DPaySelCode))
                       oiReturnStatus = -1.
                       
                <M-76 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'qadfin-458588':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
            end. /* if vlFcQueryRecordsAvailable <> false */
            else do:
                <Q-70 assign vlFcQueryRecordsAvailable = DDocumentByIncSelCode (NoCache)
                   (input viCompanyId, (CompanyId)
                    input t_sDPaySel.DPaySelCode, (DDocumentIncassoSelectCode)) in BDDocument>
    
                if vlFcQueryRecordsAvailable <> false
                then do:
                    assign vcMessage = trim(substitute(#T-69'A customer payment selection for code &1 already exists.':250(57365)T-69#, t_sDPaySel.DPaySelCode))
                           oiReturnStatus = -1.
    
                    <M-26 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  '':U (icRowid), 
                        input  'qadfin-352184':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
    
                    assign oiReturnStatus = -1.
                 end. /* if vlFcQueryRecordsAvailable <> false */            
                else
                if can-find(first bDPaySel where
                                  bDPaySel.DPaySelCode = tDPaySel.DPaySelCode and
                                  rowid(bDPaySel)      <> rowid(t_sDPaySel))
                then do:
                    assign vcMessage = trim(substitute(#T-67'A customer payment selection for code &1 already exists.':250(57365)T-67#, t_sDPaySel.DPaySelCode))
                           oiReturnStatus = -1.
                    <M-47 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  '':U (icRowid), 
                        input  'qadfin-721490':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>                
                end.            
            end. /*  else do: */
        end. /*  else do: */
    
        /* IncSelIsDocumentPerDueDate */
        if t_sDPaySel.DPaySelIsDocPerDueDate = ?
        then do:
             <M-81 run SetMessage
                (input  trim(#T-1'You must enter a valid value for the Payment per Due Date setting.':250(1643)T-1#) (icMessage), 
                 input  '':U (icArguments), 
                 input  '':U (icFieldName), 
                 input  '':U (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  '':U (icRowid), 
                 input  'qadfin-276322':U (icFcMsgNumber), 
                 input  '' (icFcExplanation), 
                 input  '' (icFcIdentification), 
                 input  '' (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
    
            assign oiReturnStatus = -1.
        end. /* if t_sDPaySel.DPaySelIsDocPerDueDate */
    
        /* IncSelDate */
        if t_sDPaySel.DPaySelDate            = ? and
           t_sDPaySel.DPaySelIsDocPerDueDate = false
        then do:
            <M-53 run SetMessage
               (input  trim(#T-8'You must enter the collection selection date.':250(1644)T-8#) (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-62032':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
    
            assign oiReturnStatus = -1.
        end. /*  if t_sDPaySel.DPaySelDate */
   
        /* At least one IncSelLine is needed - no longer valid as if lines are moved then it could be ok
        although perhaps this record should then be removed... 
        if not can-find(first tDIncSelLine where
                              tDIncSelLine.tc_ParentRowid = t_sDPaySel.tc_Rowid and
                              tDIncSelLine.tlIsSelected   = true)
        then do:
            <M-33 run SetMessage
               (input  trim(#T-43'The system cannot find lines for collection selection $1. The system cannot continue.':250(1647)T-43#) (icMessage), 
                input  t_sDPaySel.DPaySelCode (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-86539':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
    
            assign oiReturnStatus = -1.
        end.
     */
     
        /* Set status of modified payment selection codes */
        for each t_sDPaySelPayCode:
            find t_iDPaySelPayCode where t_iDPaySelPayCode.tc_rowid=t_sDPaySelPayCode.tc_rowid no-error.
            if(available(t_iDPaySelPayCode) and
                t_iDPaySelPayCode.tcPayFormatCode <> t_sDPaySelPayCode.tcPayFormatCode and
                (t_sDPaySelPayCode.tc_status='' or t_sDPaySelPayCode.tc_status=?)) then
                t_sDPaySelPayCode.tc_status='C':U.
        end. /* for each t_sPaySelPayCode */
     
        /* Check lines */
        for each tDIncSelLine where
                 tDIncSelLine.tc_ParentRowid = t_sDPaySel.tc_Rowid and
                 tDIncSelLine.tlIsSelected   = true:
            /* Invoice must be unchanged */
            <Q-40 run DInvoiceByPaymentInfo (all) (Read) (NoCache)
               (input ?, (CompanyId)
                input ?, (DInvoiceType)
                input ?, (DInvoiceIsOpen)
                input ?, (DInvoiceIsSelected)
                input ?, (BusinessRelationCode)
                input ?, (BusinessRelationIsInterco)
                input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
                input ?, (CountryCode)
                input ?, (PaymentGroupCode)
                input ?, (CurrencyCode)
                input ?, (DivisionCode)
                input tDIncSelLine.tiDInvoiceId, (DInvoiceId)
                output dataset tqDInvoiceByPaymentInfo) in BDInvoice>
    
            find first tqDInvoiceByPaymentInfo where
                       tqDInvoiceByPaymentInfo.tiDInvoice_ID     = tDIncSelLine.tiDInvoiceId and
                       tqDInvoiceByPaymentInfo.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}
                       no-error.
    
            if not available tqDInvoiceByPaymentInfo
            then do:
                <M-74 run SetMessage
                   (input  trim(#T-25'Customer invoice (ID: $1) is not defined in the system.':250(1648)T-25#) (icMessage), 
                    input  string(tDIncSelLine.tiDInvoiceId) (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'qadfin-415163':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
    
                assign oiReturnStatus = -1.
                next.
            end. /*  if not available tqDInvoiceByPaymentInfo */
    
            if tqDInvoiceByPaymentInfo.tlDInvoiceIsOpen           <> true                         or
               tqDInvoiceByPaymentInfo.tlDInvoiceIsSelected       <> false                        or
               tqDInvoiceByPaymentInfo.tdDInvoiceOriginalDebitTC  <> ?                            and
               tqDInvoiceByPaymentInfo.tdDInvoiceOriginalDebitTC  <> 0                            and
               tqDInvoiceByPaymentInfo.tdDInvoiceBalanceDebitTC   <> tDIncSelLine.tdInvoiceBalance or
               tqDInvoiceByPaymentInfo.tdDInvoiceOriginalCreditTC <> ?                            and
               tqDInvoiceByPaymentInfo.tdDInvoiceOriginalCreditTC <> 0                            and
               tqDInvoiceByPaymentInfo.tdDInvoiceBalanceCreditTC  <> tDIncSelLine.tdInvoiceBalance 
            then do:
                if  tqDInvoiceByPaymentInfo.tcDInvoiceType <> {&INVOICETYPE-DEDUCTION} then
                do:
                    <M-46 run SetMessage
                       (input  trim(#T-79'Customer invoice $1 can no longer be processed because someone else modified it.':250(1649)T-79#) (icMessage), 
                        input  tDIncSelLine.tcInvoiceNumber (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  '':U (icRowid), 
                        input  'qadfin-595464':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
    
                    assign oiReturnStatus = -1.
               end.   
            end. /* if tqDInvoiceByPaymentInfo.tlDInvoiceIsOpen */
         
        end. /* for each tDIncSelLine */ 
        
    end. /* for each t_sDPaySel */
    
    <M-37 run ValidateComponentPaySelPayCode  (output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
    if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.
    
    if oiReturnStatus < 0
    then return.
    
    /* make sure that if the paysel line has a status of 'd' that the related tables have a status of ' '.
       this is to get around the issue of cascading deletes when moving a stage payment to another payment selection 
       the PaySelPayRef record deletion is managed from the UI - so always set that status to blank.
       */
    for each t_sDPaySelLine where t_sDPaySelLine.tc_Status = "D":U:
        for each t_sDPaySelLineStg where t_sDPaySelLineStg.DPaySelLine_ID = t_sDPaySelLine.DPaySelLine_ID:        
            if t_sDPaySelLineStg.tc_status = "D":U then
            assign t_sDPaySelLineStg.tc_status = " ":U.
        end. /* for each t_sDPaySelLineStg */     
    end. /* for each t_sDPaySelLine */
    for each t_sDPaySelPayRef:
        if t_sDPaySelPayRef.tc_status = "D":U then
        assign t_sDPaySelPayRef.tc_status = " ":U.
    end. /* for each t_sDPaySelLineStg */