Wednesday 30 December 2015

How to integrate VB.NET application with Tally ERP 9.0?

Introduction

        This article focuses on how to integrate the .NET Applications with Tally Accounting Software. Using Tally APIhttp://localhost:9000.

       The developers can pull data from Tally Software into their .NET application or push data from their .NET application into Tally Software.

If we need to pull/push the data must be opened tally software and .NET application.

Environment Setup

            These are the steps for that – first install the software, then configure it, and finally try the XML/HTTP interface to interact with it

1.Install Tally 7.0 OR Tally ERP 9.0 Software.(Educational Version)
2.Instal the Visual studio 2008(Express Edition).
3.Optional SQL Server Express Edition.

Using the code

Push data from their .NET application into Tally Software.

We need to  push data from their .NET application to tally software through tally API http://localhost:9000 with XML/HTPP request.

We will see this article, create, alter and delete the party Ledgers. 
VB.NET Code
//
//Send XML data through TallyPushData functions.
//

Private Sub TallyPushData(ByVal XMLData As String)

        Dim TallyRequest As WebRequest
        Dim RequestXML As String = ""
        RequestXML = XMLData ' Called XML Function
        TallyRequest = WebRequest.Create("http://localhost:9000")
        CType(TallyRequest, HttpWebRequest).UserAgent = ".NET Framework Example Client"
        TallyRequest.Method = "POST"
        Dim postData As String = RequestXML
        Dim byteArray() As Byte = Encoding.UTF8.GetBytes(postData)
        TallyRequest.ContentType = "application/x-www-form-urlencoded"
        TallyRequest.ContentLength = byteArray.Length
        Try
            Dim dataStream As Stream = TallyRequest.GetRequestStream
            dataStream.Write(byteArray, 0, byteArray.Length)
            dataStream.Close()
            Dim response1 As WebResponse = TallyRequest.GetResponse
            Dim Response As String = CType(response1, HttpWebResponse).StatusDescription.ToString
            dataStream = response1.GetResponseStream
            Dim reader As StreamReader = New StreamReader(dataStream)
            Dim responseFromTallyServer As String = reader.ReadToEnd.ToString
            Dim ErrorCheck As Integer = 0
            ErrorCheck = InStrRev(responseFromTallyServer, "<LINEERROR>")
            Dim BA As Boolean
            qry = responseFromTallyServer
            BA = qry.Contains("<ERRORS>1</ERRORS>")
If ErrorCheck = 0 And BA = False Then
                Dim TallyResponseDataSet As DataSet = New DataSet
                TallyResponseDataSet.ReadXml(New StringReader(responseFromTallyServer))
                MasterId = ""
                qry = ""
                qry = responseFromTallyServer
                Tem = qry.IndexOf("<LASTVCHID>") + "<LASTVCHID>".Length
                Tem1 = qry.IndexOf("</LASTVCHID>")
                MasterId = qry.Substring(CInt(Tem), CInt(Tem1 - Tem)).Trim
                reader.Close()
                dataStream.Close()
                response1.Close()
                byteArray = Nothing
                Response = Nothing
                responseFromTallyServer = Nothing
                Response = Nothing
                dataStream = Nothing
            Else
                MsgBox("Failed to POST " & responseFromTallyServer & " ",  MsgBoxStyle.Critical)
            End If
        Catch ex As Exception
            MsgBox(ex.Message.ToString, MsgBoxStyle.Critical)
        End Try
    End Sub

Create Ledger XML Code
Private Sub CreateXMLParty(ByVal LedgerName As String, ByVal MailingName As String, ByVal Address As String, ByVal Email As String, ByVal Pincode As String, ByVal Opening As String, ByRef CreditDebit As String, ByVal Group As String, ByVal Phoneno As String, ByVal TinNo As String, ByVal SalesTaxNo As String)

        Dim x As String = ""
        x = "<ENVELOPE>"
        x = (x + "<HEADER>")
        x = (x + "<TALLYREQUEST>Import Data</TALLYREQUEST>")
        x = (x + "</HEADER>")
        x = (x + "<BODY>")
        x = (x + "<IMPORTDATA>")
        x = (x + " <REQUESTDESC>")
        x = (x + "<REPORTNAME>All Masters</REPORTNAME>")
        x = (x + "</REQUESTDESC>")
        x = (x + "<REQUESTDATA>")
        x = (x + "<TALLYMESSAGE xmlns:UDF='TallyUDF'>")
        x = (x + " <LEDGER NAME='" & LedgerName & "' ACTION='Create'>")
        x = (x + "<MAILINGNAME.LIST>")
        x = (x + "<MAILINGNAME>" & MailingName & "</MAILINGNAME>")
        x = (x + "</MAILINGNAME.LIST>")
        x = (x + " <ADDRESS>" & Address & " </ADDRESS>")
        x = (x + "<STATENAME></STATENAME>")
        x = (x + "<PINCODE>" & Pincode & "</PINCODE>")
        x = (x + "<LEDGERCONTACT></LEDGERCONTACT>")
        x = (x + "<LEDGERPHONE>" & Phoneno & "</LEDGERPHONE>")
        x = (x + "<LEDGERFAX></LEDGERFAX>")
        x = (x + " <LEDGERMOBILE>" & Phoneno & "</LEDGERMOBILE>")
        x = (x + "<EMAIL>" & Email & "</EMAIL>")
        x = (x + "<INCOMETAXNUMBER >" & TinNo & "</INCOMETAXNUMBER>") ' IT/PAN Number
        x = (x + "<VATTINNUMBER></VATTINNUMBER>")
        x = (x + "<CSTNUMBER></CSTNUMBER>")
        x = (x + "<SALESTAXNUMBER>" & SalesTaxNo & "</SALESTAXNUMBER>")
        x = (x + " <OPENINGBALANCE>" & Opening & "" & " " & CreditDebit & " </OPENINGBALANCE>")
        x = (x + " <NAME.LIST><NAME> " & LedgerName & "</NAME></NAME.LIST>")
        x = (x + "  <PARENT>" & Group & "</PARENT>")
        x = (x + " <ISSUBLEDGER>No</ISSUBLEDGER>")
        x = (x + "  <ISBILLWISEON>No</ISBILLWISEON>")
        x = (x + " <ISCOSTCENTRESON>No</ISCOSTCENTRESON>")
        x = (x + "</LEDGER>")
        x = (x + "</TALLYMESSAGE>")
        x = (x + "</REQUESTDATA>")
        x = (x + "</IMPORTDATA>")
        x = (x + "</BODY>")
        x = (x + "</ENVELOPE>")
        TallyPushData(x)
    End Sub

