project QadFinancials > class BCInvoice > method ApiSelectCInvoiceByPayRef

API query

Description

Query procedure to select invoices by a payment reference - this payment reference is transformed into a number of different filters on the standard SelectCInvoice query


Parameters


tFilterinputtemp-table
tqApiSelectCInvoiceByPayRefoutputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program6/bcinvoice.p)

/* Set up the filters for normal and staged payments and run the query for normal then staged */
assign 
    vcPaymentAmount = "":U
    vdPaymentAmount = ?
    vlNormalPaymentTypeOnly = false
    vlStagedPaymentTypeOnly  = false.
    
empty temp-table tApiSelectCInvoiceByPayRef.
empty temp-table tqApiSelectCInvoiceByPayRef.

/* has the user specified a specific payment type? */
find first tFilter where tFilter.tcBusinessFieldName  = "tPaymentCondition.PaymentConditionPaymentTyp" no-error.

if available tFilter 
then do:
    if tFilter.tcParameterValue = {&PAYMENTCONDITIONPAYMENTTYPE-NORMAL} then
        assign 
            vlNormalPaymentTypeOnly = true
            vlStagedPaymentTypeOnly = false.   
    if tFilter.tcParameterValue = {&PAYMENTCONDITIONPAYMENTTYPE-STAGED} then
        assign 
            vlNormalPaymentTypeOnly = false
            vlStagedPaymentTypeOnly  = true.                                 
end. /* if available tFilter */
else do:
/* if none is specified, then we'll first retrieve the normal payments then afterwards the staged */
    create tFilter.
    assign 
        tFilter.tcBusinessFieldName  = "tPaymentCondition.PaymentConditionPaymentTyp":U
        tFilter.tcDataType = "c":U
        tFilter.tcOperator = "=":U
        tFilter.tcParameterValue = {&PAYMENTCONDITIONPAYMENTTYPE-NORMAL}.
end. /* else do */        

find first tFilter where tFilter.tcBusinessFieldName  = "tCInvoice.CInvoiceBalanceTC" no-error.
if available tFilter
then do:
    assign 
        vcPaymentAmount = tFilter.tcParameterValue   
        vdPaymentAmount   = decimal(vcPaymentAmount) no-error.
        if error-status:error
            then assign vdPaymentAmount = ?.                    
end. /* if available tFilter */    

/* remove the invoice stage due date from this query - as we only want to work from the 
   invoice due date - which we will rename to use for the staged query later */
find first tFilter where tFilter.tcBusinessFieldName  = "tCInvoiceStage.CInvoiceStageDueDate" no-error.
if available tFilter
then delete tFilter.    
   
    
assign viSeq = 0.

if not vlStagedPaymentTypeOnly 
then do:   
    find first tFilter where tFilter.tcBusinessFieldName  = "tPaymentCondition.PaymentConditionPaymentTyp" no-error.
    if available tFilter
    then assign tFilter.tcParameterValue = {&PAYMENTCONDITIONPAYMENTTYPE-NORMAL}.        
        
    find first tFilter where tFilter.tcBusinessFieldName  = "tCInvoiceStage.CInvoiceStageAmountTC" no-error.
    if available tFilter
    then do:
        delete tFilter.
    end. /* if available */        
    find first tFilter where tFilter.tcBusinessFieldName  = "tCInvoice.CInvoiceBalanceTC" no-error.
    if available tFilter
    then do:
        assign             
            tFilter.tcParameterValue = "-" + vcPaymentAmount.
    end. /* if available tFilter */ 
    
    <Q-2 run api/bcinvoice/selectcinvoiceopen.p
       (input  ? (icApiLogin), 
        input  ? (icApiPassword), 
        input  ? (icApiExtra), 
        input  viSessionID (iiApiSessionId), 
        input  'A' (icRange), 
        input  ? (icRowid), 
        input  0 (iiRowNum), 
        input  0 (iiNumber), 
        input  '' (icSortColumns), 
        input  false (ilCountOnly), 
        input  true (ilForwardRead), 
        input  50000 (iiMaximumBrowseRecordsToCount), 
        input  dataset tFilter (izFilterDS), 
        output viDummy (oiCount), 
        output vlDummy (olEndOfQuery), 
        output dataset tApiSelectCInvoiceByPayRef (ozResultsetDS), 
        output dataset tFcMessages (ozFcMessagesDS), 
        output oiReturnStatus (oiReturnStatus))>

    for each tApiSelectCInvoiceByPayRef by tApiSelectCInvoiceByPayRef.ti_sequence:
        create tqApiSelectCInvoiceByPayRef.
        buffer-copy tApiSelectCInvoiceByPayRef to tqApiSelectCInvoiceByPayRef.
        assign 
            viSeq = viSeq + 1
            tqApiSelectCInvoiceByPayRef.ti_sequence = viSeq.    
    end. /* for each */
