project QadFinancials > class BDCollection > method ExportXml


Parameters


iiDCollectionIdinputinteger
ilDuplicateinputlogical
itSpilDateinputdate
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDCollection.Export


program code (program5/bdcollection.p)

assign vlSuppresEmpty = yes.

/* Get the collection */
<Q-1 run DCollectionByID (all) (Read) (NoCache)
   (input ?, (CompanyId)
    input iiDCollectionId, (CollectionId)
    output dataset tqDCollectionByID) in BDCollection >

find tqDCollectionByID where
     tqDCollectionByID.tiDCollection_ID = iiDCollectionId
     no-error.

if not available tqDCollectionByID
then do:
    <M-2 run SetMessage
       (input  trim(#T-14'The customer payment collection $1 cannot be found.':250(1635)T-14#) (icMessage), 
        input  string(iiDCollectionId) (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QADFIN-3029':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDCollection>

    assign oiReturnStatus = -1.
    return.
end.

assign tqDCollectionByID.ttDCollectionRequestedDate = itSpilDate.

/* Create the objects we need. */
CREATE X-DOCUMENT vhDoc in widget-pool "non-persistent".
CREATE X-NODEREF vhRoot in widget-pool "non-persistent".
CREATE X-NODEREF vhRow in widget-pool "non-persistent".
CREATE X-NODEREF vhSubRow in widget-pool "non-persistent".
CREATE X-NODEREF vhSubRow2 in widget-pool "non-persistent".
CREATE X-NODEREF vhSubRow3 in widget-pool "non-persistent".
CREATE X-NODEREF vhSubRow4 in widget-pool "non-persistent".
CREATE X-NODEREF vhSubRow5 in widget-pool "non-persistent".
CREATE X-NODEREF vhField in widget-pool "non-persistent".
CREATE X-NODEREF vhText in widget-pool "non-persistent".

/* Set up a root node. */
vhDoc:CREATE-NODE (vhRoot, "DCollection":U, "ELEMENT":U).
vhDoc:APPEND-CHILD (vhRoot).

vhBuf = BUFFER tqDCollectionByID:HANDLE.

vhDoc:CREATE-NODE (vhRow, "tiDCollection_ID":U, "ELEMENT":U).
vhRoot:APPEND-CHILD (vhRow).
        
vhDoc:CREATE-NODE (vhText, "":U, "TEXT":U).
vhRow:APPEND-CHILD (vhText).
vhText:NODE-VALUE = string(tqDCollectionByID.tiDCollection_ID).

DCollectionNodes:
REPEAT viCounter = 1 TO vhBuf:NUM-FIELDS:
   
    vhDBFld = vhBuf:BUFFER-FIELD (viCounter).
    
    if (index(vhDBFld:name,"_":U) > 0 or index(vhDBFld:name,"Custom":U) > 0)     
    or  (vhDBFld:buffer-value = "":U and vlSuppresEmpty) 
    then next DCollectionNodes.

    
    vhDoc:CREATE-NODE (vhRow, vhDBFld:name, "ELEMENT":U).
    vhRoot:APPEND-CHILD (vhRow).

    
    vhDoc:CREATE-NODE (vhText, "":U, "TEXT":U).
    vhRow:APPEND-CHILD (vhText).
    vhText:NODE-VALUE = string( vhDBFld:buffer-value).
end.
/* add node for duplicate */
vhDoc:CREATE-NODE (vhRow, "tlIsDuplicate":U, "ELEMENT":U).
vhRoot:APPEND-CHILD (vhRow).

    
vhDoc:CREATE-NODE (vhText, "":U, "TEXT":U).
vhRow:APPEND-CHILD (vhText).
vhText:NODE-VALUE = string(ilDuplicate).

/* Create a Constituent row node. */
vhDoc:CREATE-NODE (vhRow, "Constituent":U, "ELEMENT":U).
vhRoot:APPEND-CHILD (vhRow).

/* Get Company Name and City */
<Q-3 run CompanyPropertyByIdCode (all) (Read) (NoCache)
   (input tqDCollectionByID.tiCompany_ID, (CompanyId)
    input ?, (CompanyPropertyId)
    input ?, (BusinessRelationId)
    input ?, (CurrencyId)
    input ?, (CompanyPropertyCode)
    input ?, (CompanyCode)
    input ?, (BusinessRelationCode)
    input ?, (CurrencyCode)
    output dataset tqCompanyPropertyByIdCode) in BCompanyProperty >

find first tqCompanyPropertyByIdCode where
           tqCompanyPropertyByIdCode.tiCompany_ID = tqDCollectionByID.tiCompany_ID
           no-error.

if available tqCompanyPropertyByIdCode
then do:
    
    <Q-4 run AddressByAddressType (all) (Read) (NoCache)
       (input tqCompanyPropertyByIdCode.tiBusinessRelation_ID, (BusinessRelationId)
        input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
        output dataset tqAddressByAddressType) in BBusinessRelation >

    find first tqAddressByAddressType where
               tqAddressByAddressType.tiBusinessRelation_ID = tqCompanyPropertyByIdCode.tiBusinessRelation_ID and
               tqAddressByAddressType.tcAddressTypeCode     = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}
               no-error.
    

    if available tqAddressByAddressType
    then do:
        vhDoc:CREATE-NODE (vhSubRow, "Address":U, "ELEMENT":U).
        vhRow:APPEND-CHILD (vhSubRow).
        /*
        assign vcCompanyName = tqAddressByAddressType.tcBusinessRelationName1
                    vcCompanyCity = tqAddressByAddressType.tcAddressCity.
                    */
        
        vhBuf = BUFFER tqAddressByAddressType:HANDLE.
    
        CompanyDetails:
        REPEAT viCounter = 1 TO vhBuf:NUM-FIELDS:
            
            vhDBFld = vhBuf:BUFFER-FIELD (viCounter).
            
            if (index(vhDBFld:name,"_":U) > 0 or index(vhDBFld:name,"Custom":U) > 0)             
            or  (vhDBFld:buffer-value = "":U and vlSuppresEmpty) 
            then next CompanyDetails.
        
            vhDoc:CREATE-NODE (vhSubRow2, vhDBFld:name, "ELEMENT":U).
            vhSubRow:APPEND-CHILD (vhSubRow2).
            
            vhDoc:CREATE-NODE (vhText, "":U, "TEXT":U).
            vhSubRow2:APPEND-CHILD (vhText).
            vhText:NODE-VALUE = string( vhDBFld:buffer-value).
        end.
    end.      
    
end.

/* Get the Current Company BankNumber */
<Q-5 run BankNumberByParentID (all) (Read) (NoCache)
   (input tqDCollectionByID.tiGL_ID, (ParentObjectId)
    input {&BANKNUMBERPARENTTYPE-GL}, (BankNumberParentType)
    input true, (BankNumberIsDefault)
    input tqDCollectionByID.tiCompany_ID, (CompanyId)
    output dataset tqBankNumberByParentID) in BBankNumber >

find first tqBankNumberByParentID
           no-error.
vhBuf2 = BUFFER tqBankNumberByParentID:HANDLE.
if available tqBankNumberByParentID 
then do:
    
    vhDoc:CREATE-NODE (vhSubRow, "Financial":U, "ELEMENT":U).
    vhRow:APPEND-CHILD (vhSubRow).

    FinacialNodes:
    REPEAT viCounter = 1 TO vhBuf2:NUM-FIELDS:
    
        vhDBFld = vhBuf2:BUFFER-FIELD (viCounter).
    
        if  index(vhDBFld:name,"_":U) > 0
        or  index(vhDBFld:name,"Company":U) > 0
        or  index(vhDBFld:name,"BusinessRelation":U) > 0
        or  (vhDBFld:buffer-value = "":U and vlSuppresEmpty) 
        then next FinacialNodes.

        /* We already did Cust-num and Name above so skip them. */
        vhDoc:CREATE-NODE (vhSubRow2, vhDBFld:name, "ELEMENT":U).
        vhSubRow:APPEND-CHILD (vhSubRow2).

        
        vhDoc:CREATE-NODE (vhText, "":U, "TEXT":U).
        vhSubRow2:APPEND-CHILD (vhText).
        vhText:NODE-VALUE = string( vhDBFld:buffer-value).
        
    end.

    <Q-22 run AddressByAddressType (all) (Read) (NoCache)
       (input tqBankNumberByParentID.tiBankBusinessRelation_ID, (BusinessRelationId)
        input {&ADDRESSTYPECODESYSTEM-PAYM}, (AddressTypeCode)
        output dataset tqAddressByAddressType) in BBusinessRelation >

    
    find first tqAddressByAddressType where
                tqAddressByAddressType.tiBusinessRelation_ID = tqBankNumberByParentID.tiBankBusinessRelation_ID and
                tqAddressByAddressType.tcAddressTypeCode     = {&ADDRESSTYPECODESYSTEM-PAYM}
                no-error.

    if not available tqAddressByAddressType
    then do:

        <Q-19 run AddressByAddressType (all) (Read) (NoCache)
           (input tqBankNumberByParentID.tiBankBusinessRelation_ID, (BusinessRelationId)
            input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
            output dataset tqAddressByAddressType) in BBusinessRelation >
    
        find first tqAddressByAddressType where
            tqAddressByAddressType.tiBusinessRelation_ID = tqBankNumberByParentID.tiBankBusinessRelation_ID and
            tqAddressByAddressType.tcAddressTypeCode     = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}
            no-error.
    end.

    vhBuf2 = BUFFER tqAddressByAddressType:HANDLE.
    vhDoc:CREATE-NODE (vhSubRow2, "BankAddress":U, "ELEMENT":U).
    vhSubRow:APPEND-CHILD (vhSubRow2).       
    if available tqAddressByAddressType
    then do:
        
        
        FinacialBankAddressNodes:
        REPEAT viCounter = 1 TO vhBuf2:NUM-FIELDS:
        
            vhDBFld = vhBuf2:BUFFER-FIELD (viCounter).
        
            if  index(vhDBFld:name,"_":U) > 0
            or  index(vhDBFld:name,"Company":U) > 0
            or  (vhDBFld:buffer-value = "":U and vlSuppresEmpty) 
            then next FinacialBankAddressNodes.
    
            
            vhDoc:CREATE-NODE (vhSubRow3, vhDBFld:name, "ELEMENT":U).
            vhSubRow2:APPEND-CHILD (vhSubRow3).
                
            vhDoc:CREATE-NODE (vhText, "":U, "TEXT":U).
            vhSubRow3:APPEND-CHILD (vhText).
            vhText:NODE-VALUE = string( vhDBFld:buffer-value).
        end.
    end.
    /*assign vcBankNumber = string(decimal(replace(tqBankNumberByParentID.tcBankNumber, ".":U, "":U)),">>>>>99999999":U).*/
end.








/* Create payrecords 1 (Transactieinfo) */
<Q-8 run DDocumentByCollectionID (all) (Read) (NoCache)
   (input tqDCollectionByID.tiCompany_ID, (CompanyId)
    input tqDCollectionByID.tiDCollection_ID, (DCollectionID)
    input ?, (DDocumentID)
    input {&DOCUMENTSTATUS-INCASSO} + ',':U + {&DOCUMENTSTATUS-DISCONT}, (DDocumentStatus)
    output dataset tqDDocumentByCollectionID) in BDDocument >
/*
assign viA            = 3
       vdTotalBankNrs = 0
       vdTotalLC      = 0
       viPostCounter  = 0.
*/       

<Q-9 run DebtorByDebtor
   (Start) in BDebtor >

/* Create Documents row node. */
vhDoc:CREATE-NODE (vhRow, "DDocuments":U, "ELEMENT":U).
vhRoot:APPEND-CHILD (vhRow).



vhBuf = BUFFER tqDDocumentByCollectionID:HANDLE.

for each tqDDocumentByCollectionID:
    vhDBFld = vhBuf:BUFFER-FIELD (viCounter).

   
    vhDoc:CREATE-NODE (vhSubRow, "DDocument":U, "ELEMENT":U).
    vhRow:APPEND-CHILD (vhSubRow).

    <Q-10 run DebtorByDebtor (first) (Read) (NoCache)
       (input tqDCollectionByID.tiCompany_ID, (CompanyId)
        input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
        input tqDDocumentByCollectionID.tiDebtor_ID, (DebtorId)
        input ?, (DebtorCode)
        output dataset tqDebtorByDebtor) in BDebtor >
    vhBuf2 = BUFFER tqDebtorByDebtor:HANDLE.
    find first tqDebtorByDebtor
               no-error.
   

    vhDoc:CREATE-NODE (vhSubRow2, "Debtor":U, "ELEMENT":U).
    vhSubRow:APPEND-CHILD (vhSubRow2).

    vhDoc:CREATE-NODE (vhSubRow3, "Address":U, "ELEMENT":U).
    vhSubRow2:APPEND-CHILD (vhSubRow3).

    DebtorNodes:
    REPEAT viCounter = 1 TO vhBuf2:NUM-FIELDS:
        
        vhDBFld = vhBuf2:BUFFER-FIELD (viCounter).
        
        if (index(vhDBFld:name,"_":U) > 0 or index(vhDBFld:name,"Custom":U) > 0) 
        and vhDBFld:name <> "tiDebtor_ID":U
        or  (vhDBFld:buffer-value = "":U and vlSuppresEmpty) 
        then next DebtorNodes.
    
        /* We already did Cust-num and Name above so skip them. */
        vhDoc:CREATE-NODE (vhSubRow4, vhDBFld:name, "ELEMENT":U).
        vhSubRow3:APPEND-CHILD (vhSubRow4).
    
        
        vhDoc:CREATE-NODE (vhText, "":U, "TEXT":U).
        vhSubRow4:APPEND-CHILD (vhText).
        vhText:NODE-VALUE = string( vhDBFld:buffer-value).
    end.


    if available tqDebtorByDebtor 
    then do:
        

        /* Get the Debtor BankNumber */
        <Q-12 run BankNumberByParentID (all) (Read) (NoCache)
           (input tqDebtorByDebtor.tiDebtor_ID, (ParentObjectId)
            input {&BANKNUMBERPARENTTYPE-DEBTOR}, (BankNumberParentType)
            input true, (BankNumberIsDefault)
            input tqDCollectionByID.tiCompany_ID, (CompanyId)
            output dataset tqBankNumberByParentID) in BBankNumber >
        vhBuf2 = BUFFER tqBankNumberByParentID:HANDLE.
        find first tqBankNumberByParentID
                   no-error.

        
        if available tqBankNumberByParentID 
        then do:

            /*assign vcDebtorBankNumber = tqBankNumberByParentID.tcBankNumber.*/
            vhDoc:CREATE-NODE (vhSubRow3, "Financial":U, "ELEMENT":U).
            vhSubRow2:APPEND-CHILD (vhSubRow3).
    
            FinacialNodes:
            REPEAT viCounter = 1 TO vhBuf2:NUM-FIELDS:
            
                vhDBFld = vhBuf2:BUFFER-FIELD (viCounter).
                
                if  index(vhDBFld:name,"_":U) > 0
                or  index(vhDBFld:name,"Company":U) > 0
                or  index(vhDBFld:name,"BusinessRelation":U) > 0
                or  (vhDBFld:buffer-value = "":U and vlSuppresEmpty) 
                then next FinacialNodes.
                

                
                vhDoc:CREATE-NODE (vhSubRow4, vhDBFld:name, "ELEMENT":U).
                vhSubRow3:APPEND-CHILD (vhSubRow4).
                    
                vhDoc:CREATE-NODE (vhText, "":U, "TEXT":U).
                vhSubRow4:APPEND-CHILD (vhText).
                vhText:NODE-VALUE = string( vhDBFld:buffer-value).
            end.

            <Q-18 run AddressByAddressType (all) (Read) (NoCache)
               (input tqBankNumberByParentID.tiBankBusinessRelation_ID, (BusinessRelationId)
                input {&ADDRESSTYPECODESYSTEM-PAYM}, (AddressTypeCode)
                output dataset tqAddressByAddressType) in BBusinessRelation >

            vhBuf2 = BUFFER tqAddressByAddressType:HANDLE. 
            find first tqAddressByAddressType where
                tqAddressByAddressType.tiBusinessRelation_ID = tqBankNumberByParentID.tiBankBusinessRelation_ID and
                tqAddressByAddressType.tcAddressTypeCode     = {&ADDRESSTYPECODESYSTEM-PAYM}
                no-error.
    
            vhDoc:CREATE-NODE (vhSubRow4, "BankAddress":U, "ELEMENT":U).
            vhSubRow3:APPEND-CHILD (vhSubRow4).       

            if not available tqAddressByAddressType
            then do:
                <Q-20 run AddressByAddressType (all) (Read) (NoCache)
                   (input tqBankNumberByParentID.tiBankBusinessRelation_ID, (BusinessRelationId)
                    input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
                    output dataset tqAddressByAddressType) in BBusinessRelation >

               
                find first tqAddressByAddressType where
                    tqAddressByAddressType.tiBusinessRelation_ID = tqBankNumberByParentID.tiBankBusinessRelation_ID and
                    tqAddressByAddressType.tcAddressTypeCode     = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}
                    no-error.
            end.

            if available tqAddressByAddressType
            then do:

                vhBuf2 = BUFFER tqAddressByAddressType:HANDLE. 

                FinacialBankAddressNodes:
                REPEAT viCounter = 1 TO vhBuf2:NUM-FIELDS:
                
                    vhDBFld = vhBuf2:BUFFER-FIELD (viCounter).
                
                    if  index(vhDBFld:name,"_":U) > 0
                    or  index(vhDBFld:name,"Company":U) > 0
                    or  (vhDBFld:buffer-value = "":U and vlSuppresEmpty) 
                    then next FinacialBankAddressNodes.
            
                    
                    vhDoc:CREATE-NODE (vhSubRow5, vhDBFld:name, "ELEMENT":U).
                    vhSubRow4:APPEND-CHILD (vhSubRow5).
                        
                    vhDoc:CREATE-NODE (vhText, "":U, "TEXT":U).
                    vhSubRow5:APPEND-CHILD (vhText).
                    vhText:NODE-VALUE = string( vhDBFld:buffer-value).
                end.
            end.
        end.
        /* Get the Linked Invoices */
        vhDoc:CREATE-NODE (vhSubRow2, "Invoices":U, "ELEMENT":U).
        vhSubRow:APPEND-CHILD (vhSubRow2).

        <Q-16 run DDocumentInvoiceXrefbyId (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input tqDDocumentByCollectionID.tiDDocument_ID, (DocumentID)
            output dataset tqDDocumentInvoiceXrefbyId) in BDDocument >
        vhBuf2 = BUFFER tqDDocumentInvoiceXrefbyId:HANDLE.
        
        for each tqDDocumentInvoiceXrefbyId:

            vhDoc:CREATE-NODE (vhSubRow3, "Invoice":U, "ELEMENT":U).
            vhSubRow2:APPEND-CHILD (vhSubRow3).

            vhDoc:CREATE-NODE (vhSubRow4, "tdDInvoiceOriginalAmount":U, "ELEMENT":U).
            vhSubRow3:APPEND-CHILD (vhSubRow4).
           
            vhDoc:CREATE-NODE (vhText, "":U, "TEXT":U).
            vhSubRow4:APPEND-CHILD (vhText).
            vhText:NODE-VALUE = string(tqDDocumentInvoiceXrefbyId.tdDInvoiceOriginalDebitTC - tqDDocumentInvoiceXrefbyId.tdDInvoiceOriginalDebitTC).

            InvoiceNodes:
            REPEAT viCounter = 1 TO vhBuf2:NUM-FIELDS:
            
                vhDBFld = vhBuf2:BUFFER-FIELD (viCounter).
                
                if  index(vhDBFld:name,"_":U) > 0
                or  index(vhDBFld:name,"Original":U) > 0
                or  index(vhDBFld:name,"Custom":U) > 0    
                or  (vhDBFld:buffer-value = "":U and vlSuppresEmpty) 
                then next InvoiceNodes.
        
                vhDoc:CREATE-NODE (vhSubRow4, vhDBFld:name, "ELEMENT":U).
                vhSubRow3:APPEND-CHILD (vhSubRow4).
        
            
                vhDoc:CREATE-NODE (vhText, "":U, "TEXT":U).
                vhSubRow4:APPEND-CHILD (vhText).
                vhText:NODE-VALUE = string( vhDBFld:buffer-value).
            end.
        end.

        
    
        vhDoc:CREATE-NODE (vhSubRow2, "tiDDocument_ID":U, "ELEMENT":U).
        vhSubRow:APPEND-CHILD (vhSubRow2).

        vhDoc:CREATE-NODE (vhText, "":U, "TEXT":U).
        vhSubRow2:APPEND-CHILD (vhText).
        vhText:NODE-VALUE = string(tqDDocumentByCollectionID.tiDDocument_ID).
        
        
        vhBuf2 = BUFFER tqDDocumentByCollectionID:HANDLE. 
        DDocumentNodes:
        REPEAT viCounter = 1 TO vhBuf:NUM-FIELDS:
    
            vhDBFld = vhBuf:BUFFER-FIELD (viCounter).    

            if (index(vhDBFld:name,"_":U) > 0 or index(vhDBFld:name,"Debtor":U) > 0 or index(vhDBFld:name,"BusinessRelation":U) > 0 or index(vhDBFld:name,"Custom":U) > 0)
            or  (vhDBFld:buffer-value = "":U and vlSuppresEmpty) 
            then next DDocumentNodes.
        
            vhDoc:CREATE-NODE (vhSubRow2, vhDBFld:name, "ELEMENT":U).
            vhSubRow:APPEND-CHILD (vhSubRow2).
        
            
            vhDoc:CREATE-NODE (vhText, "":U, "TEXT":U).
            vhSubRow2:APPEND-CHILD (vhText).
            vhText:NODE-VALUE = string( vhDBFld:buffer-value).
        end.


    end.
