Description
This method returns the proposed payment selection lines (the information of these lines come from the invoice).
The input values can be used to drive and limited the returned values.
Parameters
ilIsInitialLoad | input | logical | IsInitialLoad |
iiBankPayFormatID | input | integer | |
ilShowAll | input | logical | ShowAll |
itDueDate | input | date | DueDate |
icPaymentSelectionDue | input | character | PaymentSelectionDue |
icCurrencyCode | input | character | Currency Code |
icDivisionCode | input | character | Sub-Account Code |
icCountryCode | input | character | BusinessRelationCountryCode |
icBusinessRelationCode | input | character | Business Relation Code |
icFromBusinessRelationCode | input | character | From BusinessRelationCode |
icToBusinessRelationCode | input | character | To BusinessRelationCode |
icBusinessRelationType | input | character | BusinessRelationType |
ilBusinessRelationIsInterco | input | logical | Business Relation Interco |
icPaymentGroupCode | input | character | Payment Group Code |
icCorporateGroupCode | input | character | |
ilAllEntities | input | logical | |
ilIsWithBank | input | logical | |
iiPaySelID | input | integer | |
itPaySelDate | input | date | PaySelDate |
icPaySelCurrCode | input | character | PaySelCurrCode |
iiMaxNumberOfLinesToReturn | input | integer | MaxNumberOfLinesToReturn: If this parameter is filled (meaning it is not zero and not null) then the output parameter tProposedLine will not contain more lines than the number filled in here |
iiCInvoiceID | input | integer | If this parameter is filled then this indicates only the data of a single CInvoice needs to be retrived |
icBankNumberFormatted | input | character | Formatted bank number |
icPaymentReference | input | character | Payment Reference |
tProposedLine | output | temp-table | Proposed Line |
tProposedLineStage | output | temp-table | Temp-table holding the Stage details of tProposedLine |
itDisCountRefDueDate | input | date | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bpaymentselection.p)
/* ========================= */
/* Set default return status */
/* Start Block */
/* ========================= */
assign oiReturnStatus = -98
viLocalReturn = 0.
MAINAPIPROCESSINGBLOCK: DO :
/* ======================== */
/* Clear the output tables */
/* Set initial values */
/* ======================== */
empty temp-table tProposedLine.
empty temp-table tProposedLineStage.
assign viNumberOfAdditions = viNumberOfAdditions + 1 /* Data-item on class level */
icBusinessRelationType = {&PAYMENTSELECTIONRELATION-CREDITOR}. /* Only handle the supplier side for now */
/* ============================================================= */
/* Validate/Normalise/Convert version-spepcific input parameters */
/* ============================================================= */
if icFromBusinessRelationCode <> "":U and
icFromBusinessRelationCode <> ? and
icFromBusinessRelationCode = icToBusinessRelationCode and
(icBusinessRelationCode = "":U or
icBusinessRelationCode = ?)
then assign icBusinessRelationCode = icFromBusinessRelationCode.
if icFromBusinessRelationCode <> "":U and
icFromBusinessRelationCode <> ? and
icToBusinessRelationCode <> "":U and
icToBusinessRelationCode <> ? and
icFromBusinessRelationCode > icToBusinessRelationCode
then do :
assign vcMessage = trim(substitute(#T-22'To-Business-Relation (&2) cannot precede From-Business-Relation (&1).':255(27495021)T-22#,icFromBusinessRelationCode,icToBusinessRelationCode))
viLocalReturn = -1.
<M-28 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'qadfin-137183':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
Leave MAINAPIPROCESSINGBLOCK.
end. /* if icFromBusinessRelationCode <> "":U and */
if iiMaxNumberOfLinesToReturn = ?
then assign iiMaxNumberOfLinesToReturn = 0.
/* ======================================================================================================================= */
/* Parameter ilIsInitialLoad is only true when you open an existing Supplier Payment Selection so the existing PaySelLines */
/* are returned without having the user to press the search-btn on the filter-area */
/* Parameter ilIsInitialLoad is false in all other cases: this is when the user pressed the search-btn on the filter-area. */
/* ======================================================================================================================= */
if ilIsInitialLoad = true
then do:
<M-3 run GetToPayObjectsInitLoadFromInst
(input iiPaySelID (iiPaySel_ID),
input icPaySelCurrCode (icPaySelCurrCode),
input itPaySelDate (itPaySelDate),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
end. /* if ilIsInitialLoad = true */
else do:
/* Creditor */
if icBusinessRelationType = {&PAYMENTSELECTIONRELATION-CREDITOR} or
icBusinessRelationType = ? or
icBusinessRelationType = "":U
then do:
<M-5 run GetToPayObjectsForCInvoice
(input icPaymentSelectionDue (icPaymentSelectionDue),
input ilShowAll (ilShowAll),
input itDueDate (itDueDate),
input icCurrencyCode (icCurrencyCode),
input icDivisionCode (icDivisionCode),
input icBusinessRelationCode (icBusinessRelationCode),
input icFromBusinessRelationCode (icFromBusinessRelationCode),
input icToBusinessRelationCode (icToBusinessRelationCode),
input ilBusinessRelationIsInterco (ilBusinessRelationIsInterco),
input icPaymentGroupCode (icPaymentGroupCode),
input icCountryCode (icCountryCode),
input itPaySelDate (itPaySelDate),
input if ilIsWithBank then iiBankPayFormatId else ? (iiBankPayFormatID),
input ilAllEntities (ilAllEntities),
input ilIsWithBank (ilIsWithBanks),
input icCorporateGroupCode (icCorporateGroupCode),
input iiMaxNumberOfLinesToReturn (iiMaxNumberOfLinesToReturn),
input iiCInvoiceID (iiCInvoiceID),
input iiPaySelID (iiPaySel_ID),
input icBankNumberFormatted (icBankNumberFormatted),
input icPaymentReference (icPaymentReference),
input itDisCountRefDueDate (itDisCountRefDueDate),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper <> 0
then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave MAINAPIPROCESSINGBLOCK.
end. /* if icBusinessRelationType = {&PAYMENTSELECTIONRELATION-CREDITOR} or */
end. /* Not if ilIsInitialLoad = true */
/* ====================================================================== */
/* Indicate for all lines if there are multiple lines for the same object */
/* ====================================================================== */
for each tProposedLine
group by tProposedLine.tiObject_ID:
accumulate tProposedLine.tiObject_ID (count by tProposedLine.tiObject_ID).
if last-of(tProposedLine.tiObject_ID) and
(accum count by tProposedLine.tiObject_ID (tProposedLine.tiObject_ID)) > 1
then do:
for each btProposedLine where
btProposedLine.tiObject_ID = tProposedLine.tiObject_ID:
assign btProposedLine.tlIsMultiple = true.
end. /* for each btProposedLine where */
end. /* if last-of(tProposedLine.tiObject_ID) and */
end. /* for each tProposedLine */
/* ====================================================================== */
/* Call a submethod that will do some more specific assignements etc */
/* ====================================================================== */
<M-29 run GetToPayObjectsCheck (output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper <> 0
then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave MAINAPIPROCESSINGBLOCK.
/* ====================================================================== */
/* Assign the amounts in base-currency for all lines */
/* ====================================================================== */
for each tProposedLine where
tProposedLine.tdPaymentAmountTC <> 0:
/* Assign tProposedLine.tdPaymentAmountBC and optionally get the rate */
if tProposedLine.tcInvoiceCurrencyCode <> "":U and
tProposedLine.tcInvoiceCurrencyCode <> ? and
icPaySelCurrCode <> "":U and
icPaySelCurrCode <> ?
then do:
/* Calculate BC Amount */
if (tProposedLine.tcInvoiceCurrencyCode <> icPaySelCurrCode
and tProposedLine.tcObjectType <> {&PAYMENTSELECTIONTYPE-PREPAYMENT})
or (tProposedLine.tcInvoiceCurrencyCode <> vcCompanyLC
and tProposedLine.tcObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENT})
then do:
if (tProposedLine.tcInvoiceCompanyCode <> vcCompanyCode)
or (tProposedLine.tcObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENT})
then do:
<M-69 run GetExchangeRate
(input ? (iiCompanyID),
input ? (iiFromCurrencyID),
input tProposedLine.tcInvoiceCurrencyCode (icFromCurrencyCode),
input viCompanyLCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input tProposedLine.ttInvoiceDate (itValidityDate),
output vdExchangeRate (odExchangeRate),
output vdExchangeRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper <> 0
then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave MAINAPIPROCESSINGBLOCK.
end. /* if tProposedLine.tcInvoiceCompanyCode <> vcCompanyCode */
else assign vdExchangeRate = tProposedLine.tdInvoiceRate
vdExchangeRateScale = tProposedLine.tdInvoiceRateScale.
assign tProposedLine.tdPaymentAmountBC = <M-11 RoundAmount
(input tProposedLine.tdPaymentAmountTC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount),
input ? (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BPaymentSelection>.
end. /* if tProposedLine.tcInvoiceCurrencyCode <> icPaySelCurrCode and */
else if (tProposedLine.tcObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENT}
and tProposedLine.tcInvoiceCurrencyCode = vcCompanyLC)
then do:
assign tProposedLine.tdPaymentAmountBC = tProposedLine.tdPaymentAmountTC.
end.
else assign tProposedLine.tdPaymentAmountBC = <M-23 RoundAmount
(input tProposedLine.tdPaymentAmountTC * tProposedLine.tdInvoiceRate * tProposedLine.tdInvoiceRateScale (idUnroundedAmount),
input ? (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BPaymentSelection>.
/* Assign the signed BC-amount and the Allocated-Amount */
assign tProposedLine.tdPaymentAmountSignBC = tProposedLine.tdPaymentAmountBC
* (if tProposedLine.tcPaymentAmntBCDebitCreditAbbr = vcCreditTR
then -1
else 1)
tProposedLine.tdAllocatedAmount = tProposedLine.tdPaymentAmountTC + tProposedLine.tdDiscountTC + tProposedLine.tdWHTAmtTC.
/* calculate Bank Payment Amount */
if vcCompanyLC = icPaySelCurrCode
then do:
assign tProposedLine.tdPaymentAmountBank = tProposedLine.tdPaymentAmountBC.
end.
else if tProposedLine.tcInvoiceCurrencyCode = icPaySelCurrCode
then do:
assign tProposedLine.tdPaymentAmountBank = tProposedLine.tdPaymentAmountTC.
end.
else if tProposedLine.tcInvoiceCurrencyCode <> icPaySelCurrCode
then do:
<M-27 run GetExchangeRate
(input ? (iiCompanyID),
input ? (iiFromCurrencyID),
input tProposedLine.tcInvoiceCurrencyCode (icFromCurrencyCode),
input ? (iiToCurrencyID),
input icPaySelCurrCode (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input tProposedLine.ttInvoiceDate (itValidityDate),
output vdExchangeRate (odExchangeRate),
output vdExchangeRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper < 0
then assign viLocalReturn = -2.
if vdExchangeRate <> 0 and
vdExchangeRate <> ? and
vdExchangeRateScale <> 0 and
vdExchangeRateScale <> ?
then assign tProposedLine.tdPaymentAmountBank = <M-33 RoundAmount
(input tProposedLine.tdPaymentAmountTC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount),
input ? (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BPaymentSelection>. else assign tProposedLine.tdPaymentAmountBank = 0
tProposedLine.tdPaymentAmountTC = 0
tProposedLine.tdPaymentSignedAmtTC = 0
tProposedLine.tdPaymentAmountBC = 0
tProposedLine.tdPaymentAmountSignBC = 0
tProposedLine.tdDiscountTC = 0
tProposedLine.tdInterestTC = 0
tProposedLine.tdWHTAmtTC = 0
tProposedLine.tdAllocatedAmount = 0
tProposedLine.tlProposedLineIsSelected = false.
end. /* else if tProposedLine.tcInvoiceCurrencyCode <> icPaySelCurrCode */
end. /* tProposedLine.tcInvoiceCurrencyCode <> "":U and */
end. /* for each tProposedLine where */
if viLocalReturn = -2
then do:
<M-56 run SetMessage
(input trim(#T-87'For some invoices, no exchange rate exists between the corresponding Invoice Currency and Bank Currency $1. See other messages for more details.':255(195584259)T-87#) (icMessage),
input icPaySelCurrCode (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-674311':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
assign viLocalReturn = -1.
end.
/* ============================================= */
/* Assign the original TC- and BC-payment-amount */
/* Assign the signed TC-payment-amount */
/* ============================================= */
for each tProposedLine:
/* Set the signed payment-amount */
if tProposedLine.tcPaymentAmntDebitCreditAbbr = vcCreditTR
then assign tProposedLine.tdPaymentSignedAmtTC = - tProposedLine.tdPaymentAmountTC.
else assign tProposedLine.tdPaymentSignedAmtTC = tProposedLine.tdPaymentAmountTC.
/* Two extra fields were created to store the Payment Amount. This way, the normal payment amount fields can be changed on UI without loosing the original values */
assign tProposedLine.tdOriginalPaymentAmountTC = tProposedLine.tdPaymentAmountTC
tProposedLine.tdOriginalPaymentAmountBC = tProposedLine.tdPaymentAmountBC.
end. /* For each tProposedLine: */
END. /* MAINAPIPROCESSINGBLOCK */
/* ========================= */
/* Set return status */
/* ========================= */
assign oiReturnStatus = viLocalReturn.
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 = "BPaymentSelection".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiGetToPayObjectsV04".
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/bpaymentselection.apigettopayobjectsv04.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::ilIsInitialLoad = <parameter value>
vhParameter::iiBankPayFormatID = <parameter value>
vhParameter::ilShowAll = <parameter value>
vhParameter::itDueDate = <parameter value>
vhParameter::icPaymentSelectionDue = <parameter value>
vhParameter::icCurrencyCode = <parameter value>
vhParameter::icDivisionCode = <parameter value>
vhParameter::icCountryCode = <parameter value>
vhParameter::icBusinessRelationCode = <parameter value>
vhParameter::icFromBusinessRelationCode = <parameter value>
vhParameter::icToBusinessRelationCode = <parameter value>
vhParameter::icBusinessRelationType = <parameter value>
vhParameter::ilBusinessRelationIsInterco = <parameter value>
vhParameter::icPaymentGroupCode = <parameter value>
vhParameter::icCorporateGroupCode = <parameter value>
vhParameter::ilAllEntities = <parameter value>
vhParameter::ilIsWithBank = <parameter value>
vhParameter::iiPaySelID = <parameter value>
vhParameter::itPaySelDate = <parameter value>
vhParameter::icPaySelCurrCode = <parameter value>
vhParameter::iiMaxNumberOfLinesToReturn = <parameter value>
vhParameter::iiCInvoiceID = <parameter value>
vhParameter::icBankNumberFormatted = <parameter value>
vhParameter::icPaymentReference = <parameter value>
vhParameter::itDisCountRefDueDate = <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.