Delete Ledger XML Code
Private Sub DeleteXMLParty(ByVal LedgerName As String)

        Dim x As String = ""
        x = (x + "<ENVELOPE>")
        x = (x + "<HEADER>")
        x = (x + "<TALLYREQUEST>Import Data</TALLYREQUEST>")
        x = (x + "</HEADER>")
        x = (x + "<BODY>")
        x = (x + "<IMPORTDATA>")
        x = (x + "<REQUESTDESC>")
        x = (x + "<REPORTNAME>All Masters</REPORTNAME>")
        x = (x + "</REQUESTDESC>")
        x = (x + "<REQUESTDATA>")
        x = (x + "<TALLYMESSAGE xmlns:UDF='TallyUDF'>")
        x = (x + "<LEDGER NAME='" & LedgerName & "' ACTION='Delete'>")
        x = (x + "<NAME.LIST>")
        x = (x + "<NAME>" & LedgerName & "</NAME>")
        x = (x + "</NAME.LIST>")
        x = (x + "</LEDGER>")
        x = (x + "</TALLYMESSAGE>")
        x = (x + "</REQUESTDATA>")
        x = (x + "</IMPORTDATA>")
        x = (x + "</BODY>")
        x = (x + "</ENVELOPE>")
        TallyPushData(x)
    End Sub
Alter Ledger XML Code
private Sub AlterXMLParty(ByVal LedgerName As String, ByVal MailingName As String, ByVal Address As String, ByVal Email As String, ByVal Pincode As String, ByVal Opening As String, ByRef CreditDebit As String, ByVal Group As String, ByVal OldLedgerName As String, ByVal Phoneno As String, ByVal TinNo As String, ByVal SalesTaxNo As String)
        Dim x As String = ""
        x = "<ENVELOPE>"
        x = (x + "<HEADER>")
        x = (x + "<TALLYREQUEST>Import Data</TALLYREQUEST>")
        x = (x + "</HEADER>")
        x = (x + "<BODY>")
        x = (x + "<IMPORTDATA>")
        x = (x + " <REQUESTDESC>")
        x = (x + "<REPORTNAME>All Masters</REPORTNAME>")
        x = (x + "</REQUESTDESC>")
        x = (x + "<REQUESTDATA>")
        x = (x + "<TALLYMESSAGE xmlns:UDF='TallyUDF'>")
        x = (x + " <LEDGER NAME='" & OldLedgerName & "' ACTION='Alter'>")
        x = (x + "<NAME>" & LedgerName & "</NAME>")
        x = (x + "<MAILINGNAME.LIST>")
        x = (x + "<MAILINGNAME>" & LedgerName & "</MAILINGNAME>")
        x = (x + "</MAILINGNAME.LIST>")
        x = (x + " <ADDRESS>" & Address & " </ADDRESS>")
        x = (x + "<EMAIL>" & Email & "</EMAIL>")
        x = (x + "<STATENAME></STATENAME>")
        x = (x + "<PINCODE>" & Pincode & "</PINCODE>")
        x = (x + "<LEDGERCONTACT></LEDGERCONTACT>")
        x = (x + "<LEDGERPHONE>" & Phoneno & "</LEDGERPHONE>")
        x = (x + "<LEDGERFAX>0000</LEDGERFAX>")
        x = (x + "<EMAIL>" & Email & "</EMAIL>")
        x = (x + "<INCOMETAXNUMBER> " & TinNo & " </INCOMETAXNUMBER>")
        x = (x + " <VATTINNUMBER></VATTINNUMBER>") 
        x = (x + "<SALESTAXNUMBER> " & SalesTaxNo & " </SALESTAXNUMBER>")
        x = (x + " <OPENINGBALANCE>" & Opening & "</OPENINGBALANCE>")
        x = (x + " <NAME.LIST><NAME> " & LedgerName & "</NAME></NAME.LIST>")
        x = (x + "  <PARENT>" & Group & "</PARENT>")
        x = (x + " <ISSUBLEDGER>No</ISSUBLEDGER>")
        x = (x + "  <ISBILLWISEON>No</ISBILLWISEON>")
        x = (x + " <ISCOSTCENTRESON>No</ISCOSTCENTRESON>")
        x = (x + "</LEDGER>")
        x = (x + "</TALLYMESSAGE>")
        x = (x + "</REQUESTDATA>")
        x = (x + "</IMPORTDATA>")
        x = (x + "</BODY>")
        x = (x + "</ENVELOPE>")
        TallyPushData(x)
    End Sub

References

http://mirror.tallysolutions.com/Downloads/TDL%20Developer/Tally.ERP%209%20-%20Integration%20Capabilities.pdf

No comments:

Post a Comment