XML TWO INVOICES

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
tomtagaris
Posts: 113
Joined: Tue Aug 23, 2016 2:43 pm

XML TWO INVOICES

Post by tomtagaris »

I receive a file that has two invoices, one has a counterpart while the other does not have how can I copy it since it stops at the first
<?xml version="1.0" encoding="utf-8"?>
<RequestedDoc xmlns:icls="https://www.aade.gr/myDATA/incomeClassificaton/v1.0" xmlns:ecls="https://www.aade.gr/myDATA/expensesClassificaton/v1.0" xmlns="http://www.aade.gr/myDATA/invoice/v1.0">
<invoicesDoc>
<invoice>
<uid>ED1585BFFE3E992BA6E496DFF30F3543F549466B</uid>
<mark>400000000176781</mark>
<issuer>
<vatNumber>029690710</vatNumber>
<country>GR</country>
<branch>0</branch>
</issuer>
<counterpart> // This have
<vatNumber>126513345</vatNumber>
<country>GR</country>
<branch>0</branch>
<address>
<street>25η Μαρτίου</street>
<postalCode>25001</postalCode>
<city>Καλάβρυτα</city>
</address>
</counterpart>
<invoiceHeader>
<series> 0</series>
<aa>00001 </aa>
<issueDate>2020-10-01</issueDate>
<invoiceType>3.1</invoiceType>
<vatPaymentSuspension>false</vatPaymentSuspension>
<currency>EUR</currency>
</invoiceHeader>
<paymentMethods>
<paymentMethodDetails>
<type>3</type>
<amount>550.00</amount>
</paymentMethodDetails>
</paymentMethods>
<invoiceDetails>
<lineNumber>1</lineNumber>
<netValue>550</netValue>
<vatCategory>8</vatCategory>
<vatAmount>0</vatAmount>
<expensesClassification>
<ecls:classificationType>E3_102_001</ecls:classificationType>
<ecls:classificationCategory>category2_1</ecls:classificationCategory>
<ecls:amount>550.00</ecls:amount>
</expensesClassification>
</invoiceDetails>
<invoiceSummary>
<totalNetValue>550</totalNetValue>
<totalVatAmount>0</totalVatAmount>
<totalWithheldAmount>0</totalWithheldAmount>
<totalFeesAmount>0</totalFeesAmount>
<totalStampDutyAmount>0</totalStampDutyAmount>
<totalOtherTaxesAmount>0</totalOtherTaxesAmount>
<totalDeductionsAmount>0</totalDeductionsAmount>
<totalGrossValue>550</totalGrossValue>
<expensesClassification>
<ecls:classificationType>E3_102_001</ecls:classificationType>
<ecls:classificationCategory>category2_1</ecls:classificationCategory>
<ecls:amount>550.00</ecls:amount>
</expensesClassification>
</invoiceSummary>
</invoice>
<invoice>
<uid>B402850E49664EE46AE120991D1D510E8516FB0C</uid>
<mark>400000012994854</mark>
<cancelledByMark>0</cancelledByMark>
<issuer>
<vatNumber>029690710</vatNumber>
<country>GR</country>
<branch>0</branch>
</issuer> // This no
<invoiceHeader>
<series>1</series>
<aa>00004</aa>
<issueDate>2020-10-29</issueDate>
<invoiceType>11.1</invoiceType>
<vatPaymentSuspension>false</vatPaymentSuspension>
<currency>EUR</currency>
</invoiceHeader>
<paymentMethods>
<paymentMethodDetails>
<type>3</type>
<amount>723.61</amount>
</paymentMethodDetails>
</paymentMethods>
<invoiceDetails>
<lineNumber>1</lineNumber>
<netValue>637.62</netValue>
<vatCategory>2</vatCategory>
<vatAmount>82.89</vatAmount>
<incomeClassification>
<icls:classificationType>E3_561_003</icls:classificationType>
<icls:classificationCategory>category1_1</icls:classificationCategory>
<icls:amount>637.62</icls:amount>
</incomeClassification>
</invoiceDetails>
<invoiceDetails>
<lineNumber>2</lineNumber>
<netValue>2.5</netValue>
<vatCategory>1</vatCategory>
<vatAmount>0.60</vatAmount>
<incomeClassification>
<icls:classificationType>E3_561_003</icls:classificationType>
<icls:classificationCategory>category1_1</icls:classificationCategory>
<icls:amount>2.50</icls:amount>
</incomeClassification>
</invoiceDetails>
<invoiceDetails>
<lineNumber>3</lineNumber>
<netValue>0</netValue>
<vatCategory>3</vatCategory>
<vatAmount>0</vatAmount>
<incomeClassification>
<icls:classificationType>E3_561_003</icls:classificationType>
<icls:classificationCategory>category1_1</icls:classificationCategory>
<icls:amount>0</icls:amount>
</incomeClassification>
</invoiceDetails>
<taxesTotals>
<taxes>
<taxType>1</taxType>
<taxAmount>0</taxAmount>
</taxes>
</taxesTotals>
<invoiceSummary>
<totalNetValue>640.12</totalNetValue>
<totalVatAmount>83.49</totalVatAmount>
<totalWithheldAmount>0</totalWithheldAmount>
<totalFeesAmount>0</totalFeesAmount>
<totalStampDutyAmount>0</totalStampDutyAmount>
<totalOtherTaxesAmount>0</totalOtherTaxesAmount>
<totalDeductionsAmount>0</totalDeductionsAmount>
<totalGrossValue>723.61</totalGrossValue>
<incomeClassification>
<icls:classificationType>E3_561_003</icls:classificationType>
<icls:classificationCategory>category1_1</icls:classificationCategory>
<icls:amount>640.12</icls:amount>
</incomeClassification>
</invoiceSummary>
</invoice>
</invoicesDoc>
</RequestedDoc>
--------------------------------------------------------------
i use this method from edk
cXml := ohttp:ResponseBody()
pRoot := mxmlLoadString( NIL, cXml, MXML_OPAQUE_CALLBACK )



