project QadFinancials > class BERSProcessor > method GetERSLegalDocumentsLC

Description

Sub-method that finds the pending vouchers attached to a legal document.


Parameters


icDomainCodeinputcharacterFiltering parameter: domain code.
icSupplierinputcharacterFiltering parameter: supplier codes.
icSupplierFrominputcharacterFiltering parameter: start value for the supplier codes.
icSupplierToinputcharacterFiltering parameter: end value for the supplier codes.
icSiteinputcharacter
icSiteFrominputcharacterFiltering parameter: start value for the site codes.
icSiteToinputcharacterFiltering parameter: end value for the site codes.
icReceiverinputcharacterFiltering parameter: receiver number.
icReceiverFrominputcharacterFiltering parameter: start value for the receiver number.
icReceiverToinputcharacterFiltering parameter: end value for the receiver number.
itReceiptDateinputdateFiltering parameter: receipt dates.
itReceiptDateFrominputdateFiltering parameter: beginng date of the receipt dates.
itReceiptDateToinputdateFiltering parameter: endign date of the receipt dates.
icLegalDocumentinputcharacter
icLegalDocumentFrominputcharacter
icLegalDocumentToinputcharacterFiltering parameter: end value for the legal document number.
itEffIssueDateinputdateFiltering parameter: beginng date of the effective issue dates.
itEffIssueDateFrominputdateFiltering parameter: beginng date of the effective issue dates.
itEffIssueDateToinputdateFiltering parameter: ending date of the effective issue dates.
tERSProcessorRefoutputtemp-tableOutput temp-table: used to store the pending vouchers being considered for ERS Processing.
tERSProcessorLogRefoutputtemp-tableOutput temp-table: used to log status information for the pending vouchers being considered by the ERS Processor.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BERSProcessor.GetERSLegalDocuments


program code (program5/bersprocessor.p)

/* =================================================================================================== *
 * Retrieve pending vouchers with logistical charge which can be processed by ERS processor and for    *
 * which Legal documents exist                                                                         *
 * =================================================================================================== */

/* =================================================================================================== */
/* Get legal document lines fitting the input parameters condition                                     */
/* =================================================================================================== */
<Q-40 run LegalDocumentPendVoucherLCForERS (all) (Read) (NoCache)
   (input icDomainCode, (Domain)
    input icSupplier, (Supplier)
    input icSupplierFrom, (SupplierFrom)
    input icSupplierTo, (SupplierTo)
    input icSite, (Site)
    input icSiteFrom, (SiteFrom)
    input icSiteTo, (SiteTo)
    input itReceiptDate, (ReceiptDate)
    input itReceiptDateFrom, (ReceiptDateFrom)
    input itReceiptDateTo, (ReceiptDateTo)
    input icLegalDocument, (LegalDoc)
    input icLegalDocumentFrom, (LegalDocFrom)
    input icLegalDocumentTo, (LegalDocTo)
    input itEffIssueDate, (EffDate)
    input itEffIssueDateFrom, (EffDateFrom)
    input itEffIssueDateTo, (EffDateTo)
    output dataset tqLegalDocumentPendVoucherLCForE) in BMFGLegalDocument>
    
/* =================================================================================================== */
/* Remove pending vouchers, that were incorrectly read. We cannot have that directly done in the query */
/* because of complexity                                                                               */
/* =================================================================================================== */
for each tqLegalDocumentPendVoucherLCForE:
    /* Remove those pending vouchers that were posted already */
    if tqLegalDocumentPendVoucherLCForE.tllgd_posted = true
    then do:
        delete tqLegalDocumentPendVoucherLCForE.
        next.
    end.
    
end. /* for each tqLegalDocumentPendVoucherLCForE: */    
    
    

