project QadFinancials > class BCPay > method ApiCreateCPay
Description
APICreateCPay
Parameters
iiCInvoice_ID | input | integer | CInvoice_ID |
iiPostingLine_ID | input | integer | PostingLine_ID |
icCPayTypeCode | input | character | CPayTypeCode |
iiPaySelLine_ID | input | integer | |
ilClearData | input | logical | Clear Data : pass true in case you want BCPay to start from scratch |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bcpay.p)
/* replace unknown values */
if iiCInvoice_ID = ? then assign iiCInvoice_ID = 0.
if ilClearData = ? then assign ilClearData = false.
/* CPayTypeCode must be creditor payment or bank entry */
assign vlFound = false.
do viCounter = num-entries({&PAYTYPECODESCREDITOR}, chr(2)) to 2 by -1 :
if icCPayTypeCode = entry(viCounter,{&PAYTYPECODESCREDITOR},chr(2))
then do:
assign vlFound = true.
leave.
end.
end.
if not vlFound
then do viCounter = num-entries({&DOCUMENTSTATUSCREDITORS}, chr(2)) to 2 by -1:
if icCPayTypeCode = entry(viCounter, {&DOCUMENTSTATUSCREDITORS}, chr(2))
then do:
assign vlFound = true.
leave.
end.
end.
if not vlFound
then do:
assign vcMessage = trim(substitute(#T-9'The supplier payment type must be a valid payment status or one of the following types: &1 or &2.':150(1419)t-9#,{&PAYTYPECODE-CREDPAY-TR},{&PAYTYPECODE-BANKENTRY-TR}))
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-1169':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCPay>
return.
end.
/* first clear the instance, otherwise problems when you execute it twice */
if ilClearData
then do :
<M-7 run ClearData (output oiReturnStatus (oiReturnStatus)) in BCPay>
if oiReturnStatus < 0 then return.
end.
/* create CPay - a link between PostingLine and CInvoice */
<M-6 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 = iiCInvoice_ID
tCPay.PostingLine_ID = iiPostingLine_ID
tCPay.PaySelLine_ID = iiPaySelLine_ID
tCPay.CPayTypeCode = icCPayTypeCode.
/* validate */
<M-1 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-2 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-3 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 = "ApiCreateCPay".
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.apicreatecpay.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::iiCInvoice_ID = <parameter value>
vhParameter::iiPostingLine_ID = <parameter value>
vhParameter::icCPayTypeCode = <parameter value>
vhParameter::iiPaySelLine_ID = <parameter value>
vhParameter::ilClearData = <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.