hHash := XMLtoHash( pRoot, /* start from root node */ )
cHash := XMLtoHash( pRoot, /* start from root node */ )
mxmlDelete( pRoot )

hInvoice := hHash["RequestedDoc"][ 1 ]["invoicesDoc"][1]["invoice"]//All <invoice> nodes



For i=1 TO Len(hInvoice)


// the "invoice" root node
cInv_Root := "uid: " + hInvoice[ i ]["uid"] + CRLF + ;
"mark: " + hInvoice[ i ]["mark"]



// the "invoice" node has only one [1] "issuer" node
cInv_Issuer := "issuer -> vatNumber:" +hb_HGetDef( hInvoice[ i ]["issuer"][ 1 ],"vatNumber","") + CRLF +;
"issuer -> counrty:" +hb_HGetDef( hInvoice[ i ]["issuer"][ 1 ],"country","") + CRLF +;
"issuer -> name:" + hb_HGetDef( hInvoice[ i ]["issuer"][ 1 ],"name","")


cInv_Counterpart := "counterpart -> vatNumber:" + hb_HGetDef(hInvoice["counterpart"][ 1 ],"vatNumber","") + CRLF +;
"counterpart -> country:" + hb_HGetDef(hInvoice[ i ]["counterpart"][ 1 ],"country","")// + CRLF +;
"counterpart -> branch:" + hb_HGetDef(hInvoice[ i ]["counterpart"][ 1 ],"branch","")

msginfo(cInv_Root+ CRLF +cInv_Issuer+crlf+cInv_Counterpart)

next i
The msginfo displays only what it has counterpart
A LITTLE HELP
User avatar
IMATECH
Posts: 188
Joined: Sun May 27, 2012 9:33 pm
Location: Brazil: Goiânia-GO.

Re: XML TWO INVOICES

Post by IMATECH »

Code: Select all

    LOCAL hAux := hb_Hash()
    LOCAL cXml := ohttp:ResponseBody()

    hAux['Root'] := mxmlLoadString( NIL, cXml, MXML_OPAQUE_CALLBACK )

    // 1st invoice
    hAux['Node'] := NIL
    hAux['Node'] := mxmlFindElement( hAux['Node'], hAux['Root'], "invoice", NIL, NIL, MXML_DESCEND_FIRST) /* or MXML_DESCEND */
    
    While !Empty( hAux['Node'] )
  
        // Do what you need    
        hHash := XMLtoHash( hAux['Node'] )

        // Next invoice
        hAux['Node'] := mxmlFindElement( hAux['Node'], hAux['Root'], "invoice", NIL, NIL, MXML_NO_DESCEND)
    End

    mxmlDelete( hAux['Root'])