/* =================================================================================================== */
/* Process retrieved legal documents                                                                   */
/* =================================================================================================== */
for each tqLegalDocumentPendVoucherLCForE
    break by tqLegalDocumentPendVoucherLCForE.tclgd_domain
          by tqLegalDocumentPendVoucherLCForE.ttlgd_effdate 
          by tqLegalDocumentPendVoucherLCForE.tclgd_nbr
          by tqLegalDocumentPendVoucherLCForE.tclgd_shipfrom:
          
    
    /* Read all details about the legal document */
    if first-of(tqLegalDocumentPendVoucherLCForE.tclgd_shipfrom)
    then do:
        /* Read legal document data only when not yet done */
        if not(can-find(first tLgddDetMatForAPMERS where
                              tLgddDetMatForAPMERS.tclgd_domain   = tqLegalDocumentPendVoucherLCForE.tclgd_domain  and
                              tLgddDetMatForAPMERS.tclgd_nbr      = tqLegalDocumentPendVoucherLCForE.tclgd_nbr     and
                              tLgddDetMatForAPMERS.ttlgd_effdate  = tqLegalDocumentPendVoucherLCForE.ttlgd_effdate and
                              tLgddDetMatForAPMERS.tclgd_shipfrom = tqLegalDocumentPendVoucherLCForE.tclgd_shipfrom)) and
           not(can-find(first tLgddDetLCForAPMERS where
                              tLgddDetLCForAPMERS.tclgd_domain   = tqLegalDocumentPendVoucherLCForE.tclgd_domain  and
                              tLgddDetLCForAPMERS.tclgd_nbr      = tqLegalDocumentPendVoucherLCForE.tclgd_nbr     and
                              tLgddDetLCForAPMERS.ttlgd_effdate  = tqLegalDocumentPendVoucherLCForE.ttlgd_effdate and
                              tLgddDetLCForAPMERS.tclgd_shipfrom = tqLegalDocumentPendVoucherLCForE.tclgd_shipfrom))
        then do:
            /* instantiate method */ 
            if viBMFGLegalDocumentID = 0 or
               viBMFGLegalDocumentID = ? 
            then do:
                <I-56 {bFcStartAndOpenInstance
                     &ADD-TO-TRANSACTION   = "no"
                     &CLASS                = "BMFGLegalDocument"}>
            end.
            else if not valid-handle(vhBMFGLegalDocumentInst)
            then do:
                 <I-69 {bFcOpenInstance
                      &CLASS           = "BMFGLegalDocument"}>
            end.
    
            /* Retrieve all legal document lines for one legal document */
            <M-17 run GetLegalDocumentDetForAPMatching
               (input  tqLegalDocumentPendVoucherLCForE.tclgd_domain (icLgdDomain), 
                input  tqLegalDocumentPendVoucherLCForE.tclgd_nbr (icLgdNbr), 
                input  tqLegalDocumentPendVoucherLCForE.tclgd_shipfrom (icLgdSuppl), 
                input  tqLegalDocumentPendVoucherLCForE.ttlgd_effdate (itLgdEffDate), 
                input  ? (icInvSuppl), 
                input  ? (iiLgddLine), 
                input  ? (icLgddDocType), 
                input  ? (icLgddOrder), 
                input  ? (iiLgddOrderLine), 
                output tLgddDetMatForAPMERS (tLgddDetMatForAPM), 
                output tLgddDetLCForAPMERS (tLgddDetLCForAPM), 
                output tLgddDetLCDistForAPMERS (tLgddDetLCDistForAPM), 
                output tLgddDetTaxForAPMERS (tLgddDetTaxForAPM), 
                output viFcReturnSuper (oiReturnStatus)) in BMFGLegalDocument>
            if viFcReturnSuper < 0 or viFcReturnSuper > 0 and oiReturnStatus = 0 then assign oiReturnStatus = viFcReturnSuper.
            if oiReturnStatus < 0 then return.
        end. /* if not-can find(first tLgddDetMatForAPMERS where */

        
    
        for each tLgddDetLCForAPMERS where
                 tLgddDetLCForAPMERS.tclgd_domain   = tqLegalDocumentPendVoucherLCForE.tclgd_domain   and
                 tLgddDetLCForAPMERS.tclgd_nbr      = tqLegalDocumentPendVoucherLCForE.tclgd_nbr      and
                 tLgddDetLCForAPMERS.tclgd_shipfrom = tqLegalDocumentPendVoucherLCForE.tclgd_shipfrom and
                 tLgddDetLCForAPMERS.ttlgd_effdate  = tqLegalDocumentPendVoucherLCForE.ttlgd_effdate,
            each tLgddDetLCDistForAPMERS where
                 tLgddDetLCDistForAPMERS.tc_ParentRowid = tLgddDetLCForAPMERS.tc_Rowid:
                 
                 
            assign  vcInvoiceReference = substitute("&1,&2/&3/&4":U,
                                                    trim(tqLegalDocumentPendVoucherLCForE.tclgd_nbr),
                                                    string((year(tLgddDetLCForAPMERS.ttlgd_effdate) modulo 100), "99"),
                                                    string(month(tLgddDetLCForAPMERS.ttlgd_effdate), "99"),
                                                    string(day(tLgddDetLCForAPMERS.ttlgd_effdate), "99")).
    

            /* create record in resulting temporary table */
            create tERSProcessorRef.
            assign tERSProcessorRef.tiPvoId                        = tLgddDetLCDistForAPMERS.tiPvoId
                   tERSProcessorRef.tiPvodLineId                   = tLgddDetLCDistForAPMERS.tiPvodIdLine
                   tERSProcessorRef.tcCInvoiceCurrencyCode         = tLgddDetLCDistForAPMERS.tcpvo_curr
                   tERSProcessorRef.tcCInvoiceReference            = vcInvoiceReference
                   tERSProcessorRef.tcDomainCode                   = tLgddDetLCDistForAPMERS.tcPvoDomain
                   tERSProcessorRef.tcPurchaseOrderNbr             = tLgddDetLCForAPMERS.tclc_charge
                   tERSProcessorRef.tcReceiverNbr                  = tLgddDetLCDistForAPMERS.tcpvo_internal_ref 
                   tERSProcessorRef.tdAPMatchingLnMatchQty         = 0
                   tERSProcessorRef.tdAPMatchingLnMatchUnitPriceLC = tLgddDetLCDistForAPMERS.tdAmountLC
                   tERSProcessorRef.tdAPMLnMatchUnitPriceBaseTC    = tLgddDetLCDistForAPMERS.tdAmountBaseLC
                   tERSProcessorRef.tdAPMatchingLnMatchUnitPriceTC = tERSProcessorRef.tdAPMatchingLnMatchUnitPriceLC
                   tERSProcessorRef.tdAPMatchingLnExtendedCostLC   = tERSProcessorRef.tdAPMatchingLnMatchUnitPriceLC
                   tERSProcessorRef.tdAPMatchingLnExtendedCostTC   = tERSProcessorRef.tdAPMatchingLnMatchUnitPriceTC
                   tERSProcessorRef.tiPurchaseOrderLineNbr         = tLgddDetLCDistForAPMERS.tipvo_line
                   tERSProcessorRef.tlIsLogCharge                  = true
                   tERSProcessorRef.tlIsSelected                   = true
                   tERSProcessorRef.tlIsProcessed                  = false
                   tERSProcessorRef.tcFcRowid                      = string(tLgddDetLCForAPMERS.tdoid_lgdd_det) + '|':U + 
                                                                     string(tLgddDetLCForAPMERS.ttlgd_effdate)  + '|':U +
                                                                     tLgddDetLCDistForAPMERS.tcSupplier + '|':U +
                                                                     string(tLgddDetLCDistForAPMERS.tiPvoId)
                   tERSProcessorRef.tiERSStatus                    = tLgddDetLCDistForAPMERS.tipvo_ers_status
                   tERSProcessorRef.tiERSOpt                       = tLgddDetLCDistForAPMERS.tipvo_ers_opt
                   /* Price list is not relevant, as we are taking price from the legal document */
                   tERSProcessorRef.tiERSPriceListOption           = ?
                   tERSProcessorRef.tcLegalDocNbr                  = tLgddDetLCForAPMERS.tclgd_nbr
                   tERSProcessorRef.tcLegalDocType                 = tLgddDetLCForAPMERS.tclgd_doc_type
                   tERSProcessorRef.tcPOProjectCode                = tLgddDetLCDistForAPMERS.tcpvo_project
                   tERSProcessorRef.ttEffectiveIssueDate           = tLgddDetLCForAPMERS.ttlgd_effdate
                   tERSProcessorRef.tcSupplier                     = tLgddDetLCDistForAPMERS.tcSupplier
                   tERSProcessorRef.tcShipFrom                     = tLgddDetLCForAPMERS.tclgd_shipfrom.
                            
         
            /* ================================================================================ *
             * For logistic charges we needjust ERS Option. When the value is not stored in the *
             * pending voucher, then value is taken from the ers maintenance with following     *
             * order:                                                                           *
             *      Supplier & Site                                                             *
             *      Supplier                                                                    *
             *      Site                                                                        *
             * ================================================================================ */
            if tERSProcessorRef.tiERSOpt = ? or
               tERSProcessorRef.tiERSOpt = 0
            then do:
                assign vcSite = if (tLgddDetLCDistForAPMERS.tcpvo_order_type = {&PENDINGVOUCHER-ORDERTYPE-SO} OR
                                    tLgddDetLCDistForAPMERS.tcpvo_order_type = {&PENDINGVOUCHER-ORDERTYPE-DO}) 
                                then tLgddDetLCDistForAPMERS.tcpvo_shipfrom
                                else tLgddDetLCDistForAPMERS.tcpvo_shipto.
    
                <M-35 run GetERSPendingVouchersERSOpt
                   (input  tERSProcessorRef.tcSupplier (icCreditorCode), 
                    input  vcSite (icSiteCode), 
                    input  ? (icPartCode), 
                    input-output tERSProcessorRef.tiERSOpt (biERSOption), 
                    input-output viDummy (biERSPriceListOption), 
                    output viLocalReturn (oiReturnStatus)) in BERSProcessor>
            end. /* if tERSProcessorRef.tiERSOpt = ? or */
             
            /* if any error occured during processing of receipt -> remove it from processing */
            if viLocalReturn < 0 then assign tERSProcessorRef.tiERSStatus = {&PVO_ERS_STATUS_ERROR_PROCESS}.
    
            /* should be this receipt processed by ERS */
            if tERSProcessorRef.tiERSOpt = 0 or   /* 0 - should not be, but for sure */
               tERSProcessorRef.tiERSOpt = 1      /* 1 - NO ERS Process allowed      */
            then do:
                delete tERSProcessorRef.
                empty temp-table tFcMessages.
            end.
            else do:
                <M-62 run CopyToReceiptErrors
                   (input  tERSProcessorRef.tcFcRowid (icReceiptRowId), 
                    input  true (ilDeleteSystemErrors), 
                    output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
                if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
                if viFcReturnSuper <  0 then return.
            end.
        end. /* for each tLgddDetLCForAPMERS where */
    end. /* if first-of(tqLegalDocumentPendVoucherLCForE.tclgd_shipfrom) */
end. /* for each tqLegalDocumentPendVoucherLCForE */