project QadFinancials > class BERSProcessor > method ERSProcessPORec

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


biNumberOfProcessedRecordsinput-outputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BERSProcessor.ERSProcess


program code (program5/bersprocessor.p)

/* =============================================================================================== */
/* Pickup all receipt lines of this receiver                                                       */
/* =============================================================================================== */
/* Calculate the total amount for all Receiver Lines */
assign vdAPMatchingLnRecTotAmt = 0.
for each bERSProcessorRef where
         bERSProcessorRef.tcReceiverNbr = tERSProcessorRef.tcReceiverNbr and
         bERSProcessorRef.tiERSOpt      = tERSProcessorRef.tiERSOpt      and     
         bERSProcessorRef.tlIsSelected  = true                           and
         bERSProcessorRef.tlIsProcessed = false                          and
         (bERSProcessorRef.tiERSStatus  = {&PVO_ERS_STATUS_READY_0} or
          bERSProcessorRef.tiERSStatus  = {&PVO_ERS_STATUS_READY_1} or
          bERSProcessorRef.tiERSStatus  = {&PVO_ERS_STATUS_ERROR}):
    assign vdAPMatchingLnRecTotAmt = vdAPMatchingLnRecTotAmt + 
                                    (bERSProcessorRef.tdAPMatchingLnMatchQty * 
                                    bERSProcessorRef.tdAPMatchingLnMatchUnitPriceTC).
end.

RECEIPT_BLOCK:
for each bERSProcessorRef where
         bERSProcessorRef.tcReceiverNbr = tERSProcessorRef.tcReceiverNbr and
         bERSProcessorRef.tiERSOpt      = tERSProcessorRef.tiERSOpt      and     
         bERSProcessorRef.tlIsSelected  = true                           and
         bERSProcessorRef.tlIsProcessed = false                          and
         (bERSProcessorRef.tiERSStatus  = {&PVO_ERS_STATUS_READY_0} or
          bERSProcessorRef.tiERSStatus  = {&PVO_ERS_STATUS_READY_1} or
          bERSProcessorRef.tiERSStatus  = {&PVO_ERS_STATUS_ERROR})
    break by bERSProcessorRef.tcReceiverNbr:

    assign viRecLineReturn            = 0
           biNumberOfProcessedRecords = biNumberOfProcessedRecords + 1.

    RECEIPT_LINE_BLOCK: 
    do:
        /* =========================================================================================== */
        /* Get some details about this receipt                                                         */
        /* =================================================================================================== */
        <Q-15 run PendingVoucherForERSDetail (all) (Read) (NoCache)
           (input bERSProcessorRef.tcDomainCode, (Domain)
            input bERSProcessorRef.tcReceiverNbr, (Receiver)
            input bERSProcessorRef.tiPvoId, (PvoId)
            input bERSProcessorRef.tiPvodLineId, (PvodLineId)
            output dataset tqPendingVoucherForERSDetail) in BMfgPendingVoucher >
            
        find first tqPendingVoucherForERSDetail where
                   tqPendingVoucherForERSDetail.tcprh_domain   = bERSProcessorRef.tcDomainCode  and
                   tqPendingVoucherForERSDetail.tcprh_receiver = bERSProcessorRef.tcReceiverNbr and
                   tqPendingVoucherForERSDetail.tipvo_id       = bERSProcessorRef.tiPvoId       and
                   tqPendingVoucherForERSDetail.tipvod_id_line = bERSProcessorRef.tiPvodLineId
                   no-error.
        
        if not available tqPendingVoucherForERSDetail
        then do:
            assign vcMessage = #T-17'Cannot get purchase and receipt details for validation executed during processing of ERS.':255(70683)T-17#
                   vcContext = "DomainCode=&1|PvoID=&2|PvodLineID=&3":U
                   vcContext = replace(vcContext, "|":U, chr(2))
                   vcContext = substitute(vcContext, bERSProcessorRef.tcDomainCode, bERSProcessorRef.tiPvoId, bERSProcessorRef.tiPvodLineId).
            <M-16 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-8499':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  vcContext (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
             assign viRecLineReturn = -1.
             leave RECEIPT_LINE_BLOCK.
        end.
    
        /* =========================================================================================== */
        /* Validate receipt                                                                            */
        /* =========================================================================================== */
        <M-18 run ValidateReceipt
           (input  bERSProcessorRef.tcDomainCode (icDomain), 
            input  bERSProcessorRef.tiPvoId (iiPvoId), 
            input  bERSProcessorRef.tiPvodLineId (iiPvodLineId), 
            input  bERSProcessorRef.tdAPMatchingLnMatchQty (idMatchQty), 
            output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
        if viFcReturnSuper <> 0 then assign viRecLineReturn = viFcReturnSuper.
        if viFcReturnSuper <  0 then leave RECEIPT_LINE_BLOCK.

        /* =========================================================================================== */
        /* Create supplier invoice                                                                     */
        /* =========================================================================================== */
        if first-of(bERSProcessorRef.tcReceiverNbr)
        then do:
            <M-7 run ERSProcessCInvoice
               (input  bERSProcessorRef.tcFcRowid (icERSProcessorRefRowId), 
                input  vdAPMatchingLnRecTotAmt (idAPMatchingLnRecTotAmt), 
                output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
            if viFcReturnSuper <> 0 then assign viRecLineReturn = viFcReturnSuper.
            if viFcReturnSuper <  0 then leave RECEIPT_LINE_BLOCK.
        end.
        
        /* =========================================================================================== */
        /* Create supplier invoice PO lines                                                            */
        /* =========================================================================================== */
        <M-19 run ERSProcessCInvoicePO
           (input  bERSProcessorRef.tcFcRowid (icERSProcessorRefRowId), 
            output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
        if viFcReturnSuper <> 0 then assign viRecLineReturn = viFcReturnSuper.
        if viFcReturnSuper <  0 then leave RECEIPT_LINE_BLOCK.


        /* =========================================================================================== */
        /* Create matching line                                                                        */
        /* =========================================================================================== */
        <M-8 run ERSProcessAPMatching
           (input  bERSProcessorRef.tcFcRowid (icERSProcessorRefRowId), 
            output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
        if viFcReturnSuper <> 0 then assign viRecLineReturn = viFcReturnSuper.
        if viFcReturnSuper <  0 then leave RECEIPT_LINE_BLOCK.
    end. /* of RECEIPT_LINE_BLOCK */
    
    /* =========================================================================================== */
    /* Copy all errors to current record                                                           */
    /* =========================================================================================== */
    if viRecLineReturn < 0 
    then assign bERSProcessorRef.tiERSStatus = {&PVO_ERS_STATUS_ERROR_PROCESS}.

    <M-2 run CopyToReceiptErrors
       (input  bERSProcessorRef.tcFcRowid (icReceiptRowId), 
        input  true (ilDeleteSystemErrors), 
        output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
    if viFcReturnSuper <> 0 then assign viExternalReturn = viFcReturnSuper.
    if viRecLineReturn < 0
    then do:
      assign oiReturnStatus = viRecLineReturn.
      leave RECEIPT_BLOCK.
    end.
end. /* of RECEIPT_BLOCK */