M., Ronaldo

By: IMATECH

Imation Tecnologia
User avatar
tomtagaris
Posts: 113
Joined: Tue Aug 23, 2016 2:43 pm

Re: XML TWO INVOICES

Post by tomtagaris »

THANK YOU FOR THE ANSWER
BUT I DO NOT UNDERSTAND HOW IT WORKS CAN YOU GIVE ME MORE INFORMATION
THANKS
User avatar
IMATECH
Posts: 188
Joined: Sun May 27, 2012 9:33 pm
Location: Brazil: Goiânia-GO.

Re: XML TWO INVOICES

Post by IMATECH »

Wel ! no much to explain.
A call to mxmlFindElement (mxml) then use a loop to navigate over MXL data (then use it like in your 1st post)

Code: Select all

    /* get the XML body */
    cXml := ohttp:ResponseBody()

    /* Load the XML to mxml Lib */
    pRoot := mxmlLoadString( NIL, cXml, MXML_OPAQUE_CALLBACK )

    // Empty string
    pNode := ''

    // read the 1st invoice to it
    pNode := mxmlFindElement( pNode, pRoot , "invoice", NIL, NIL, MXML_DESCEND_FIRST) /* or MXML_DESCEND */
    
    /* Loop to read all invoces */
    While !Empty( pNode )
  
        /* Code here to save invoice data */
        hHash := XMLtoHash( pNode )

        hInvoice := hHash["RequestedDoc"][ 1 ]["invoicesDoc"][1]["invoice"]//All <invoice> nodes

        For i=1 TO Len(hInvoice)
        
            // the "invoice" root node
            cInv_Root := "uid: " + hInvoice[ i ]["uid"] + CRLF + ;
            "mark: " + hInvoice[ i ]["mark"]
            
            // the "invoice" node has only one [1] "issuer" node
            cInv_Issuer := "issuer -> vatNumber:" +hb_HGetDef( hInvoice[ i ]["issuer"][ 1 ],"vatNumber","") + CRLF +;
            "issuer -> counrty:" +hb_HGetDef( hInvoice[ i ]["issuer"][ 1 ],"country","") + CRLF +;
            "issuer -> name:" + hb_HGetDef( hInvoice[ i ]["issuer"][ 1 ],"name","")
            
            cInv_Counterpart := "counterpart -> vatNumber:" + hb_HGetDef(hInvoice["counterpart"][ 1 ],"vatNumber","") + CRLF +;
            "counterpart -> country:" + hb_HGetDef(hInvoice[ i ]["counterpart"][ 1 ],"country","")// + CRLF +;
            "counterpart -> branch:" + hb_HGetDef(hInvoice[ i ]["counterpart"][ 1 ],"branch","")
            
            msginfo(cInv_Root+ CRLF +cInv_Issuer+crlf+cInv_Counterpart)
        
        next i

        // Next invoice
        pNode := mxmlFindElement( pNode, pRoot , "invoice", NIL, NIL, MXML_NO_DESCEND)
    End

    /* release resource Lib */
    mxmlDelete( pRoot )
M., Ronaldo

By: IMATECH

Imation Tecnologia
User avatar
tomtagaris
Posts: 113
Joined: Tue Aug 23, 2016 2:43 pm

Re: XML TWO INVOICES

Post by tomtagaris »

UNFORTUNATELY IT DOES NOT WORK
WHAT CAN BE WRONG
User avatar
IMATECH
Posts: 188
Joined: Sun May 27, 2012 9:33 pm
Location: Brazil: Goiânia-GO.

Re: XML TWO INVOICES

Post by IMATECH »

You can find some samples to use hbmxml at harbour folder:
\harbour\contrib\hbmxml\tests

Code: Select all

1st invoice                             
ED1585BFFE3E992BA6E496DFF30F3543F549466B
400000000176781                         
                                        
Next                                    
B402850E49664EE46AE120991D1D510E8516FB0C
400000012994854                         
Attachments
read_invoice.7z
(1.64 KiB) Downloaded 94 times
M., Ronaldo

By: IMATECH

Imation Tecnologia
Post Reply