Description
Create XML export file in accordance to UNIFI specification.
Parameters
iiCCollection_ID | input | integer | |
ilGroupingAllowed | input | logical | |
icOutputFileName | input | character | |
itPayDate | input | date | |
iiGL_ID | input | integer | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program7/bpaymentselection.p)
assign oiReturnStatus = -98.
/********************************/
/* Create payment file */
/********************************/
do on error undo, retry:
if retry
then do:
assign vcPaySelMsg = substitute(#T-65'The system cannot create the file (&1).':200(15532)t-65#,
trim(icOutputFileName) )
oiReturnStatus = -1.
<M-66 run SetMessage (input trim(vcPaySelMsg) (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-3704':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
return.
end.
output stream sExpStream to value(icOutputFileName).
end.
GETDATA-BLOCK:
DO:
assign vcPaySelMsg = "":U.
/* Get the Business Relation Code for the Company */
<Q-68 run CompanyPropertyByBusinessRel (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
output dataset tqCompanyPropertyByBusinessRel) in BCompanyProperty >
find first tqCompanyPropertyByBusinessRel
no-lock no-error.
if not available(tqCompanyPropertyByBusinessRel)
then do:
assign vcPaySelMsg = #T-70'The system cannot find the entity property information.':200(15677)t-70#
oiReturnStatus = -1.
leave GETDATA-BLOCK.
end.
<Q-74 run CountryByCountry (all) (Read) (NoCache)
(input ?, (CountryId)
input tqCompanyPropertyByBusinessRel.tcIdentityCountryCode, (CountryCode)
output dataset tqCountryByCountry) in BCountry >
find first tqCountryByCountry where
tqCountryByCountry.tcCountryCode = tqCompanyPropertyByBusinessRel.tcIdentityCountryCode
no-lock no-error.
if not available(tqCountryByCountry)
then do:
assign vcPaySelMsg = substitute(#T-75'The country code of the entity (&1) is not defined in the system.':200(15797)t-75#,
trim(tqCompanyPropertyByBusinessRel.tcIdentityCountryCode) )
oiReturnStatus = -1.
leave GETDATA-BLOCK.
end.
/* Get the VAT number for the Business Relation Code of the company */
<Q-76 run VatNumberPrim (all) (Read) (NoCache)
(input ?, (VatNumberId)
input ?, (BusinessRelationId)
input ?, (IdentityCountryID)
input ?, (VatNumberIdentity)
input tqCompanyPropertyByBusinessRel.tcBusinessRelationCode, (BusinessRelationCode)
input tqCompanyPropertyByBusinessRel.tcIdentityCountryCode, (IdentityCountryCode)
output dataset tqVatNumberPrim) in BBusinessRelation >
find first tqVatNumberPrim where
tqVatNumberPrim.tcBusinessRelationCode = tqCompanyPropertyByBusinessRel.tcBusinessRelationCode and
tqVatNumberPrim.tcCountryCode = tqCompanyPropertyByBusinessRel.tcIdentityCountryCode
no-lock no-error.
if not available(tqVatNumberPrim)
then do:
assign vcPaySelMsg = substitute(#T-77'No tax number is defined for this combination of business relation (&1) and country code (&2).':200(15798)t-77#,
trim(tqCompanyPropertyByBusinessRel.tcBusinessRelationCode),
trim(tqCompanyPropertyByBusinessRel.tcIdentityCountryCode) )
oiReturnStatus = -1.
leave GETDATA-BLOCK.
end.
END. /* GETDATA-BLOCK */
if vcPaySelMsg <> "":U
then do:
<M-78 run SetMessage (input trim(vcPaySelMsg) (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-3804':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
return.
end.
/* Populate tPaymentSelectionForUNIFI using tPaySel records */
for each tPaySel no-lock:
create tPaymentSelectionForUNIFI.
buffer-copy tPaySel to tPaymentSelectionForUNIFI no-error.
<M-85 run GetPaymentInstrument
(input tPaySel.BankPayFormat_ID (iiBankPayFormatID),
output tPaymentSelectionForUNIFI.tcPayInstru (ocPaymentInstrument),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
end.
/********************************/
/* Create main XML-structure */
/********************************/
create X-DOCUMENT vhXMLDoc in widget-pool "non-persistent".
create X-NODEREF vhXMLRoot in widget-pool "non-persistent".
create X-NODEREF vhXMLPain in widget-pool "non-persistent".
vhXMLDoc:ENCODING = 'UTF-8':U.
vhXMLDoc:CREATE-NODE(vhXMLRoot, "Document":U, "ELEMENT":U).
vhXMLRoot:SET-ATTRIBUTE("xmlns":U, "urn:std:iso:20022:xsd:pain.001.001.01":U).
vhXMLRoot:SET-ATTRIBUTE("xmlns:xsi":U, "http://www.w3.org/2001/XMLSchema-instance":U).
vhXMLDoc:APPEND-CHILD(vhXMLRoot).
vhXMLDoc:CREATE-NODE(vhXMLPain, "pain.001.001.01":U, "ELEMENT":U).
vhXMLRoot:APPEND-CHILD(vhXMLPain).
/* ================================================ */
/* 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-UNIFI},
/* first tPaySel where
tPaySel.tc_Rowid = tPaySelLine.tc_ParentRowid */
first tPaymentSelectionForUNIFI where
tPaymentSelectionForUNIFI.tc_Rowid = tPaySelLine.tc_ParentRowid
break by tCCollectionPaySel.CCollection_ID
/* by tPaySel.CDocumentType */
by tPaymentSelectionForUNIFI.tcPayInstru
by tPaySelLine.tcCreditorCode
by tPaySelLine.tcInvoiceCurrencyCode
by tPaySelLine.BankNumber_ID:
if first-of(tCCollectionPaySel.CCollection_ID)
then do:
/************************************/
/* Add GroupHeader element */
/************************************/
<M-79 run ExportUNIFIGroupHeader (input vhXMLDoc (ihXMLDoc),
input vhXMLPain (ihXMLParentNode),
output vhXMLCompanyPostalAddress (ohXMLCompanyPostalAddress),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
end.
if first-of(tPaySelLine.tcCreditorCode)
then do:
/************************************/
/* Get Creditor-Info */
/************************************/
<M-80 run ExportUNIFIPreselectCreditor (output viCreditorID (oiCreditorID),
output vcCreditorName1 (ocCreditorName1),
output vcCreditorStreet1 (ocCreditorStreet1),
output vcCreditorStreet2 (ocCreditorStreet2),
output vcCreditorStreet3 (ocCreditorStreet3),
output vcCreditorZip (ocCreditorZip),
output vcCreditorCity (ocCreditorCity),
output vcCreditorCountryCode (ocCreditorCountryCode),
output vcCreditorCountryDescr (ocCreditorCountryDescr),
output vcBankNumberParentType (ocBankNumberParentType),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then next.
end.
end.
if first-of(tPaySelLine.BankNumber_ID)
then do:
/************************************/
/* Get Creditor BankNumber */
/************************************/
<M-81 run ExportUNIFIPreselectBank (input vcBankNumberParentType (icBankNumberParentType),
input viCreditorID (iiBankNumberParentObjectID),
input tPaySelLine.BankNumber_ID (iiBankNumberID),
output vcCreditorBankNumber (ocBankNumber),
output vcCreditorBankNumberValidation (ocBankNumberValidation),
output vcCreditorBankNumberExtension (ocBankNumberExtension),
output vcCreditorBankNumberSwiftCode (ocBankNumberSwiftCode),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then next.
end.
end.
/* if first-of(tPaySel.CDocumentType) */
if first-of(tPaymentSelectionForUNIFI.tcPayInstru)
then do:
/************************************/
/* Add PaymentInformation element */
/************************************/
<M-82 run ExportUNIFIPaymentInformation
(input vhXMLDoc (ihXMLDoc),
input vhXMLPain (ihXMLParentNode),
output vhXMLPmtInf (ohXMLPmtInf),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
assign vcPrevPI = vcCurrPI.
end.
/************************************/
/* Add PaymentTransaction element */
/************************************/
<M-83 run ExportUNIFIPaymentTransaction (input vhXMLDoc (ihXMLDoc),
input vhXMLPmtInf (ihXMLParentNode),
input vcCreditorName1 (icCreditorName1),
input vcCreditorStreet1 (icCreditorStreet1),
input vcCreditorStreet2 (icCreditorStreet2),
input vcCreditorStreet3 (icCreditorStreet3),
input vcCreditorZip (icCreditorZip),
input vcCreditorCity (icCreditorCity),
input vcCreditorCountryCode (icCreditorCountryCode),
input vcCreditorCountryDescr (icCreditorCountryDescr),
input vcCreditorBankNumber (icCreditorBankNumber),
input vcCreditorBankNumberValidation (icCreditorBankNumberValidation),
input vcCreditorBankNumberExtension (icCreditorBankNumberExtension),
input vcCreditorBankNumberSwiftCode (icCreditorBankNumberSwiftCode),
output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
create tExportReferences.
assign tExportReferences.tiPaySelLineId = tPaySelLine.PaySelLine_ID
tExportReferences.tlPaySelLineIsRefInFile = true.
/************************************/
/* Clean up dynamic objects. */
/************************************/
/* if last-of(tPaySel.CDocumentType) */
if last-of(tPaymentSelectionForUNIFI.tcPayInstru)
then do:
if vhXMLPmtInf <> ? then
delete object vhXMLPmtInf.
end.
end.
/************************************/
/* Write the XML-document to a file */
/************************************/
vhXMLDoc:SAVE("STREAM":U,"sExpStream":U).
/* Close the stream */
output stream sExpStream close.
/* Delete dynamically created objects */
delete object vhXMLPain.
delete object vhXMLRoot.
delete object vhXMLDoc.
if oiReturnStatus = -98
then assign oiReturnStatus = 0.