Description
Export payment file in the format of Belgian domestic payments.
Parameters
iiCCollection_ID | input | integer | Collection to be processed. |
ilGroupingAllowed | input | logical | Can PaySelLines be grouped by creditor? General flag. |
icOutputFileName | input | character | Output file name. |
itPayDate | input | date | Collection payment date. |
iiGL_ID | input | integer | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program7/bpaymentselection.p)
empty temp-table tExpFields.
/* Get the Country Code of Belgium */
<Q-29 run CountryByCountry (all) (Read) (NoCache)
(input ?, (CountryId)
input {&BANKNUMBERVALIDATION-BE}, (CountryCode)
output dataset tqCountryByCountry) in BCountry >
find first tqCountryByCountry no-error.
if not available tqCountryByCountry
then do:
<M-30 run SetMessage
(input #T-39'The country Belgium is not defined in the system.':80(2983)T-39# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input {&BANKNUMBERVALIDATION-BE} (icFieldValue),
input 'D':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'QADFIN-1061':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
assign oiReturnStatus = -1.
return.
end.
/* Get the Business Relation Code for the Company */
<Q-28 run CompanyPropertyForAllData (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
output dataset tqCompanyPropertyForAllData) in BCompanyProperty >
find first tqCompanyPropertyForAllData no-error.
if not available tqCompanyPropertyForAllData
then do:
<M-31 run SetMessage
(input #T-40'The system cannot find the entity property information.':80(2984)T-40# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'D':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'QADFIN-1062':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
assign oiReturnStatus = -1.
return.
end.
/* Get the VAT number for the Business Relation Code of the company */
<Q-27 run VatNumberPrim (all) (Read) (NoCache)
(input ?, (VatNumberId)
input ?, (BusinessRelationId)
input ?, (IdentityCountryID)
input '':U, (VatNumberIdentity)
input tqCompanyPropertyForAllData.tcBusinessRelationCode, (BusinessRelationCode)
input if tqCountryByCountry.tlCountryIsEUCountry then {&BANKNUMBERVALIDATION-BE} else '':U, (IdentityCountryCode)
output dataset tqVatNumberPrim) in BBusinessRelation >
find first tqVatNumberPrim no-error.
/* Select proper lines and fill in temporary table */
for each tCCollectionPaySel where
tCCollectionPaySel.CCollection_ID = iiCCollection_ID,
each tCDocumentInfoForCollection where
tCDocumentInfoForCollection.tcPayFormatTypeCode = tCCollectionPaySel.tcPayFormatType,
each tCDocumentInvoiceXrefPaySel where
tCDocumentInvoiceXrefPaySel.CDocument_ID = tCDocumentInfoForCollection.tiCDocument_ID,
each tPaySelLine where
tPaySelLine.PaySelLine_ID = tCDocumentInvoiceXRefPaySel.PaySelLine_ID and
tPaySelLine.PayFormatTypeCode = {&PAYMENTFORMAT-BE1},
first tPaySel where
tPaySel.tc_Rowid = tPaySelLine.tc_ParentRowid
break by tPaySelLine.tcCreditorCode
by tPaySelLine.tcInvoiceCurrencyCode
by tPaySelLine.BankNumber_ID:
/* Get the Creditor in order to decide if the grouping is possible */
if first-of(tPaySelLine.tcCreditorCode)
then do:
<M-36 run ExportBEInlandPreSelect
(output vcCredBusRelationCode (ocCredBusRelationCode),
output vlCredIsIndividualPayment (olCredIsIndividualPayment),
output vcCredAddressLanguage (ocCredAddressLanguage),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
end.
if (ilGroupingAllowed and
first-of(tPaySelLine.BankNumber_ID) and
not vlCredIsIndividualPayment) or /* Possible grouping based on creditor */
tPaySelLine.tcTSM <> '':U or /* TSM filled in */
not ilGroupingAllowed or /* Grouping not allowed with the Payment Selection Transfer */
vlCredIsIndividualPayment /* Grouping allowed with the Payment Selection Transfer, but the creditor doesn't allow the grouping */
then do:
empty temp-table tqBankNumberPrim.
if tPaySelLine.BankNumber_ID <> ? and
tPaySelLine.BankNumber_ID <> 0
then do:
/* Get the Creditor's Bank Account on which the Payment has been Realised */
<Q-16 run BankNumberPrim (all) (Read) (NoCache)
(input tPaySelLine.BankNumber_ID, (BankNumberId)
input ?, (ParentObjectId)
input '':U, (BankNumber)
input '':U, (BankNumberExtension)
input ?, (BankPayFormatID)
output dataset tqBankNumberPrim) in BBankNumber >
end.
find first tqBankNumberPrim no-error.
if not available tqBankNumberPrim
then do:
<M-17 run SetMessage
(input #T-41'The supplier bank account ($1) is not defined in the system.':80(2985)T-41# (icMessage),
input tqBankNumberPrim.tcBankNumber (icArguments),
input '':U (icFieldName),
input tqBankNumberPrim.tcBankNumber (icFieldValue),
input 'D':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-1045':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
assign oiReturnStatus = min(-1, viFCReturnSuper).
return.
end.
create tExpFields.
assign tExpFields.tcCredCreditorCode = tPaySelLine.tcCreditorCode
tExpFields.tcCredBankNumber = tqBankNumberPrim.tcBankNumber
tExpFields.tcCredBankNumberValidation = tqBankNumberPrim.tcBankNumberValidation
tExpFields.tcCredBankNumberExtension = tqBankNumberPrim.tcBankNumberExtension
tExpFields.tcCredBusRelationCode = vcCredBusRelationCode
tExpFields.tcCredAddressLanguage = vcCredAddressLanguage
tExpFields.tcTSM = tPaySelLine.tcTSM
vcCredBankNumber = tqBankNumberPrim.tcBankNumber
vcCredBankNumberValidation = tqBankNumberPrim.tcBankNumberValidation
vcCredBankNumberExtension = tqBankNumberPrim.tcBankNumberExtension.
end.
else find tExpFields where
tExpFields.tcCredCreditorCode = tPaySelLine.tcCreditorCode and
tExpFields.tcCredBankNumber = vcCredBankNumber and
tExpFields.tcCredBankNumberValidation = vcCredBankNumberValidation and
tExpFields.tcCredBankNumberExtension = vcCredBankNumberExtension and
tExpFields.tcTSM = tPaySelLine.tcTSM
no-error.
if tExpFields.tcPaySelRef <> fill(chr(2),12)
then do:
if tExpFields.tcPaySelRef = '':U
then assign tExpFields.tcPaySelRef = tPaySel.PaySelCode.
else if tPaySel.PaySelCode <> tExpFields.tcPaySelRef
then assign tExpFields.tcPaySelRef = fill(chr(2),12).
end.
create tExportReferences.
assign tExportReferences.tiPaySelLineId = tPaySelLine.PaySelLine_ID
tExportReferences.tlPaySelLineIsRefInFile = true.
/* Get the Invoice for the PaySelectionLine in order to retrieve the Ext.reference */
if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICE} OR
tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR} or
tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTE} OR
tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTECORR} OR
tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENTINV} or
tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-ADJUSTMENT}
then do:
<Q-24 run CInvoiceByPaymentInfo (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input tExpFields.tcCredBusRelationCode, (BusinessRelationCode)
input tPaySelLine.PaySelLineParentObject_ID, (CInvoice_ID)
input '':U, (PaymentGroupCode)
input '':U, (CurrencyCode)
input '':U, (DivisionCode)
input ?, (BusinessRelationIsInterco)
input '':U, (CInvoiceType)
input ?, (IsInvoiceApproved)
input ?, (IsLockPayment)
input ?, (CInvoiceIsSelected)
input ?, (CInvoiceIsOpen)
input ?, (BusinessRelationCountryCode)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
output dataset tqCInvoiceByPaymentInfo) in BCInvoice >
find first tqCInvoiceByPaymentInfo no-error.
if not available tqCInvoiceByPaymentInfo
then do:
<M-25 run SetMessage
(input #T-42'The specified supplier invoice is not defined in the system or is invalid. ':80(2986)T-42# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'D':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-1059':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
assign oiReturnStatus = min(-1, viFCReturnSuper).
return.
end.
assign viLength = length(tPaySelLine.tcTSM,"CHARACTER":U).
if tPaySelLine.tcTSM <> '':U
then do viPosCounter = 1 to viLength :
if lookup(substring(tPaySelLine.tcTSM,viPosCounter,1,"CHARACTER":U),"1,2,3,4,5,6,7,8,9,0":U) > 0
then do:
if vilength <= 12 /* Maximum 12 numeric positions of TSM */
then assign tExpFields.tcReference1 = tExpFields.tcReference1 + substring(tPaySelLine.tcTSM,viPosCounter,1,"CHARACTER":U).
else leave.
end.
end.
else do:
if vilength + 1 <= 53
then assign tExpFields.tcReference1 = tExpFields.tcReference1 + ' ':U + tqCInvoiceByPaymentInfo.tcCInvoiceReference.
else if vilength + 1 <= 53
then assign tExpFields.tcReference2 = tExpFields.tcReference2 + ' ':U + tqCInvoiceByPaymentInfo.tcCInvoiceReference.
else assign tExpFields.tcReference1 = '':U
tExpFields.tcReference2 = '':U
tExportReferences.tlPaySelLineIsRefInFile = false.
end.
end.
else do:
<Q-37 run GetDInvoiceForPaymentSelection (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input ?, (IsPaymentAllowed)
input tExpFields.tcCredBusRelationCode, (BusinessRelationCode)
input tPaySelLine.PaySelLineParentObject_ID, (DInvoice_ID)
input ?, (CurrencyCode)
input ?, (DivisionCode)
input ?, (BusinessRelationIsInterco)
input ?, (DInvoiceType)
input ?, (DInvoiceIsOpen)
input ?, (DInvoiceIsSelected)
input ?, (BusinessRelationCountryCode)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
output dataset tqGetDInvoiceForPaymentSelection) in BDInvoice >
find first tqGetDInvoiceForPaymentSelection no-error.
if not available tqGetDInvoiceForPaymentSelection
then do:
<M-38 run SetMessage
(input #T-43'The specified customer credit note is not defined in the system or is invalid.':80(2987)T-43# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'D':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-1218':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
assign oiReturnStatus = min(-1, viFCReturnSuper).
return.
end.
if vilength + 1 <= 53
then assign tExpFields.tcReference1 = tExpFields.tcReference1 + ' ':U + tqGetDInvoiceForPaymentSelection.tcDInvoiceTSMNumber.
else if vilength + 1 <= 53
then assign tExpFields.tcReference2 = tExpFields.tcReference2 + ' ':U + tqGetDInvoiceForPaymentSelection.tcDInvoiceTSMNumber.
else assign tExpFields.tcReference1 = '':U
tExpFields.tcReference2 = '':U
tExportReferences.tlPaySelLineIsRefInFile = false.
end.
/* Payment Amount */
if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICE} or
tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTECORR}
then assign tExpFields.tdAmountLC01 = if tPaySelLine.tcInvoiceCurrencyCode = vcCompanyLC
then tExpFields.tdAmountLC01 + abs(tPaySelLine.PaySelLineAmountTC) /* LC */
else tExpFields.tdAmountLC01 + abs(<M-50 RoundAmount
(input tPaySelLine.PaySelLineAmountTC * tqCInvoiceByPaymentInfo.tdCInvoiceExchangeRate * tqCInvoiceByPaymentInfo.tdCinvoiceRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in business>). /* TC <> LC */
else if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-DEBTORCREDITNOTE}
then assign tExpFields.tdAmountLC01 = if tPaySelLine.tcInvoiceCurrencyCode = vcCompanyLC
then tExpFields.tdAmountLC01 + abs(tPaySelLine.PaySelLineAmountTC) /* LC */
else tExpFields.tdAmountLC01 + abs(<M-51 RoundAmount
(input tPaySelLine.PaySelLineAmountTC * tqGetDInvoiceForPaymentSelection.tdDInvoiceExchangeRate * tqGetDInvoiceForPaymentSelection.tdDInvoiceRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in business>). /* TC <> LC */
else if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTE} OR
tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR} or
tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENTINV}
then assign tExpFields.tdAmountLC01 = if tPaySelLine.tcInvoiceCurrencyCode = vcCompanyLC
then tExpFields.tdAmountLC01 - abs(tPaySelLine.PaySelLineAmountTC) /* LC */
else tExpFields.tdAmountLC01 - abs(<M-52 RoundAmount
(input tPaySelLine.PaySelLineAmountTC * tqCInvoiceByPaymentInfo.tdCInvoiceExchangeRate * tqCInvoiceByPaymentInfo.tdCinvoiceRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in business>). /* TC <> LC */
else if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-DEBTORCNCORR}
then assign tExpFields.tdAmountLC01 = if tPaySelLine.tcInvoiceCurrencyCode = vcCompanyLC
then tExpFields.tdAmountLC01 - abs(tPaySelLine.PaySelLineAmountTC) /* LC */
else tExpFields.tdAmountLC01 - abs(<M-53 RoundAmount
(input tPaySelLine.PaySelLineAmountTC * tqGetDInvoiceForPaymentSelection.tdDInvoiceExchangeRate * tqGetDInvoiceForPaymentSelection.tdDInvoiceRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in business>). /* TC <> LC */
else if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-ADJUSTMENT}
then assign tExpFields.tdAmountLC01 = if tPaySelLine.tcInvoiceCurrencyCode = vcCompanyLC
then tExpFields.tdAmountLC01 + tPaySelLine.PaySelLineAmountTC /* LC */
else tExpFields.tdAmountLC01 + <M-54 RoundAmount
(input tPaySelLine.PaySelLineAmountTC * tqGetDInvoiceForPaymentSelection.tdDInvoiceExchangeRate * tqGetDInvoiceForPaymentSelection.tdDInvoiceRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in business>. /* TC <> LC */
end.