project QadFinancials > class TConvertInstalNETXML > method LoadXMLRepresentation


Parameters


icFileinputcharacter
imDocumentinputmemptr
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method TConvertInstalNETXML.Convert


program code (program1/tconvertinstalnetxml.p)

/* ================================================= */
/* Import the CInvoice+CInvoiceVAT from the XML-file */
/* ================================================= */
assign oiReturnStatus = -98.

empty temp-table tNETDBTableRef.
empty temp-table tNETKnownTable.
empty temp-table tNETTableRef.
empty temp-table t_oCInvoice.
empty temp-table t_oCInvoiceBank.
empty temp-table t_oCInvoiceMovement.
empty temp-table t_oCInvoicePO.
empty temp-table t_oCInvoicePosting.
empty temp-table t_oCInvoiceStage.
empty temp-table t_oCInvoiceVat.

create x-document vhDocument in widget-pool "non-persistent".

if icFile = "":U or icFile = ?
then vhDocument:load ("MEMPTR":U, imDocument, no) no-error.
else vhDocument:load ("FILE":U, icFile, no) no-error.
if error-status:num-messages > 0
then do viErrors = 1 to error-status:num-messages:
    assign vcErrors = vcErrors + chr(2) + error-status:get-message(viErrors).
end.

if vcErrors <> "":U
then do:
    <M-10 run SetMessageInLog (input  vcErrors (icMessage), 
                           output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>           
    assign oiReturnStatus = -1.
    return.
end.

/* ========================================================================================= */
/* The following peace of code is the modification of loadxmldocument in bxmldaemonprocessor */
/* Here just only root "object" + "class representation" nodes                               */
/* ========================================================================================= */
create x-noderef vhRoot in widget-pool "non-persistent".
create x-noderef vhNode in widget-pool "non-persistent".
create x-noderef vhValue in widget-pool "non-persistent".
create x-noderef vhParentNode in widget-pool "non-persistent".
create x-noderef vhNodeChild in widget-pool "non-persistent".
create x-noderef vhValueChild in widget-pool "non-persistent".
create x-noderef vhCompanyNode in widget-pool "non-persistent".

ROOT: do:
    do viCnt1 = 1 to vhDocument:num-children:
        vhDocument:get-child(vhRoot,viCnt1).
        if vhRoot:local-name = "object":U
        then leave ROOT.
    end.
    <M-14 run SetMessageInLog (input  #T-8'Invalid XML document: object node not found.':100(16040)T-8# (icMessage), 
                       output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
    assign oiReturnStatus = -3.
    return.                       
end.
    
do viCnt1 = 1 to vhRoot:num-children:

    assign oiReturnStatus    = 0
           viCompanyLoadedId = ?.
    
    vhRoot:get-child(vhNode,viCnt1).

    if vhNode:local-name = "classRepresentation":U
    then do viCnt2 = 1 to vhNode:num-children:

        vhNode:get-child(vhValue,viCnt2).
        if not vhValue:local-name = "InvoiceHeader":U
        then next.
    
        do viCnt3 = 1 to vhValue:num-children:
            
            vhValue:get-child(vhNodeChild,viCnt3).
            if not vhNodeChild:local-name = "Buyer":U
            then next.
            
            do viCnt4 = 1 to vhNodeChild:num-children:
            
                vhNodeChild:get-child(vhValueChild,viCnt4).            
            
                if vhValueChild:local-name = "PartyNumberId":U and
                   vhValueChild:num-children = 1
                then do:   
                    vhValueChild:get-child(vhCompanyNode,1).
                    
                    /* Get the proper company code */
                    if vhCompanyNode:name = "#text":U
                    then do:
                        empty temp-table tqCompanyPropertyByBusRelSimple.
                        
                        <Q-16 run BusinessRelationByEANCode (all) (Read) (NoCache)
          (input vhCompanyNode:node-value, (EANCode)
           output dataset tqBusinessRelationByEANCode) in BBusinessRelation >
                        find tqBusinessRelationByEANCode no-error.
                        if available tqBusinessRelationByEANCode
                        then do:
                            <Q-19 run CompanyPropertyByBusRelSimple (all) (Read) (NoCache)
          (input ?, (CompanyId)
           input ?, (CompanyCode)
           input tqBusinessRelationByEANCode.tcBusinessRelationCode, (BusinessRelationCode)
           output dataset tqCompanyPropertyByBusRelSimple) in BCompanyProperty >
                            find tqCompanyPropertyByBusRelSimple no-error.
                        end.
                        
                        if not available tqCompanyPropertyByBusRelSimple
                        then do:
                            assign vcMessage = trim(substitute(#T-18'Invalid EAN code (&1) for entity business relation.':255(16092)T-18#, "<InvoiceHeader.Supplier.GLN>":U + vhCompanyNode:node-value + "</InvoiceHeader.Supplier.GLN>":U)).
                            <M-17 run SetMessageInLog (input  vcMessage (icMessage), 
                           output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>           
                            assign oiReturnStatus = -3.
                            return.
                        end.
                        else assign viCompanyLoadedId = tqCompanyPropertyByBusRelSimple.tiCompany_ID.

                        /* generic run of business method */
                        assign vcTables = "":U.
                        for each tNETDynRel:
                            assign vcTables = vcTables + ",":U + string(tNETDynRel.thFcBuffer)
                                                       + ",":U + tNETDynRel.tcFcTo.
                        end.
                        
                        <M-15 run ConvertXmlToTable
                           (input  {&TARGETPROCEDURE} (ihComponent), 
                            input  vhValue (ihParentNode), 
                            input  substring(vcTables,2,-1,'CHARACTER':U) (icTables), 
                            output tNETDBTableRef (tNETTableRef), 
                            output oiReturnStatus (oiReturnStatus)) in TConvertInstalNETXML>
                        assign vcMessage = trim(substitute(#T-20'XML Load on file &1':255(16218)T-20#, icFile)) + ' ':U +
                                           (if oiReturnStatus = 0
                                            then trim(#T-21'succeeded.':255(16097)T-21#)
                                            else trim(#T-22'The action did not succeed.':255(16098)t-22#)).
                        <M-23 run SetMessageInLog (input  vcMessage (icMessage), 
                           output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
                        
                        if oiReturnStatus < 0
                        then return.
                    end.
                end.
            end.
        end.    
    end.
end.

delete object vhValue.
delete object vhNode.
delete object vhRoot.
delete object vhParentNode.
delete object vhNodeChild.
delete object vhValueChild.
delete object vhCompanyNode.

if oiReturnStatus = -98
then oiReturnStatus = 0.