project QadFinancials > class BCPay > method ApiCreateCPayRecords

Description

Create CPay Records based on temp table


Parameters


tAPICPayinputtemp-table
ilClearDatainputlogicalClear the Data : pass true in case you want BCPay to start from scratch
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCDocument.AdditionalUpdatesPosting


program code (program9/bcpay.p)

/* first clear the instance, otherwise problems when you execute it twice */
if ilClearData
then do :
    <M-9 run ClearData (output oiReturnStatus (oiReturnStatus)) in BCPay>
    if oiReturnStatus < 0 then return.
end.

/* replace unknown values */
find first tAPICPay no-error.
if not available tAPICPay
then do:
    assign vcMessage      = trim(#T-10'No input record was found. You must define for which records you want to create supplier payments.':255(1418)t-10#)
           oiReturnStatus = -1.
    <M-8 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1387':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BCPay>
    return.
end.

assign vcDOCUMENTSTATUSCREDITORS = {&DOCUMENTSTATUSCREDITORS}
       vcPAYTYPECODESCREDITOR    = {&PAYTYPECODESCREDITOR}.

for each tAPICPay no-lock:
    /* CPayTypeCode must be creditor payment or bank entry */
    assign vlFound = false.
    do viCounter = num-entries(vcPAYTYPECODESCREDITOR, chr(2)) to 2 by -1 :
         if tAPICPay.CPayTypeCode = entry(viCounter,vcPAYTYPECODESCREDITOR,chr(2)) 
         then do:
             assign vlFound = true.
             leave.
         end.
    end.
    
    if not vlFound
    then do viCounter = num-entries(vcDOCUMENTSTATUSCREDITORS, chr(2)) to 2 by -1:
        if tAPICPay.CPayTypeCode = entry(viCounter, vcDOCUMENTSTATUSCREDITORS, chr(2))
        then do:
            assign vlFound = true.
            leave.
        end.
    end.
    
    if not vlFound
    then do:
        assign vcMessage      = trim(substitute(#T-11'The supplier payment type must be a valid payment status or one of the following types: &1 or &2.':150(1419)t-11#,{&PAYTYPECODE-CREDPAY-TR},{&PAYTYPECODE-BANKENTRY-TR}))
               oiReturnStatus = -1.
        <M-1 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1386':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BCPay>
        return.
    end.
    
    
    /* create CPay - a link between PostingLine and CInvoice */
    <M-3 run AddDetailLine (input  'CPay':U (icTable), 
                            input  '':U (icParentRowid), 
                            output viFcReturnSuper (oiReturnStatus)) in BCPay>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
    then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.
    
    assign tCPay.CInvoice_ID    = tAPICPay.CInvoice_ID
           tCPay.PostingLine_ID = tAPICPay.PostingLine_ID
           tCPay.PaySelLine_ID  = tAPICPay.PaySelLine_ID
           tCPay.CPayTypeCode   = tAPICPay.CPayTypeCode.
end.

/* validate */
<M-5 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BCPay>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

/* additional updates */
<M-6 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BCPay>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

/* save */
<M-7 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BCPay>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.


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 = "BCPay".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiCreateCPayRecords".
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/bcpay.apicreatecpayrecords.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::ilClearData = <parameter value>.

vhParameter = vhInputDS:get-buffer-handle("tAPICPay").
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.