end. /* if not vlStagedPaymentTypeOnly */


if not vlNormalPaymentTypeOnly 
then do:   
    empty temp-table tApiSelectCInvoiceByPayRef.
    
    find first tFilter where tFilter.tcBusinessFieldName  = "tPaymentCondition.PaymentConditionPaymentTyp" no-error.
    if available tFilter
    then assign tFilter.tcParameterValue = {&PAYMENTCONDITIONPAYMENTTYPE-STAGED}.
        
    find first tFilter where tFilter.tcBusinessFieldName  = "tCInvoice.CInvoiceBalanceTC" no-error.
    if available tFilter
    then delete tFilter.    
    
    if vcPaymentAmount <> ""
    then do:
       find first tFilter where tFilter.tcBusinessFieldName  = "tCInvoiceStage.CInvoiceStageAmountTC" no-error.
       if not available tFilter
       then do:
            create tFilter.
            assign 
                tFilter.tcBusinessFieldName  = "tCInvoiceStage.CInvoiceStageAmountTC":U           
                tFilter.tcDataType = "d":U
                tFilter.tcOperator = "<=":U.
        end. /* if not available */                
        assign tFilter.tcParameterValue = vcPaymentAmount.                                    
    end. /* if vdPaymentAmount */
    
    /* Use the Invoice due date filter for the stage due date filter */
    find first tFilter where tFilter.tcBusinessFieldName  = "tCInvoice.CInvoiceDueDate" no-error.
    if available tFilter  
    then do:    
         assign tFilter.tcBusinessFieldName  = "tCInvoiceStage.CInvoiceStageDueDate":U.                     
    end.    
 
    <Q-16 run api/bcinvoice/selectcinvoicestagedopen.p
       (input  ? (icApiLogin), 
        input  ? (icApiPassword), 
        input  ? (icApiExtra), 
        input  viSessionID (iiApiSessionId), 
        input  'A' (icRange), 
        input  ? (icRowid), 
        input  0 (iiRowNum), 
        input  0 (iiNumber), 
        input  '' (icSortColumns), 
        input  false (ilCountOnly), 
        input  true (ilForwardRead), 
        input  50000 (iiMaximumBrowseRecordsToCount), 
        input  dataset tFilter (izFilterDS), 
        output viDummy (oiCount), 
        output vlDummy (olEndOfQuery), 
        output dataset tApiSelectCInvoiceByPayRef (ozResultsetDS), 
        output dataset tFcMessages (ozFcMessagesDS), 
        output oiReturnStatus (oiReturnStatus))>

    for each tApiSelectCInvoiceByPayRef by tApiSelectCInvoiceByPayRef.ti_sequence:        
        if (tApiSelectCInvoiceByPayRef.tdAbsoluteBalanceTC = vdPaymentAmount or vdPaymentAmount = ?)
        then do:
            create tqApiSelectCInvoiceByPayRef.
            buffer-copy tApiSelectCInvoiceByPayRef to tqApiSelectCInvoiceByPayRef.
            assign 
                viSeq = viSeq + 1
                tqApiSelectCInvoiceByPayRef.ti_sequence = viSeq.           
        end. /* if tApiSelectCInvoiceByPayRef.tdAbsoluteBalanceTC = vcPaymentAmount */            
    end. /* for each */
end. /* if not vlNormalPaymentTypeOnly */


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 = "BCInvoice".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiSelectCInvoiceByPayRef".
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/bcinvoice.apiselectcinvoicebypayref.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tFilter").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

/* 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.