project QadFinancials > class BERSProcessor > method ERSProcess

Description

Main method used for ERS processing: all pending voucher records flagged by the user will be processed: the pending vouchers will be validated. If the validation is passed, the supplier invoices and AP matching records will be created for the pending vouchers.


Parameters


oiNumberOfProcessedRecordsoutputintegerOutput parameter: records the number of pending vouchers processed by the ERS processor.
olIsEndOfFileoutputlogicalOutput parameter: logical flag to indicate when the processing has finished.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BERSProcessor.ERSProcessBatch


program code (program5/bersprocessor.p)

/* =================================================================================================== */
/* Method      : ERSProcess                                                                            */
/* Desc        : Main procedure or ERS Processor, pickups first not yet processed receipt, does        */
/*               validation of this receipt and creates CI and RM for it                               */
/* --------------------------------------------------------------------------------------------------- */
/* Params:   (O) NumberOfProcessedRecords     Number of processed records                              */
/*           (O) IsEndOfFile                  Is end of file                                           */
/* =================================================================================================== */

assign oiReturnStatus = -98.

/* =================================================================================================== */
/* Default output values                                                                               */
/* =================================================================================================== */
assign oiNumberOfProcessedRecords = 0
       olIsEndOfFile              = false.

/* =================================================================================================== */
/* AP Control File                                                                                     */
/* =================================================================================================== */
<Q-4 run AccountsPayableCtrlByDomain (all) (Read) (Cache)
   (input vcDomainCode, (DomainCode)
    output dataset tqAccountsPayableCtrlByDomain) in BMfgAccountPayableCtrl >
find first tqAccountsPayableCtrlByDomain where
           tqAccountsPayableCtrlByDomain.tcapc_domain = vcDomainCode
           no-error.

