project QadFinancials > class BDebtor > method ApiGetCreditDataV01
Description
This API method holds the main logic for returning credit data for a given customer.
Parameters
icDebtorCode | input | character | |
icCurrencyCode | input | character | |
odFixedCreditLimit | output | decimal | |
odTurnoverCreditLimit | output | decimal | |
odARBalance | output | decimal | |
odOpenOrdersBalance | output | decimal | |
olCustomerOnCreditHold | output | logical | |
ocCreditRating | output | character | |
ilincludeSalesOrder | input | logical | Input parameter to indicate whether or not open sales orders should be included with the credit information or whether the customer's credit settings should determine if the sales orders are included. |
ilincludeOpenItems | input | logical | Input parameter to indicate whether or not open items should be included with the credit information or whether the customer's credit settings should determine if the open items are included. |
ilincludeDrafts | input | logical | Input parameter to indicate whether or not drafts should be included with the credit information or whether the customer's credit settings should determine if the drafts are included. |
odDraftBalance | output | decimal | Output paramter that holds the draft balance. |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bdebtor.p)
assign
odFixedCreditLimit = 0
odTurnoverCreditLimit = 0
odARBalance = 0
odOpenOrdersBalance = 0
olCustomerOnCreditHold = false
ocCreditRating = "":U
oiReturnStatus = -98.
<Q-57 run DebtorByCreditLimitInfo (all) (Read) (NoCache)
(input viCompanyID, (CompanyId)
input ?, (DebtorId)
input icDebtorCode, (DebtorCode)
output dataset tqDebtorByCreditLimitInfo) in BDebtor >
for first tqDebtorByCreditLimitInfo
where tqDebtorByCreditLimitInfo.tcDebtorCode = icDebtorCode:
assign
odFixedCreditLimit = if tqDebtorByCreditLimitInfo.tlDebtorIsFixedCredLim
then tqDebtorByCreditLimitInfo.tdDebtorFixedCredLimTC
else 0
olCustomerOnCreditHold = tqDebtorByCreditLimitInfo.tlDebtorIsLockedCredLim
ocCreditRating = tqDebtorByCreditLimitInfo.TCDEBTORCREDITRATINGCODE.
/* Need to provide Open Amount as the reporting currency */
if odFixedCreditLimit > 0
then do:
<M-62 run GetCurrencyAmount
(input tqDebtorByCreditLimitInfo.tcCurrencyCode (icCurrencyFrom),
input icCurrencyCode (icCurrencyTo),
input tqDebtorByCreditLimitInfo.tdDebtorFixedCredLimTC (idAmount),
output odFixedCreditLimit (odAmount),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end.
/* Whether or not the open sales orders, drafts or open AR items are included */
/* in the credit data is controled via three logical input parameters. These */
/* parameters are used to decided which of the three document types should */
/* always be included or whether the customer credit settings should determine */
/* if the documents should be included. */
if ilincludeSalesOrder = true
then assign vlincludeSalesOrders = true.
else assign vlincludeSalesOrders = tqDebtorByCreditLimitInfo.tlDebtorIsInclSOCredLim.
if ilincludeOpenItems = true
then assign vlincludeOpenItems = true.
else assign vlincludeOpenItems = tqDebtorByCreditLimitInfo.tlDebtorIsInclOpenItmCredLim.
if ilincludeDrafts = true
then assign vlincludeDrafts = true.
else assign vlincludeDrafts = tqDebtorByCreditLimitInfo.tlDebtorIsInclDraftCredLim.
<M-25 run CalculateBalances
(input tqDebtorByCreditLimitInfo.tiDebtor_ID (iiDebtorId),
input tqDebtorByCreditLimitInfo.tcDebtorCode (icDebtorCode),
input tqDebtorByCreditLimitInfo.tcCurrencyCode (icCurrencyCode),
input vlincludeSalesOrders (ilSalesOrders),
input vlincludeOpenItems (ilOpenItems),
input vlincludeDrafts (ilDrafts),
input tqDebtorByCreditLimitInfo.tlDebtorIsTurnOverCredLim (ilCreditOnTurnover),
input tqDebtorByCreditLimitInfo.tdDebtorPercTurnOverCredLim (idPercentageOfTurnover),
output vdSOBalance (odSOBalance),
output vdOIBalance (odOIBalance),
output vdDraftBalance (odDraftBalance),
output vdCreditOnTurnOver (odCreditOnTurnover),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
assign
odDraftBalance = vdDraftBalance
odOpenOrdersBalance = vdSOBalance
odARBalance = vdOIBalance.
/* If the open AR balance is greater than 0, then convert to the required currency */
if(odARBalance <> 0 )
then do:
<M-19 run GetCurrencyAmount
(input tqDebtorByCreditLimitInfo.tcCurrencyCode (icCurrencyFrom),
input icCurrencyCode (icCurrencyTo),
input vdOIBalance (idAmount),
output odARBalance (odAmount),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end. /* positive odARBalance */
/* Convert the draft balance to the required currency */
<M-22 run GetCurrencyAmount
(input tqDebtorByCreditLimitInfo.tcCurrencyCode (icCurrencyFrom),
input icCurrencyCode (icCurrencyTo),
input vdDraftBalance (idAmount),
output odDraftBalance (odAmount),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
/* Convert the Open Order amount to the required currency */
<M-12 run GetCurrencyAmount
(input tqDebtorByCreditLimitInfo.tcCurrencyCode (icCurrencyFrom),
input icCurrencyCode (icCurrencyTo),
input vdSOBalance (idAmount),
output odOpenOrdersBalance (odAmount),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
if vdCreditOnTurnOver > 0
then do:
<M-34 run GetCurrencyAmount
(input tqDebtorByCreditLimitInfo.tcCurrencyCode (icCurrencyFrom),
input icCurrencyCode (icCurrencyTo),
input vdCreditOnTurnOver (idAmount),
output odTurnoverCreditLimit (odAmount),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end.
end. /* end tqDebtorByCreditLimitInfo */
if not available(tqDebtorByCreditLimitInfo)
then do:
assign
vcMessageText = trim(#T-4'The specified customer $1 is not defined in the system or is invalid.':255(69145)T-4#).
oiReturnStatus = -1.
<M-14 run SetMessage
(input vcMessageText (icMessage),
input icDebtorCode (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-867183':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
end. /* end no customer found */
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 = "BDebtor".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiGetCreditDataV01".
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/bdebtor.apigetcreditdatav01.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icDebtorCode = <parameter value>
vhParameter::icCurrencyCode = <parameter value>
vhParameter::ilincludeSalesOrder = <parameter value>
vhParameter::ilincludeOpenItems = <parameter value>
vhParameter::ilincludeDrafts = <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.