Friday 7 September 2018

reading file from the XML

private void processXML( str _filename)
{

    str             filename, nodeName,nodeName1,nodeName2,nodeName3,bodynodeDDPI,bodynodevat,bodyLinesname,summarybodyname,nodename4,nodename5,getsummaryinvoicenum;
    str             getsummaryinvoiceddate;
    int             i,j,k,l,m,n,vatcount,nodevat,lineCount = 1,poLineCount=1;
    int             attachmentseqheader;
    XMLDocument XMLdoc = new XMLDocument();
    Dialog dialog      = new Dialog('Enter File Name Complete Path');
    DialogField     xmlfile;
    XMLNode         rootNode, bodyNode,bodyNode1,bodyNode2,AttNode,bodyNode3,bodyNode4,bodyNode5;
    XMLNodeList     bodyLines,childLine,childSubLine,bodyLines2,childline2,childline4,childline5;
    XMLElement      xmlElement;
    SON_SummaryDDVATInvoice     SummaryVATInvoice;
    int sequenceno = 0;
    //SON_AttachmentELMOInvoiceTmp    SON_AttachmentELMOInvoiceTmp;
    SON_AttachmentDDInvoiceTmp      SON_AttachmentDDInvoiceTmp;
    ;

    XMLdoc.load(_filename);
    if(!xmldoc.load(_filename))
    {
        box::info('Can not load xml document');
    }

    rootNode = xmldoc.documentElement();
    nodeName = rootnode.baseName();
    xmlElement = xmldoc.documentElement();

    if(rootnode.hasChildNodes())
    {
        bodyLines = rootnode.childNodes();

        for(j = 0; j< bodyLines.length(); j++)
        {
            bodyNode = bodyLines.nextNode();
            bodyLinesname = bodyNode.baseName();

            if (bodyLinesname == 'SON_DDAttachmentInvoice')
            {
            attachmentseqheader++;
            if(bodyNode.hasChildNodes())
            {
                childLine = bodyNode.childNodes();
                for(k= 0; k<childLine.length(); k++)
                {
                    lineCount = 0;
                    bodyNode1 = childLine.nextNode();

                        if(bodyNode1.hasChildNodes())
                    {
                            childLine2 = bodyNode1.childNodes();
                        nodeName3 = bodyNode1.baseName();
                        for(l= 0; l<childLine2.length(); l++)
                        {
                            bodyNode3 = childLine2.nextNode();
                            nodeName1 = bodyNode3.baseName();

                            if(nodeName1 != 'DDPI_Lines')
                            {
                                SON_AttachmentDDInvoiceTmp.FieldName  = nodeName1;
                                SON_AttachmentDDInvoiceTmp.LineNumber = 1;
                                SON_AttachmentDDInvoiceTmp.FieldValue = childLine2.item(l).text();
                                SON_AttachmentDDInvoiceTmp.AttachmentHeader = attachmentseqheader;
                                SON_AttachmentDDInvoiceTmp.insert();
                            }
                            else
                            {
                                if(childLine2.item(l).baseName() == 'DDPI_Lines')
                                {
                                lineCount++;

                                poLineCount = any2int(childLine2.item(l).text());

                                    if(bodyNode3.hasChildNodes())
                                    {
                                        childline4 = bodyNode3.childNodes();
                                        for(m= 0; m < childline4.length(); m++)
                                        {
                                        //info("1");
                                            bodyNode4 =  childline4.nextNode();
                                            //DDPI_Lines
                                            bodynodeDDPI =  bodyNode4.baseName();
                                            if(nodeName1 == 'DDPI_Lines')
                                            {
                                                SON_AttachmentDDInvoiceTmp.FieldName  = childline4.item(m).baseName();
                                                SON_AttachmentDDInvoiceTmp.LineNumber = lineCount;
                                                SON_AttachmentDDInvoiceTmp.FieldValue = strFmt("%1",childline4.item(m).text());
                                                SON_AttachmentDDInvoiceTmp.AttachmentHeader = attachmentseqheader;
                                                SON_AttachmentDDInvoiceTmp.insert();

                                            }  //if(nodeName1 == 'DDPI_Lines')

                                        }//for(m= 0; m < childline4.length(); m++)
                                    } //if(bodyNode3.hasChildNodes())

                                }//else
                                //attachmentInvoiceTmp.LineNumber = lineCount;
                                //lineCount = 0;
                            }
                            //attachmentInvoiceTmp.FieldValue = childLine2.item(l).text();
                            //attachmentInvoiceTmp.insert();
                        }//for loop l
                    }//if  body node 1
            } //for loop k
        } //if body node
            }//  if (bodyLinesname == 'SON_DDAttachmentInvoice')

            if(bodyLinesname == 'SON_DDSummaryInvoice')
            {
                if(bodyNode.hasChildNodes())
                {
                    childLine = bodyNode.childNodes();
                    for(k= 0; k<childLine.length(); k++)
                    {
                        bodyNode1 = childLine.nextNode();

                        if(bodyNode1.hasChildNodes())
                    {
                            childLine2 = bodyNode1.childNodes();
                        nodeName3 = bodyNode1.baseName();
                        for(l= 0; l<childLine2.length(); l++)
                        {
                            bodyNode3 = childLine2.nextNode();
                            nodeName1 = bodyNode3.baseName();

                            if(nodeName1 != 'Vats')
                            {
                                summaryInvIBTmp.FieldName  = nodeName1;
                                summaryInvIBTmp.LineNumber = 1;
                                summaryInvIBTmp.FieldValue = childLine2.item(l).text();
                                summaryInvIBTmp.insert();

                                if(nodeName1 == 'InvoiceNumber')
                                {
                                    getsummaryinvoicenum = childLine2.item(l).text();
                                }
                            if(nodeName1 == 'InvoiceDate')
                            {
                                    getsummaryinvoiceddate = childLine2.item(l).text();
                            }
                            }
                            else
                            {
                                if(childLine2.item(l).baseName() == 'Vats')
                                {
                                    // lineCount++;
                                     poLineCount = any2int(childLine2.item(l).text());

                                    if(bodyNode3.hasChildNodes())
                                    {
                                        childline4 = bodyNode3.childNodes();
                                        for(m= 0; m < childline4.length(); m++)
                                        {
                                            bodyNode4 =  childline4.nextNode();
                                            nodename4 = bodyNode4.baseName();

                                            if( nodename4 == 'Vat' && bodyNode4.hasChildNodes())
                                            {
                                                childline5 = bodyNode4.childNodes();
                                                SummaryVATInvoice.clear();
                                                    for(n= 0; n < childline5.length(); n++)
                                                {

                                                    bodyNode5 = childline5.nextNode();
                                                    nodename5 = bodyNode5.baseName();

                                                    if( nodename5 == 'VatPercent')
                                                    {
                                                        SummaryVATInvoice.VATPercent =any2real(strFmt("%1",childline5.item(n).text()));

                                                    }
                                                    if(nodename5 == 'WithoutVatAmount')
                                                    {
                                                        SummaryVATInvoice.WithoutVATAmount = any2real(strFmt("%1",childline5.item(n).text()));

                                                    }
                                                    if(nodename5 == 'VatAmount')
                                                    {
                                                        SummaryVATInvoice.VATAmount = any2real(strFmt("%1",childline5.item(n).text()));

                                                    }

                                                    SummaryVATInvoice.InvoiceNumber = getsummaryinvoicenum;
                                                    SummaryVATInvoice.InvoiceDate = str2Date(getsummaryinvoiceddate,321);
                                                }
                                                SummaryVATInvoice.insert();
                                            }
                                        }//for m
                                    } //if bodynode3
                                }//if Vats
                            }//else
                        }
                        }
                    }
                }

            }//if SON_DDSummaryInvoice
    } //for j loop

}//if root node

}////method closing

No comments:

Post a Comment

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,                             Transdate _deliverydate,                             ...