if not available tqAccountsPayableCtrlByDomain
then do:
    assign vcMessage = #T-6'The accounts payable setup is missing for domain &1.':200(70372)t-6#
           vcMessage = substitute(vcMessage, vcDomainCode).
    <M-5 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  'Domain':U (icFieldName), 
        input  vcDomainCode (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-8385':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
    assign oiReturnStatus = -1.
    return.
end.

/* =================================================================================================== */
/* System does execution in about 15sec blocks                                                         */
/* =================================================================================================== */
assign viStartTime      = time
       viExternalReturn = 0.

MAIN_BLOCK:
do while true:

    /* =============================================================================================== */
    /* Get next record to be processed                                                                 */
    /* =============================================================================================== */
    find first tERSProcessorRef where
               tERSProcessorRef.tlIsSelected  = true                         and
               tERSProcessorRef.tlIsProcessed = false                        and
               (tERSProcessorRef.tiERSStatus = {&PVO_ERS_STATUS_READY_0} or
                tERSProcessorRef.tiERSStatus = {&PVO_ERS_STATUS_READY_1} or
                tERSProcessorRef.tiERSStatus = {&PVO_ERS_STATUS_ERROR})      and 
               tERSProcessorRef.tiERSOpt    <> 0                             and
               tERSProcessorRef.tiERSOpt    <> 1
               no-error.
    
    if not available tERSProcessorRef
    then do:
        assign olIsEndOfFile  = true
               oiReturnStatus = 0.
        return.
    end.

    /* =============================================================================================== */
    /* Start new execution block                                                                       */
    /* =============================================================================================== */
    empty temp-table tCInvoiceRefERS.
    empty temp-table tCInvoicePORefERS.
    empty temp-table tAPMatchingLnRefERS.
    empty temp-table tAPMatchingCostRefERS.
    empty temp-table tAPMatchingCostSafRefERS.

    <M-1 run CopyToSystemErrors  (output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
    assign viLocalReturn = 0.

    if vcGroupBy = {&ERSPROCESSORINVGROUP-LEGALDOC}
    then do:

        <M-38 run ERSProcessLegalDocuments
           (input-output oiNumberOfProcessedRecords (biNumberOfProcessedRecords), 
            output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
    end. /* if vcGroupBy = {&ERSPROCESSORINVGROUP-LEGALDOC} */
    else do:
        <M-90 run ERSProcessPORec
           (input-output oiNumberOfProcessedRecords (biNumberOfProcessedRecords), 
            output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
    end. /* NOT if vcGroupBy = {&ERSPROCESSORINVGROUP-LEGALDOC} */

    /* =============================================================================================== */
    /* Does real execution of creation of supplier invoice and receiver matching                       */
    /* =============================================================================================== */
    if vlIsCreateCIAndAPMatching and
       viLocalReturn >= 0
    then do:
    
        if (viBCInvoiceAPMatchingID = 0 or
            viBCInvoiceAPMatchingID = ?)
        then do:
            <I-11 {bFcStartAndOpenInstance
                 &ADD-TO-TRANSACTION = "false"
                 &CLASS              = "BCInvoiceAPMatching"}>
        end.
        else do:
            <I-12 {bFcOpenInstance
                 &CLASS           = "BCInvoiceAPMatching"}>
        end.    

        <M-9 run CreateCInvoiceAPMatching
           (input-output tCInvoiceRefERS (tCInvoiceRef), 
            input  tCInvoicePORefERS (tCInvoicePORef), 
            input-output tAPMatchingLnRefERS (tAPMatchingLnRef), 
            input-output tAPMatchingCostRefERS (tAPMatchingCostRef), 
            input-output tAPMatchingCostSafRefERS (tAPMatchingCostSafRef), 
            input  true (ilIsAllInvoicesInOneTrans), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoiceAPMatching>
        if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.

        <I-13 {bFcCloseAndStopInstance
             &CLASS           = "BCInvoiceAPMatching"}>
             
        /* Store created Supplier Invoice and Receiver matching Line ID */
        if viLocalReturn >= 0
        then do:
            /* Store IDs and References of Created data into the original record */
            for each tCInvoiceRefERS,
                each tAPMatchingLnRefERS where
                     tAPMatchingLnRefERS.tc_ParentRowid = tCInvoiceRefERS.tc_Rowid:
                     
                /* Find the original record which is displayed in the grid */
                find tERSProcessorRef where
                     tERSProcessorRef.tcDomainCode = tAPMatchingLnRefERS.tcDomainCode and
                     tERSProcessorRef.tiPvoId      = tAPMatchingLnRefERS.tiPvoId      and
                     tERSProcessorRef.tiPvodLineId = tAPMatchingLnRefERS.tiPvodLineId   
                     no-error.
                     
                if not available(tERSProcessorRef)
                then do:
                    assign vcMessage = #T-77'System cannot find expected record used for ERS processing.':255(241550606)T-77#
                           vcContext = "Domain=&1|PvoId=&2|PvodLineId=&3":U
                           vcContext = substitute(vcContext, tAPMatchingLnRefERS.tcDomainCode, tAPMatchingLnRefERS.tiPvoId, tAPMatchingLnRefERS.tiPvodLineId)
                           vcContext = replace(vcContext, "|":U, chr(2)).
                    <M-63 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-445593':U (icFcMsgNumber), 
                        input  '':U (icFcExplanation), 
                        input  '':U (icFcIdentification), 
                        input  vcContext (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
                    assign viExternalReturn = -1.
                    next.
                end.
                      
                assign tERSProcessorRef.tiAPMatchingLnId       = tAPMatchingLnRefERS.tiAPMatchingLnId
                       tERSProcessorRef.tiCInvoiceId           = tCInvoiceRefERS.tiCInvoice_ID
                       tERSProcessorRef.tcCInvoiceReferenceInt = tCInvoiceRefERS.tcCInvoiceReferenceInt
                       tERSProcessorRef.tlIsProcessed          = true.
            end.
        end.
    end. /* if vlIsCreateCIAndAPMatching and */

    /* =============================================================================================== */
    /* If anything went wrong during execution, all receipts are marked as excluded from processing    */
    /* =============================================================================================== */
    if vcGroupBy = {&ERSPROCESSORINVGROUP-LEGALDOC}
    then do:
        /* Copy all errors into all receipt lines */
        assign vlIsFirstPendingVoucher = true
               vcRefErrorMessage       = "":U.
        
        for each bERSProcessorRef where
                 bERSProcessorRef.tcDomainCode         = tERSProcessorRef.tcDomainCode         and
                 bERSProcessorRef.tcLegalDocNbr        = tERSProcessorRef.tcLegalDocNbr        and
                 bERSProcessorRef.tcShipFrom           = tERSProcessorRef.tcShipFrom           and
                 bERSProcessorRef.ttEffectiveIssueDate = tERSProcessorRef.ttEffectiveIssueDate and
                 bERSProcessorRef.tlIsSelected         = true:

            /* Copy the error only to the first processed pending voucher - to limit used memory */
            if vlIsFirstPendingVoucher
            then do:
                <M-66 run CopyToReceiptErrors
                   (input  bERSProcessorRef.tcFcRowid (icReceiptRowId), 
                    input  false (ilDeleteSystemErrors), 
                    output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
                if viFcReturnSuper <> 0 then assign viExternalReturn = viFcReturnSuper.
            
                assign vlIsFirstPendingVoucher = false.
            
                if can-find(first tFcMessages)
                then assign vcRefErrorMessage = substitute(#T-36'see error details for line Domain &1, Legal document number &2, Order &3, Order Ln &4 and Receiver &5':255(214811696)T-36#, 
                                                           bERSProcessorRef.tcDomainCode,
                                                           bERSProcessorRef.tcLegalDocNbr,
                                                           bERSProcessorRef.tcPurchaseOrderNbr,
                                                           bERSProcessorRef.tiPurchaseOrderLineNbr,
                                                           bERSProcessorRef.tcReceiverNbr).
            end. /* if vlIsFirstPendingVoucher */
            else if vcRefErrorMessage <> "":U
            then do:
                /* If there is an error, just set text with reference to the line with error */
                create tERSProcessorLogRef.
                assign tERSProcessorLogRef.tcFcRowid   = bERSProcessorRef.tcFcRowid
                       tERSProcessorLogRef.tcFcMessage = vcRefErrorMessage.
            end. /* else if vcRefErrorMessage <> "":U */
            
            assign bERSProcessorRef.tlIsProcessed = true.

            if viLocalReturn < 0
            then assign bERSProcessorRef.tiERSStatus            = {&PVO_ERS_STATUS_ERROR_PROCESS}
                        bERSProcessorRef.tiCInvoiceId           = ?
                        bERSProcessorRef.tcCInvoiceReferenceInt = ?.
            else assign bERSProcessorRef.tiERSStatus            = {&PVO_ERS_STATUS_INVOICED}.

        end. /* for each bERSProcessorRef where */
    end. /* if vcGroupBy = {&ERSPROCESSORINVGROUP-LEGALDOC} */
    else do: 
        /* Copy all errors into all receipt lines */
        for each bERSProcessorRef where
                 bERSProcessorRef.tcReceiverNbr    = tERSProcessorRef.tcReceiverNbr and
                 bERSProcessorRef.tiERSOpt         = tERSProcessorRef.tiERSOpt      and     
                 bERSProcessorRef.tlIsSelected     = true                           and
                 (bERSProcessorRef.tiERSStatus     = {&PVO_ERS_STATUS_READY_0} or
                  bERSProcessorRef.tiERSStatus     = {&PVO_ERS_STATUS_READY_1} or
                  bERSProcessorRef.tiERSStatus     = {&PVO_ERS_STATUS_ERROR}   or
                  bERSProcessorRef.tiERSStatus     = {&PVO_ERS_STATUS_ERROR_PROCESS}):
    
            <M-10 run CopyToReceiptErrors
               (input  bERSProcessorRef.tcFcRowid (icReceiptRowId), 
                input  false (ilDeleteSystemErrors), 
                output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
            if viFcReturnSuper <> 0 then assign viExternalReturn = viFcReturnSuper.
            
            assign bERSProcessorRef.tlIsProcessed = true.
            
            if viLocalReturn < 0
            then assign bERSProcessorRef.tiERSStatus            = {&PVO_ERS_STATUS_ERROR_PROCESS}
                        bERSProcessorRef.tiCInvoiceId           = ?
                        bERSProcessorRef.tcCInvoiceReferenceInt = ?
                        bERSProcessorRef.tlIsSelected           = false.
            else assign bERSProcessorRef.tiERSStatus            = {&PVO_ERS_STATUS_INVOICED}.
    
        end. /* for each bERSProcessorRef */
    end. /* NOT if vcGroupBy = {&ERSPROCESSORINVGROUP-LEGALDOC} */
    
    empty temp-table tFcMessages.

    /* =============================================================================================== */
    /* Stop processing or continue?                                                                    */
    /* =============================================================================================== */
    assign viEndTime     = time
           viElapsedTime = (if viEndTime >= viStartTime
                            then viEndTime - viStartTime
                            else viEndTime + 24 * 60 * 60 - viStartTime).

    if viElapsedTime > 15 then leave.
    
    /* =============================================================================================== */
    /* If there was system error, just stop                                                            */
    /* =============================================================================================== */
    if viExternalReturn <> 0 then assign oiReturnStatus = viExternalReturn.
    if oiReturnStatus <> -98 and oiReturnStatus < 0 then leave.
end. /* of MAIN_BLOCK */


/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.