Friday 9 November 2012

Tally ERP 9's Web Service Architecture (Introduction to JAVA to Tally Integration)




Are you looking for finding out ways to connect your application with Tally database. Well if so then this is the right page which will introduce you to Tally's Web Service Architecture which is the best way to integrate Tally with outside technology.
However before you go further with the introduction, my assumption is that you already know basics of Tally along with Tally's XML schema and if not then watch the following video for the basic idea of Tally's XML:

Alternate link

The following is a working java code which sends a payment voucher to Tally database through SOAP request into the Web Service Architecture of Tally and fetches a response from Tally indicating the action taken by Tally for the request in XML format.
Check it out.


1: Go to "Gateway of Tally >> F12 Configure >> Advanced Configuration" settings (Some initial settings needed to be done inside Tally)




2: Request by the Java application code

package tallyrequest;

import java.io.*;
import java.net.*;

/**
 *
 * @author SUNEET
 */
public class TallyRequest{
   
    public String CreateRequest()
    {             
        String TXML = null;

        TXML = "<ENVELOPE>"
                + "<HEADER><TALLYREQUEST>Import Data</TALLYREQUEST></HEADER>"
                + "<BODY>"
                + "<IMPORTDATA>"
                + "<REQUESTDESC><REPORTNAME>Vouchers</REPORTNAME><STATICVARIABLES><SVCURRENTCOMPANY>Company</SVCURRENTCOMPANY></STATICVARIABLES></REQUESTDESC>"
                + "<REQUESTDATA>"
                + "<TALLYMESSAGE xmlns:UDF=\"TallyUDF\">"
                + "<VOUCHER REMOTEID=\"00000001\" VCHTYPE=\"Receipt\" ACTION=\"Create\" OBJVIEW=\"Accounting Voucher View\">"      
                + "<DATE>20140401</DATE>"
                + "<VOUCHERTYPENAME>Receipt</VOUCHERTYPENAME>"
                + "<VOUCHERNUMBER>1</VOUCHERNUMBER>"
                + "<PARTYLEDGERNAME>Cash</PARTYLEDGERNAME>"
                + "<PERSISTEDVIEW>Accounting Voucher View</PERSISTEDVIEW>"      
                + "<ALLLEDGERENTRIES.LIST>"
                + "<LEDGERNAME>Capital Account</LEDGERNAME>"
                + "<ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE>"
                + "<AMOUNT>50000.00</AMOUNT>"       
                + "</ALLLEDGERENTRIES.LIST>"
                + "<ALLLEDGERENTRIES.LIST>"      
                + "<LEDGERNAME>Cash</LEDGERNAME>"
                + "<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>"
                + "<AMOUNT>-50000.00</AMOUNT>"          
                + "</ALLLEDGERENTRIES.LIST>"    
                + "</VOUCHER>"
                + "</TALLYMESSAGE>"
                + "</REQUESTDATA>"
                + "</IMPORTDATA>"
                + "</BODY>"
                + "</ENVELOPE>";
        return TXML;
    }
   
    public void SendToTally() throws Exception{
        String Url = "http://127.0.0.1:9000/";      

        String SOAPAction = "";
       
        String Voucher = this.CreateRequest();

// Create the connection where we're going to send the file.
        URL url = new URL(Url);
        URLConnection connection = url.openConnection();
        HttpURLConnection httpConn = (HttpURLConnection) connection;

       
        ByteArrayInputStream bin = new ByteArrayInputStream(Voucher.getBytes());
        ByteArrayOutputStream bout = new ByteArrayOutputStream();

// Copy the SOAP file to the open connection.
       
        copy(bin, bout);     

        byte[] b = bout.toByteArray();

// Set the appropriate HTTP parameters.
        httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
        httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
        httpConn.setRequestProperty("SOAPAction", SOAPAction);
        httpConn.setRequestMethod("POST");
        httpConn.setDoOutput(true);
        httpConn.setDoInput(true);

// Everything's set up; send the XML that was read in to b.
        OutputStream out = httpConn.getOutputStream();
        out.write(b);
        out.close();

// Read the response and write it to standard out.

        InputStreamReader isr =
                new InputStreamReader(httpConn.getInputStream());
        BufferedReader in = new BufferedReader(isr);

        String inputLine;

        while ((inputLine = in.readLine()) != null) {
            System.out.println(inputLine);
        }

        in.close();
    }

    public static void copy(InputStream in, OutputStream out)
            throws IOException {

// do not allow other threads to read from the
// input or write to the output while copying is
// taking place

        synchronized (in) {
            synchronized (out) {

                byte[] buffer = new byte[256];
                while (true) {
                    int bytesRead = in.read(buffer);
                    if (bytesRead == -1) {
                        break;
                    }
                    out.write(buffer, 0, bytesRead);
                }
            }
        }
    }
   
    public static void main(String[] args) throws Exception {
        TallyRequest r = new TallyRequest();
        r.SendToTally();
    }
}



3: Response by the Tally Web Service Architecture




4: Voucher inserted inside Tally

