project QadFinancials > class BBankImportLine > method ProcessBankImpLineAction

Description

This method processes Bank Import Line according to the action code and copy tFcMessages and return status from processed action to the BankkImpLineLog record afterwards.


Parameters


icTransactionActioninputcharacterTransaction Acition
ilCreateToPaidinputlogicalAction to pay document
ilCreateBankEntryinputlogicalaction to create Banking Entry
ilIncludeAllEntitiesinputlogicalInclude All Entities
ilExistProcessedBankImpLineinputlogicalExists Processed Bank Import Line
ilIsBankProcessLogOpeninputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankImportLine.SaveAndProcess


program code (program6/bbankimportline.p)

/* ================================================================= */
/*                                                                   */
/* ================================================================= */
assign oiReturnStatus = -98
       viLocalReturn  = 0.

/* Back up the original information in tFCMessages table*/
for each tFCMessages:
    create tFcMessagesBackUp.
    buffer-copy tFCMessages to tFCMessagesBackUp.
end.

/* Clear all the records in the tFCMessages table */
empty temp-table tFCMessages.
/* Clear all records in tBankImplineProcessRef table */
empty temp-table tBankImplineProcessRef.

/* =================================================================================================== */
/* Validate input parameters                                                                           */
/* =================================================================================================== */
if not available tBankImpLine
then do:
    assign vcMessage = trim(#T-18'Missing definition of imported bank line.':255(67965)T-18#).
    <M-23 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'S':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'qadfin-745561':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    assign oiReturnStatus = -1.
    return.
end.
/* ==================================================================================== */
/* If ilExistProcessedBankImpLineInvoiceDetail = yes, then skip processing BankImpLine, */
/* create tBankImpLineLog records with existing processed records,                      */
/* assign tBankImpLine.BankImpLineProcessedStatus from existing process record as well. */
/* If ilExistProcessedBankImpLineInvoiceDetail = no,                                    */
/* then execute originally to process BankImpLine.                                      */
/* ==================================================================================== */
if ilExistProcessedBankImpLine
then do:
    for each tBankImpLineDetRef
        where tBankImpLineDetRef.BankImp_ID = tBankImpLine.BankImp_ID:

        find first tBankImpLineDetLog where
                   tBankImpLineDetLog.BankImpLine_ID = tBankImpLineDetRef.BankImpLine_ID no-error.
        if available tBankImpLineDetLog
        then do:
             <M-67 run SetMessage
                (input  'This bank ImportLine was not Processed successfully. See details of other Bank lines for same payment reference' (icMessage), 
                 input  ? (icArguments), 
                 input  ? (icFieldName), 
                 input  ? (icFieldValue), 
                 input  'E':U (icType), 
                 input  1 (iiSeverity), 
                 input  tBankImpLine.tc_Rowid (icRowid), 
                 input  'qadfin-141109':U (icFcMsgNumber), 
                 input  ? (icFcExplanation), 
                 input  ? (icFcIdentification), 
                 input  ? (icFcContext), 
                 output oiReturnStatus (oiReturnStatus)) in BBankImportLine>

             assign tBankImpLine.BankImpLineProcessedStatus = {&BANKIMPPROCSTATUS-PROCESSED-ERROR}.

             for each tFcMessages:
                 find first tBankImpLineLog where
                     tBankImpLineLog.BankImpLineLogRowid = tFcMessages.tcFcRowid
                 no-error.
                 if not available tBankImpLineLog
                 then do:

                    <M-30 run AddDetailLine
                       (input  'BankImpLineLog':U (icTable), 
                        input  tBankImpLine.tc_Rowid (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
                    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
                    then assign oiReturnStatus = viFcReturnSuper.
                     assign tBankImpLineLog.BankImpLineLogRowid       = tFcMessages.tcFcRowid
                            tBankImpLineLog.BankImpLineLogFieldName   = tFcMessages.tcFcFieldName
                            tBankImpLineLog.BankImpLineLogFieldValue  = tFcMessages.tcFcFieldValue
                            tBankImpLineLog.BankImpLineLogLog         = "":U
                            tBankImpLineLog.BankImpLineLogMessage     = tFcMessages.tcFcMessage
                            tBankImpLineLog.BankImpLineLogSeverity    = tFcMessages.tiFcSeverity
                            tBankImpLineLog.BankImpLineLogType        = tFcMessages.tcFcType 
                            tBankImpLineLog.BankImpLineLogFieldLabel  = tFcMessages.tcFcFieldLabel.
                end. /* if not available tBankImpLineLog */
            end. /* for each tFcMessages */
            empty temp-table tFcMessages.
        end. /* if available tBankImpLineDetLog */
    end. /* for each tBankImpLineDetRef */
end. /* if ilExistProcessedBankImpLine */
else do:

    /* Create Processing Info */
    <M-81 run CreateBankImpLineProcessInfo
       (input  icTransactionAction (icProcessName), 
        input  '':U (icProcessDesc), 
        input  ? (icProcessResult), 
        input  ? (icProcessParam), 
        input  ? (icParentRowName), 
        input  0 (iiProcessStatus), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>

    /* Process Bank Import Line according to the Action Code */
    case icTransactionAction:
        when {&BANKIMPORTACTION-CREATEDDOCUMENT}
        then do:
            <M-2 run ProcessBankImpLineNewDDocument
               (input  ilIncludeAllEntities (ilIncludeAllEntities), 
                input  ilCreateToPaid (ilCreatedToPaid), 
                input  ilCreateBankEntry (ilCreateBankEntry), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>.
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
            assign viLocalReturn = viFcReturnSuper.
        end.
        
        when {&BANKIMPORTACTION-PAIDDDOCUMENT}
        then do:
            <M-5 run ProcessBankImpLineDDocStatusChg
               (input  {&DOCUMENTSTATUS-PAID} (icToStatus), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
            assign viLocalReturn = viFcReturnSuper.
        end.
        
        when {&BANKIMPORTACTION-PAIDCDOCUMENT}
        then do:
            <M-6 run ProcessBankImpLineCDocStatusChg
               (input  {&DOCUMENTSTATUS-PAID} (icToStatus), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
            assign viLocalReturn = viFcReturnSuper.
        end.
        
        when {&BANKIMPORTACTION-BOUNCEDDDOCUMENT}
        then do:
            <M-7 run ProcessBankImpLineDDocStatusChg
               (input  {&DOCUMENTSTATUS-BOUNCED} (icToStatus), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
            assign viLocalReturn = viFcReturnSuper.
        end.
        
        when {&BANKIMPORTACTION-BOUNCEDCDOCUMENT}
        then do:
            <M-8 run ProcessBankImpLineCDocStatusChg
               (input  {&DOCUMENTSTATUS-BOUNCED} (icToStatus), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
            assign viLocalReturn = viFcReturnSuper.
        end.
        
        when {&BANKIMPORTACTION-CREATEBE} 
        then do:
            <M-3 run ProcessBankImpLineNewBankEntry
               (input  true (ilIsBatchProcessing), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
            assign viLocalReturn = viFcReturnSuper.
        end.
        
        when {&BANKIMPORTACTION-CONFIRM}
        then do:
            <M-70 run ProcessBankImpLineConfirm  (output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
            assign viLocalReturn = viFcReturnSuper.
        end.
        
        when {&BANKIMPORTACTION-OTHER}
        then do:
            <Q-24 run CompanyForAddressInfo (all) (Read) (NoCache)
               (input viCompanyId, (CompanyId)
                output dataset tqCompanyForAddressInfo) in BCompany>
            
            find first tqCompanyForAddressInfo no-lock no-error.    
            
            if tBankImpLine.BankImpLineBusRelType = {&BANKIMPBUSRELTYPE-DEBTOR}  and
              (tqCompanyForAddressInfo.tcCountryCode = "BRZ":U                   or
               tqCompanyForAddressInfo.tcCountryCode = "BRS":U )  
            then do:
                <M-38 run ProcessBankImpLineOther  (output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>            
                if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
                assign viLocalReturn = viFcReturnSuper.
            end.
        end.
    end case.

    /* Update processing result */
    <M-17 run UpdateBankImpLineProcessResult
       (input  icTransactionAction (icProcessName), 
        input  viLocalReturn (iiProcessStatus), 
        input  ? (icProcessResult), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>

    /* Create new record in tBankImpLineProcessRef */
    if ilIsBankProcessLogOpen = yes
    then do:
        define buffer bBankImpLineProcBuf for tBankImpLinePrc.

        for each tBankImpLineProcessRef:
            /* Remove legacy processing info */
            <M-89 run StartPersistence
               (output vhFcComponent (ohPersistence), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
            <M-56 run InitTransaction  (output viFcReturnSuper (oiReturnStatus)) in persistence>
            <M-45 run WriteDirect
               (input  'BankImpLinePrc':U (icTableName), 
                input  'for each bankimplineprc where bankimpline_id = ' + string(tBankImpLine.BankImpLine_ID) (icPrepare), 
                input  '':U (icFieldList), 
                input  '':U (icFieldListDataTypes), 
                input  '':U (icAbsolute), 
                input  '':U (icIncremental), 
                input  {&TARGETPROCEDURE} (ihClass), 
                input  vcUserLogin (icUserLogin), 
                output viFcReturnSuper (oiReturnStatus)) in persistence>    
            <M-58 run CommitTransaction  (output viFcReturnSuper (oiReturnStatus)) in persistence>

            for each bBankImpLineProcBuf where
                 bBankImpLineProcBuf.BankImpLine_ID           = tBankImpLine.BankImpLine_ID and
                 bBankImpLineProcBuf.BankImpLinePrcCode       = tBankImpLineProcessRef.tcBankImpLineProcessName and
                 bBankImpLineProcBuf.ParentBankImpLinePrc_ID  = viProcessParentId and
                 bBankImpLineProcBuf.tc_Status                <> 'D':U:
                 delete bBankImpLineProcBuf.
            end.
            /* Find BankImpLineProcParent row if existing */
            assign viProcessParentId = 0.
            if tBankImpLineProcessRef.tcParentRow <> ? and
               tBankImpLineProcessRef.tcParentRow <> '':U then
            do:
                find first bBankImpLineProcBuf where 
                    bBankImpLineProcBuf.BankImpLine_ID    = tBankImpLine.BankImpLine_ID and
                    bBankImpLineProcBuf.BankImpLinePrcCode = tBankImpLineProcessRef.tcParentRow and
                    bBankImpLineProcBuf.tc_Status <> "D":U no-error.
                if available bBankImpLineProcBuf then assign viProcessParentId = bBankImpLineProcBuf.BankImpLinePrc_ID.
            end.
            
            /* Skip duplicate info */
            find first bBankImpLineProcBuf where 
                bBankImpLineProcBuf.BankImpLine_ID          = tBankImpLine.BankImpLine_ID and
                bBankImpLineProcBuf.BankImpLinePrcCode      = tBankImpLineProcessRef.tcBankImpLineProcessName and
                bBankImpLineProcBuf.ParentBankImpLinePrc_ID = viProcessParentId and
                bBankImpLineProcBuf.tc_Status              <> 'D':U no-error.
            if available bBankImpLineProcBuf then next.

            <M-64 run AddDetailLine
               (input  'BankImpLinePrc':U (icTable), 
                input  tBankImpLine.tc_Rowid (icParentRowid), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
            then assign oiReturnStatus = viFcReturnSuper.
            assign tBankImpLinePrc.BankImpLine_ID          = tBankImpLine.BankImpLine_ID
                   tBankImpLinePrc.BankImp_ID              = tBankImpLine.BankImp_ID
                   tBankImpLinePrc.BankImpLinePrcCode      = tBankImpLineProcessRef.tcBankImpLineProcessName
                   tBankImpLinePrc.BankImpLinePrcDesc      = tBankImpLineProcessRef.tcBankImpLineProcessDesc
                   tBankImpLinePrc.BankImpLinePrcResult    = tBankImpLineProcessRef.tcBankImpLineProcessResult
                   tBankImpLinePrc.BankImpLinePrcParam     = tBankImpLineProcessRef.tcBankImpLineProcessParam
                   tBankImpLinePrc.BankImpLinePrcStatus    = tBankImpLineProcessRef.tcBankImpLineProcessStatus
                   tBankImpLinePrc.BankImpLinePrcLevel     = tBankImpLineProcessRef.tiRowLevel
                   tBankImpLinePrc.ParentBankImpLinePrc_ID = viProcessParentId.
    
        end. /* for each tBankImpLineProcessRef */
    end. /* if ilIsBankProcessLogOpen */
    empty temp-table tBankImpLineProcessRef.

    if viLocalReturn = -98 then return.
    
    /* Copy tFcMessages and return status from processed action to the BankkImpLineLog record */
    assign vcParentRowId = "":U.

    for each tFCMessages:
        if tFcMessages.tcFcRowid begins "BIL"
        then do:
            find first tBankImpLineDet where
                tBankImpLineDet.tc_Rowid = substring(tFcMessages.tcFcRowid,4,-1,"CHARACTER":U)
            no-error.
            if available tBankImpLineDet
            then vcParentRowId = tBankImpLineDet.tc_Rowid.
        end.
        else assign vcParentRowId = tBankImpLine.tc_Rowid.

        <M-1 run AddDetailLine
           (input  'BankImpLineLog':U (icTable), 
            input  vcParentRowId (icParentRowid), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
        then assign oiReturnStatus = viFcReturnSuper.
        assign tBankImpLineLog.BankImpLineLogRowid       = vcParentRowId
               tBankImpLineLog.BankImpLineLogFieldName   = tFcMessages.tcFcFieldName
               tBankImpLineLog.BankImpLineLogFieldValue  = tFcMessages.tcFcFieldValue
               tBankImpLineLog.BankImpLineLogLog         = "":U
               tBankImpLineLog.BankImpLineLogMessage     = tFcMessages.tcFcMessage
               tBankImpLineLog.BankImpLineLogSeverity    = tFcMessages.tiFcSeverity
               tBankImpLineLog.BankImpLineLogType        = tFcMessages.tcFcType
               tBankImpLineLog.BankImpLineLogFieldLabel  = tFcMessages.tcFcFieldLabel.
        /* assign value for mandatory field BankImpLineLogRowId */
        if tBankImpLineLog.BankImpLineLogRowid = ? or
           tBankImpLineLog.BankImpLineLogRowid = ""
        then assign tBankImpLineLog.BankImpLineLogRowid = tBankImpLine.tc_Rowid.
        
    end. /* for each tFCMessages */
    empty temp-table tFCMessages.
    /* When there is no error on some invoices in this payment. */
    find first tBankImpLineLog where tBankImpLineLog.BankImpLineLogRowid = tBankImpLine.tc_Rowid no-error.
    if not available tBankImpLineLog
    then do:
        if num-entries(tBankImpLine.BankImpLineProcessedStatus) > 1 and 
            entry(1, tBankImpLine.BankImpLineProcessedStatus) = {&BANKIMPPROCSTATUS-PROCESSED-OK}
        then do:
            /* Handle warning message if necessary */
        end.
        else assign tBankImpLine.BankImpLineProcessedStatus = {&BANKIMPPROCSTATUS-PROCESSED-OK}.
    end.
end. /* else do */

/* Restore Original tFcMessages and error status from backup temp table */
for each tFcMessagesBackUp:
    create tFcMessages.
    buffer-copy tFcMessagesBackUp to tFcMessages.
end.

if oiReturnStatus = -98 then assign oiReturnStatus = 0.