project QadFinancials > class BAPMatching > method ApiGetMatchingInfoMulti

Description

This method returns APMatching information for mutliple purchase order receipts. It is primarily aimed at the PO Unvourched receipt program. It takes input parameters that are used to start the query at prh_hist


Parameters


icDomainCodeinputcharacter
icSupplierCodeFrominputcharacter
icSupplierCodeToinputcharacter
icItemFrominputcharacter
icItemToinputcharacter
itEffectiveDateinputdate
itReceiptsFromDateinputdate
icSiteFrominputcharacter
icSiteToinputcharacter
icPoSiteFrominputcharacter
icPoSiteToinputcharacter
ilSelectInventoryItemsinputlogical
ilSelectSubcontractItemsinputlogical
ilSelectMemoItemsinputlogical
icReportCurrencyinputcharacter
tAPMatchingInfooutputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/bapmatching.p)

assign oiReturnStatus = -98.
    empty temp-table tAPMatchingInfo.   

    if icDomainCode = "" or icDomainCode = ?
    then do:
        assign oiReturnStatus = -1
               vcMessage      = #T-14'You must specify a domain code.':100(4240)T-14#.
               <M-15 run SetMessage
                  (input  vcMessage (icMessage), 
                   input  '' (icArguments), 
                   input  '' (icFieldName), 
                   input  '' (icFieldValue), 
                   input  'E' (icType), 
                   input  '2' (iiSeverity), 
                   input  '' (icRowid), 
                   input  'QadFin-9036':U (icFcMsgNumber), 
                   input  '' (icFcExplanation), 
                   input  '' (icFcIdentification), 
                   input  '' (icFcContext), 
                   output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
                   return.

    end. /* if icDomainCode = "" or icDomainCode = ? */
    
    <Q-13 run PurchaseReceiptHistoryForMatching (all) (Read) (NoCache)
       (input ?, (CompanyId)
        input icDomainCode, (domain)
        input icSupplierCodeFrom, (SupplierCodeFrom)
        input itEffectiveDate, (EffectiveDate)
        input icItemFrom, (PartFrom)
        input icItemTo, (PartTo)
        input icSupplierCodeTo, (SupplierCodeTo)
        input itReceiptsFromDate, (ReceiptsFromDate)
        input icPoSiteFrom, (PoSiteFrom)
        input icPoSiteTo, (PoSiteTo)
        input ilSelectInventoryItems, (SelectInventoryItems)
        input ilSelectSubcontractItems, (SelectSubcontractItems)
        input ilSelectMemoItems, (SelectMemoItems)
        input icReportCurrency, (ReportCurrency)
        input icSiteFrom, (siteFrom)
        input icSiteTo, (siteTo)
        input '01', (OrderType)
        input '07', (InternalReferenceType)
        output dataset tqPurchaseReceiptHistoryForMatch) in BMfgPOReceipt >
        /* Copy retrieved data to resulting temp-table - only create a single output record for every APMatchingLn */
        
   for each tqPurchaseReceiptHistoryForMatch
        break by tqPurchaseReceiptHistoryForMatch.tiAPMatchingLn_ID :
        
        /* create an output record once for every APMatchingLn */
        if first-of (tqPurchaseReceiptHistoryForMatch.tiAPMatchingLn_ID)
        then do :
            create tAPMatchingInfo.
            buffer-copy tqPurchaseReceiptHistoryForMatch 
                        to tAPMatchingInfo
            assign 
                tAPMatchingInfo.tdAPMatchingLnReceiptTaxLC   = 0
                tAPMatchingInfo.tdAPMatchingLnReceiptTaxTC   = 0
                tAPMatchingInfo.tlAPMatchingLnIsPvodFinished = tqPurchaseReceiptHistoryForMatch.tlAPMatchingLnIsPvodFinished.               
        end. /* if first-of (tqPurchaseReceiptForMatching.tiAPMatchingLn_ID) */
        
        /* Check the cancelled AP matchings and age them using the effective date.     */
        /* If the cancelation occurs after the effective date then set the AP Matching */
        /* record to use the finished status.                                          */
        if tAPMatchingInfo.tcAPMatchingStatus = {&APMATCHINGSTATUS-CANCEL}
        then do:
            /* Check to see if the query has been started. If not, start the query. */
            if vlAPMatchingQueryStart = false
            then do:
                <Q-16 run APMatchingLnForPostingJournal  (Start) in BAPMatching >
                assign vlAPMatchingQueryStart = true.
            end. /* if vlAPMatchingQueryStart = false */
            
            <Q-17 run APMatchingLnForPostingJournal (all) (Read) (NoCache)
               (input viCompanyId, (CompanyId)
                input tqPurchaseReceiptHistoryForMatch.tiAPMatchingLn_ID, (ApMatchingLnID)
                output dataset tqAPMatchingLnForPostingJournal) in BAPMatching >

            find first tqAPMatchingLnForPostingJournal
            no-lock no-error.
            if available tqAPMatchingLnForPostingJournal
            then do:
                assign vcPostingOriginatorReference = substitute("&1/&2/&3":U,
                                                      string(tqAPMatchingLnForPostingJournal.tiPostingYear,"9999":U),
                                                      tqAPMatchingLnForPostingJournal.tcJournalCode,
                                                      string(tqAPMatchingLnForPostingJournal.tiPostingVoucher,"999999999":U)).
                /* Check to see if the query has been started. If not, start the query. */
                if vlPostingByReverseOriginRefStrt = false
                then do:
                    <Q-28 run PostingByReverseOriginatorRef  (Start) in BPosting >
                    assign vlPostingByReverseOriginRefStrt = true.
                end. /* if vlPostingByReverseOriginRefStrt */
                
                <Q-19 run PostingByReverseOriginatorRef (all) (Read) (NoCache)
                   (input viCompanyId, (CompanyId)
                    input vcPostingOriginatorReference, (PostingOriginatorReference)
                    input FALSE, (PostingIsReplacement)
                    input TRUE, (PostingIsReversing)
                    input '':U, (SkipRowid)
                    output dataset tqPostingByReverseOriginatorRef) in BPosting >
                    
                find first tqPostingByReverseOriginatorRef where
                           tqPostingByReverseOriginatorRef.tcPostingOriginatorReference = vcPostingOriginatorReference
                no-lock no-error.
                if available tqPostingByReverseOriginatorRef and 
                             tqPostingByReverseOriginatorRef.ttPostingDate > itEffectiveDate
                then do:
                    assign tAPMatchingInfo.tcAPMatchingStatus = {&APMATCHINGSTATUS-FINISHED}.
                end. /* if available tqPostingByReverseOriginatorRef */
            end.     /* if available tqAPMatchingLnForPostingForJourn */
        end.         /* if tqPurchaseReceiptHistoryForMatch.tcAPMatchingStatus = {&APMATCHINGSTATUS-CANCEL} */
        
        /* Sum the ReceiptTaxTC */
        assign tAPMatchingInfo.tdAPMatchingLnReceiptTaxTC = tAPMatchingInfo.tdAPMatchingLnReceiptTaxTC + 
                                                            tqPurchaseReceiptHistoryForMatch.tdAPMatchingLnTaxARRecTaxTC + 
                                                            tqPurchaseReceiptHistoryForMatch.tdAPMatchingLnTaxARNRecTaxTC. 
        
        /* State the ReceiptTaxLC based upon the ReceiptTaxTC and the LC-TC ratio */
        if last-of (tqPurchaseReceiptHistoryForMatch.tiAPMatchingLn_ID)
        then assign tAPMatchingInfo.tdAPMatchingLnReceiptTaxLC = <M-3 RoundAmount
                                                                    (input  tAPMatchingInfo.tdAPMatchingLnReceiptTaxTC * tAPMatchingInfo.tdAPMatchingLnReceiptAmtLC / tAPMatchingInfo.tdAPMatchingLnReceiptAmtTC (idUnroundedAmount), 
                                                                     input  ? (iiCurrencyID), 
                                                                     input  tAPMatchingInfo.tcCurrencyCode (icCurrencyCode)) in BAPMatching>.
        
    end. /* for each tqPurchaseReceiptForMatching */  
        
        
    /* Stop the queries */
    if vlPostingByReverseOriginRefStrt = true
    then do:
        <Q-23 run PostingByReverseOriginatorRef  (Stop) in BPosting >
    end. /* if vlPostingByReverseOriginRefStrt = true */
    
    if vlAPMatchingQueryStart = true
    then do:
        <Q-24 run APMatchingLnForPostingJournal  (Stop) in BAPMatching >
    end. /* if vlAPMatchingQueryStart = true */
        

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


Sample code: how to call this method through RPCRequestService (QXtend Inbound)

define temp-table ttContext no-undo
    field propertyQualifier as character
    field propertyName as character
    field propertyValue as character
    index entityContext is primary unique
        propertyQualifier
        propertyName
    index propertyQualifier
        propertyQualifier.

define dataset dsContext for ttContext.

define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.

/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
       ttContext.propertyValue = "BAPMatching".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiGetMatchingInfoMulti".
create ttContext.
assign ttContext.propertyName = "applicationId"
       ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
       ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
       ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
       ttContext.propertyValue = "".

/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bapmatching.apigetmatchinginfomulti.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icDomainCode = <parameter value>
       vhParameter::icSupplierCodeFrom = <parameter value>
       vhParameter::icSupplierCodeTo = <parameter value>
       vhParameter::icItemFrom = <parameter value>
       vhParameter::icItemTo = <parameter value>
       vhParameter::itEffectiveDate = <parameter value>
       vhParameter::itReceiptsFromDate = <parameter value>
       vhParameter::icSiteFrom = <parameter value>
       vhParameter::icSiteTo = <parameter value>
       vhParameter::icPoSiteFrom = <parameter value>
       vhParameter::icPoSiteTo = <parameter value>
       vhParameter::ilSelectInventoryItems = <parameter value>
       vhParameter::ilSelectSubcontractItems = <parameter value>
       vhParameter::ilSelectMemoItems = <parameter value>
       vhParameter::icReportCurrency = <parameter value>.

/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").

if not vhServer:connected()
then do:
    message "Could not connect AppServer" view-as alert-box error title "Error".
    return.
end.

/* Run */
assign vhContextDS = dataset dsContext:handle.

run program/rpcrequestservice.p on vhServer
    (input-output dataset-handle vhContextDS by-reference,
           output dataset-handle vhExceptionDS,
     input        dataset-handle vhInputDS by-reference,
     input-output dataset-handle vhInputOutputDS by-reference,
           output dataset-handle vhOutputDS).

/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).

if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).

/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.

if valid-handle(vhInputDS)
then delete object vhInputDS.

if valid-handle(vhOutputDS)
then delete object vhOutputDS.

if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.