project QadFinancials > class BBankNumber > method SetBankNumberPayCode

Description

Loads or creates records in table BankNumberPayCode based on Ref table


Parameters


t_sBankNumberPayCodeRefinputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankNumber.UpdateBankNumberAndPayCode


program code (program1/bbanknumber.p)

assign vcPAYMENTFORMATS ={&PAYMENTFORMATS}.
for each t_sBankNumberPayCodeRef where 
    t_sBankNumberPayCodeRef.tc_Status <> "":U and
    t_sBankNumberPayCodeRef.tc_Status <> "D":U:
    
    find first tBankNumberPayCode where 
               tBankNumberPayCode.BankNumberPayCode_ID = t_sBankNumberPayCodeRef.BankNumberPayCode_ID no-error.
    if not available tBankNumberPayCode
    then do:        
        /*always load all PayCodes of a certain BankNumber_Id*/
        if  not can-find(first tBankNumber where 
                              tBankNumber.BankNumber_ID = t_sBankNumberPayCodeRef.BankNumber_ID) 
        then Load_Block: do:
            assign vlRunCalculate = false.
            <M-1 run DataLoad
          (input  '':U (icRowids), 
           input  string(t_sBankNumberPayCodeRef.BankNumber_ID) (icPkeys), 
           input  '':U (icObjectIds), 
           input  '' (icFreeform), 
           input  true (ilKeepPrevious), 
           output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
            /*JBA: it can happen that somebody else in another session deleted the record 
            I can still see in my session (returnStatus -4)
            In that case I will give a error*/
            if viFcReturnSuper = -4
            then do:
                
                def var vcTemp as char case-sensitive no-undo.

                <Q-15 run PayFormatGroupPrim (all) (Read) (NoCache)
                   (input t_sBankNumberPayCodeRef.PayFormatGroup_ID, (PayFormatGroupID)
                    input ?, (PayFormatTypeCode)
                    input ?, (PayFormatGroupSequence)
                    output dataset tqPayFormatGroupPrim) in BPaymentFormat >

                for first tqPayFormatGroupPrim:
                    assign vcTemp            = tqPayFormatGroupPrim.tcPayFormatTypeCode
                           vcPayFormatTypeTr = entry(lookup(vcTemp, vcPAYMENTFORMATS, chr(2)) - 1,
                                                     vcPAYMENTFORMATS, chr(2)) no-error.
                end.

                assign  oiReturnStatus = -1.
                        vcMessage = trim(subst(#T-10'The system cannot create or modify the payment format of type &1, group &2.':200(403)t-10#, 
                                    vcPayFormatTypeTr,
                                    t_sBankNumberPayCodeRef.tcPayFormatGroupDescription)) + " ":U + 
                                   trim(#T-11'The bank number specified is not defined in the system.':200(404)t-11#) + " ":U + 
                                   trim(#T-12'Most probably deleted by somebody else in another session (just a few minutes ago).':200(405)T-12#).
                                   
                <M-9 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'D':U (icType),
                     input  '3':U (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1220':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
                return.
            end.
            
            if viFcReturnSuper <> 0
            then do:
                assign oiReturnStatus = viFcReturnSuper.
                return.
            end.
            /*continue only if this is already existing Pay code record, otherwise leave this block*/
            if t_sBankNumberPayCodeRef.tc_Status = "N":U
            then leave Load_Block.
        end. /* load the existing record */
        
        find first tBankNumber where 
                   tBankNumber.BankNumber_ID = t_sBankNumberPayCodeRef.BankNumber_ID no-error.
        if not available tBankNumber
        then do:
            /* error handling */
            assign oiReturnStatus = -1
                   vcMessage      = trim(substitute(#T-13'&1 not available.':200(406)t-13#, "tBankNumber":U)) + chr(10) + 
                                    program-name(1).
            <M-7 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'D':U (icType),
                     input  2 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1213':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
            return.
        end.
        /*JBA: create a new record 
        this is in fact an 'else' part of the previous 'if' statement but as I assign 
        the tc_Status to "N" in there I have to use another 'if' statement in here*/
        if t_sBankNumberPayCodeRef.tc_Status = "N":U
        then do:
            <M-4 run AddDetailLine (input  'BankNumberPayCode':U (icTable), 
                        input  tBankNumber.tc_Rowid (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
            if viFcReturnSuper <> 0
            then do:
                assign oiReturnStatus = viFcReturnSuper.
                return.
            end.            
        end. /* create */
        
        /*JBA 02/03/2005 ignore all the records created and deleted afterwards*/
        if t_sBankNumberPayCodeRef.tc_Status = "D":U and
           not can-find (first tBankNumberPayCode where 
                               tBankNumberPayCode.BankNumberPayCode_ID = t_sBankNumberPayCodeRef.BankNumberPayCode_ID)
        then next.
        
        /*find first tBankNumberPayCode*/
        if not available tBankNumberPayCode 
        then find first tBankNumberPayCode where 
                        tBankNumberPayCode.BankNumberPayCode_ID = t_sBankNumberPayCodeRef.BankNumberPayCode_ID no-error.
        
        if not available tBankNumberPayCode
        then do:
            /* error handling */
            assign oiReturnStatus = -1
                   vcMessage      = trim(substitute(#T-14'&1 not available.':200(406)t-14#, "tBankNumberPayCode":U)) + chr(10) + 
                                    program-name(1).
            <M-6 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'D':U (icType),
                     input  2 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1204':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
            return.
        end.
    end.
    /*copy Ref -> standard*/
    if t_sBankNumberPayCodeRef.tc_Status = "D":U
    then assign tBankNumberPayCode.tc_Status = "D":U.
    else do:
        /*Get PayFormatCode_ID */
        if t_sBankNumberPayCodeRef.tcPayFormatCode <> "":U and 
           t_sBankNumberPayCodeRef.tcPayFormatCode <> "":U and
           t_sBankNumberPayCodeRef.tcPayFormatCode <> ?
        then do:
            <Q-81 run PayFormatCodebyGroupID (all) (Read) (NoCache)
               (input ?, (PayFormatCodeID)
                input t_sBankNumberPayCodeRef.tcPayFormatCode, (PayFormatCode)
                input t_sBankNumberPayCodeRef.PayFormatGroup_ID, (PayFormatGroupID)
                output dataset tqPayFormatCodebyGroupID) in BPaymentFormat >
            find first tqPayFormatCodebyGroupID where
                       tqPayFormatCodebyGroupID.tcPayFormatCode     = t_sBankNumberPayCodeRef.tcPayFormatCode and
                       tqPayFormatCodebyGroupID.tiPayFormatGroup_ID = t_sBankNumberPayCodeRef.PayFormatGroup_ID
                       no-error.
            assign t_sBankNumberPayCodeRef.PayFormatCode_ID = if available tqPayFormatCodebyGroupID
                                                              then tqPayFormatCodebyGroupID.tiPayFormatCode_ID
                                                              else ?.
        end.
        else assign t_sBankNumberPayCodeRef.PayFormatCode_ID = ?.
        
        /*for the moment sequence always = 1 because according to the new concept 
        this field seems to be obsolate*/
        assign t_sBankNumberPayCodeRef.BankNumberPayCodeSequence = 1.
        
        buffer-copy t_sBankNumberPayCodeRef 
             except BankNumberPayCode_ID tc_Rowid tc_ParentRowid to tBankNumberPayCode.
    end.
end. /* for each */