end.

  
/* Write the XML node tree to an xml file. */
<Q-15 run DebtorByDebtor
   (Stop) in BDebtor >

vhDoc:SAVE ("memptr":U, vmMyXml).

viCounter2= 0.
REPEAT viCounter = 1 TO (GET-SIZE(vmMyXml) - (GET-SIZE(vmMyXml) MOD 128)) BY 128:
    assign viCounter2 = viCounter2 + 1.
           vcLine128  = GET-STRING(vmMyXml,viCounter,128).

    create tExport.
    assign tExport.tcValue = vcLine128
           tExport.tiSeq   = viCounter2. 
END.

assign vcLine128 = GET-STRING(vmMyXml,viCounter,GET-SIZE(vmMyXml) -  viCounter + 1).

assign viCounter2 = viCounter2 + 1.
create tExport.
assign tExport.tcValue = vcLine128
       tExport.tiSeq   = viCounter2. 

set-size (vmMyXml) = 0.

DELETE OBJECT vhDoc.
DELETE OBJECT vhRoot.
DELETE OBJECT vhRow.
DELETE OBJECT vhSubRow.
DELETE OBJECT vhSubRow2.
DELETE OBJECT vhSubRow3.
DELETE OBJECT vhSubRow4.
DELETE OBJECT vhSubRow5.
DELETE OBJECT vhField.
DELETE OBJECT vhText.
delete object vhDBFld.
DELETE OBJECT vhBuf.
DELETE OBJECT vhBuf2.