Saturday 8 September 2012

Tally ERP 9 to Java via ODBC bridge


The following is the working java code to extract consolidated data from Tally Database. 
Note: Type the following code by changing the 'TallyODBC' name to the 'TallyODBC' name in your PC and the compile but before running the code make sure that your 'Tally.exe' is running as an administrator especially if its Windows 7.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

/**
 *
 * @author SUNEET
 */
public class TallyODBC {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO codimporte application logic here
        try {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

              Connection con = DriverManager.getConnection("jdbc:odbc:TallyODBC_9696", "", "");
              Statement stmt = (Statement) con.createStatement();
              ResultSet rs = stmt.executeQuery("SELECT StockItem.`$Parent`, StockItem.`$Name`, StockItem.`$BaseUnits`, StockItem.`$OpeningBalance`, StockItem.`$_InwardQuantity`, StockItem.`$_OutwardQuantity`, StockItem.`$_ClosingBalance` FROM SuneetLtd.TallyUser.StockItem StockItem ORDER BY StockItem.`$Parent`");
           
              int numberOfColumns = rs.getRow();
              int rowCount = 1;
              while (rs.next()) {
                  //for(int i = 0; i < 7; i++){
                       int op = Integer.parseInt(rs.getString("StockItem.`$OpeningBalance`").substring(0, (rs.getString("StockItem.`$OpeningBalance`").length() - 3)).trim());
                       int in = Integer.parseInt(rs.getString("StockItem.`$_InwardQuantity`").substring(0, (rs.getString("StockItem.`$_InwardQuantity`").length() - 3)).trim());
                       int out = Integer.parseInt(rs.getString("StockItem.`$_OutwardQuantity`").substring(0, (rs.getString("StockItem.`$_OutwardQuantity`").length() - 3)).trim());
                       int cl = Integer.parseInt(rs.getString("StockItem.`$_ClosingBalance`").substring(0, (rs.getString("StockItem.`$_ClosingBalance`").length() - 3)).trim());
                       System.out.println(rs.getString("StockItem.`$Parent`") + " \t " + rs.getString("StockItem.`$Name`") + " \t " + rs.getString("StockItem.`$BaseUnits`") + " \t " + op + " \t " + in + " \t " + out + " \t " + cl);
                  //}            
                rowCount++;
              }
              //System.out.println(rowCount);
              stmt.close();
              con.close();
          } catch (Exception e) {
          System.out.println(e);
        }
    }
}

Output:

Raw Materials R 1 nos 5000 5000 0 10000
Raw Materials R 2 nos 7000 8000 0 15000

More Coming Soon

Friday 18 May 2012

The Boss of ERP System/Center of an ERP System




Accounting Module is the center of an ERP System, for every other module is directly or indirectly linked with accounts. And most strange of all even Quality Control links to accounting as without Raw Material or Finished Goods passed by Q.C. is not considered to be Purchases or Sales respectively.
Its truly the Boss of an ERP System as every Module links and ultimately reports to the Accounting Module.

Friday 4 May 2012

System/ERP Analysis


Work of System/ERP Analysis is very much like a game of chess. 
Just like a genius chess player foresees his moves, an analyst too has to foresee the development and implementation moves. If an analyst discovers new things which he failed to foresee during analysis period then its nothing but bad analysis. As those new things discovered during the development or implementation period are the direct cause of the delay in the project by demanding complete re-designing of the System.

Saturday 21 April 2012

Intrinsic Philosophy of RDBMS



The basic idea is that a data becomes meaningful only when 2 dimensions of the data are defined.
This is the Quantum level of Relational Database Management System.

Simple and amazing isn't it?

Monday 30 January 2012

The Origin of Programming Languages



It all started with invention of P.L.A.D.C. (Programmable Logic Array Digital Circuit) or P.L.D.:

P.L.A.D.C. gave birth to programming concept with Machine Languages.
Before P.L.D. only Digital Logic Circuits existed.
The invention of P.L.D. gave birth to the concept of programming itself. This was a monumental shift in the image of computers. 
Machine Language
The P.L.D. was such a device that could convert itself into any D.L.C. according to the signals sent in electronic impulses which were high and low combinations. The high and low states were named as 0s and 1s respectively and thereby called as machine language.
While machine languages were the first programming languages, it involved a process called debugging. You may know what is debugging (in higher level languages the compiler or the IDE does automatic debugging) but when machine languages were used debugging was manual. This was definitely a tedious work and the higher-level language programmers of today definitely won't do it as they are used to relatively much more sophisticated environment.  
Assembly Language  
In assembly language the 0s and 1s were replace by mnemonics. Example '1010' was replaced with 'A'. Here programming became much easier and understandable until of course there was a shift in the complexities of the functionality demanded. 
Third Generation Languages
When more and more complexities were demanded these mnemonics in the assembly language too became relatively complex for the programmers. This lead to the creation of Third Generation languages such as C, PASCAL, BASIC etc. and later on OOPs based languages like C++, Java, C# etc.
To be continued......