Monday 27 March 2017

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




This post introduces basic PHP to integrate with Tally.ERP 9.
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 PHP 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 PHP application code

$xml_str = ""
. "<ENVELOPE>"
. "<HEADER><TALLYREQUEST>Import Data</TALLYREQUEST></HEADER>"
. "<BODY>"
. "<IMPORTDATA>"
. "<REQUESTDESC><REPORTNAME>Vouchers</REPORTNAME><STATICVARIABLES><SVCURRENTCOMPANY>APB</SVCURRENTCOMPANY></STATICVARIABLES></REQUESTDESC>"
. "<REQUESTDATA>"
. "<TALLYMESSAGE xmlns:UDF=\"TallyUDF\">"
. "<VOUCHER REMOTEID=\"00000001\" VCHTYPE=\"Receipt\" ACTION=\"Create\" OBJVIEW=\"Accounting Voucher View\">"    
. "<DATE>20160401</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>";
$url = "http://localhost:9000";
$headers = array("Content-type: text/xml", "Content-length:" . strlen($xml_str), "Connection: close");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_str);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);

if(curl_errno($ch)) {
print curl_error($ch);
} else {
print "<pre>" . htmlentities($data) . "</pre>";
curl_close($ch);
}


3: Response by the Tally Web Service Architecture




4: Voucher inserted inside Tally

8 comments:

  1. Its working,
    Actually i was trying this since long time,
    unable to succeed.
    thanks once again

    ReplyDelete
  2. Such a nice blog. SMS API PHP you will be able to send messages to devices on other networks by using the PHP programming language.

    ReplyDelete
  3. it's a amazing and great coding but it is not working if i will put this file on my remote server.I'm not able to make a connection between tally and my server So can you suggest some solution for this

    ReplyDelete
  4. Thank you soo much... Its work like champ.

    But, how I can call it when my web app get any new entry, as curl url is localhost how could we use it with live web app, could you please share it as well ?

    Thank you again.

    ReplyDelete
  5. Hi,Thank you for the information blog. send personalized SMS to customers around the world get Detailed analytics and reports. Just start your Bulk SMS Campaign and own business with powerful solutions without free DLT registration.

    ReplyDelete