A web service running on the remote server is used to extract data from the external data base. It sends the response in the following XML format based on the data available in the database.
<ENVELOPE>
<HEADER>
<VERSION>version</VERSION>
<TALLYREQUEST>Import</TALLYREQUEST>
<TYPE>DATA</TYPE>
<STATUS>1</STATUS>
</HEADER>
<BODY>
<DATA>
<STKITNAME>
<ITNAME>Item 1</ITNAME>
<STKBAT>
<BATNAME>B1</BATNAME>
<BATQTY>100</BATQTY>
<BATRATE>10</BATRATE>
<BATAMT>1000</BATAMT>
</STKBAT>
<STKBAT>
<BATNAME>B2</BATNAME>
<BATQTY>10</BATQTY>
<BATRATE>10</BATRATE>
<BATAMT>100</BATAMT>
</STKBAT>
</STKITNAME>
<STKITNAME>
<ITNAME>Item 2</ITNAME> <STKBAT>
<BATNAME>B3</BATNAME>
<BATQTY>100</BATQTY>
<BATRATE>10</BATRATE>
<BATAMT>1000</BATAMT>
</STKBAT>
<STKBAT>
<BATNAME>B4</BATNAME>
<BATQTY>10</BATQTY>
<BATRATE>10</BATRATE>
<BATAMT>100</BATAMT>
</STKBAT>
</STKITNAME>
</DATA>
</BODY>
</ENVELOPE>
Tally can use the web service to fetch data from the data base and perform following operation:
● Display the retrieved data in Tally as a Report
● Retrieve data based on the request sent by Tally
● Send the request based on user input to the web server and display the response in a report
Display the retrieved data in Tally as a Report:
To retrieve the data from the database the STKXML.php page is used and this page sends the response to Tally in the XML format mentioned above.
To display the data as a report in Tally, a TDL report needs to be designed. A line in the report repeats over a collection of objects obtained from the XML. As the header information is also available in the XML, XML Object Path attributes must be used to specify the node from which the data should be retrieved in collection.
A collection is created as follows:
[Collection : STKItColl]
Remote URL : "http://remoteserver/STKXML.php"
XML Object Path : STKITNAME:1:ENVELOPE:BODY:1:DATA:1
In the part definition a line is repeated over the collection STKItColl as shown:
[Part : StkItDisp]
Line : StkItDisp
Repeat : StkItDisp : STKItColl
In this line only the Name can be displayed as there are multiple batches the line should be exploded to display the Batch Details.
[Line : StkItDisp]
Field : StkItDispNm
Explode : StkItDispBat
In the exploded part the line must be repeated over the collection StkBat in order to display the batch details.
[Part :StkItDispBat]
Line : StkItDispBat
Repeat: StkItDispBat :STKBAT
Data Retrieval based on the request sent by Tally:
In the scenario when the data is to be retrieved based on the request sent by Tally.ERP 9, Request report should be designed. Consider that this report generates the following XML format which is sent to the web server running the php page:
<ENVELOPE>
<HEADER>
<VERSION>version</VERSION>
<TALLYREQUEST>Export</TALLYREQUEST>
<TYPE>DATA</TYPE>
</HEADER>
<BODY>
<DATA>
<SVSTKITEM> Item 1 </SVSTKITEM>
</DATA>
</BODY>
</ENVELOPE>
The Item name is sent along with the request and all the batches of this item should be retrieved from the data base.
The collection is defined as follows:
[Collection : STKItColl]
Remote URL : "http://remoteserver/STKXML.php"
XML Object Path : STKITNAME:1:ENVELOPE:BODY:1:DATA:1
Remote Request : StkItReq :ASCII
The report "StkItReq" generates the XML format which is sent from Tally to the web service. The Request report "StkItReq" must contain two parts to provide the Header and Body tag informa-tion.
[From : StkItReq]
Part : StkItReqh, StkItReqb
The parts will have the tags "HEADER" and "BODY" respectively. The attribute Scroll : Vertical must be specified for in both the parts.
[Part : StkItReqh]
XML TAG : "HEADER"
The three fields in the line will have tags "VERSION", "TALLYREQUEST" and "TYPE" respec-tively. These are hard coded in this scenario.
[Part : StkItReqb]
XML TAG : "BODY"
The Line in the part StkItReqb will have the XML tag as "DATA"
[Line : StkItReqbln]
Field : StkItReqbfld
XML TAG: DATA
The field contains the XML tag as " SVStkItem". The Item name passed as the value of the field in the request sent as XML.
[Field: StkItReqbfld]
Set As : ##SVStkItem
XML TAG: SVSTKITEM
The following response is received from the web service
<ENVELOPE>
<HEADER>
<VERSION>version</VERSION>
<TALLYREQUEST>Import</TALLYREQUEST>
<TYPE>DATA</TYPE>
<STATUS>1</STATUS>
</HEADER>
<BODY>
<DATA>
<STKITNAME>
<ITNAME>Item 1</ITNAME> <STKBAT>
<BATNAME>B1</BATNAME>
<BATQTY>100</BATQTY>
<BATRATE>10</BATRATE>
<BATAMT>1000</BATAMT>
</STKBAT>
<STKBAT>
<BATNAME>B2</BATNAME>
<BATQTY>10</BATQTY>
<BATRATE>10</BATRATE>
<BATAMT>100</BATAMT>
</STKBAT>
</STKITNAME>
</DATA>
</BODY>
</ENVELOPE>
Data Retrieval based on the user input sent as request to the web server:
The data to be sent in the request can be accepted from the user. User can enter the name of the Item in the Pre Request Report. The values entered in the fields are passed through global variables to the request report. The Collection is defined as follows:
Example
[Collection : STKItColl]
Remote URL : "http://remoteserver/STKXML.php"
XML Object Path : STKITNAME:1:ENVELOPE:BODY:1:DATA:1
Remote Request : StkItReq, StkItPreReqRep :ASCII
The Pre Request Report "StkItPreReqRep" is created as a simple report which accepts the name of Stock Item from the user and stores the value in a global variable.
[Field : StkPreReqFld]
Modifies : SVStkItem
[System: Variables]
SVStkItem : ""
[Variable: SVStkItem]
Type : String
In the Request Report, the variables value is set in a field as follows:
[Field : StkItReqbfld]
Set As : ##SVStkItem
XML TAG: SVSTKITEM
Data Storage in External Database using data input in Tally
Consider the scenario when the batch details corresponding to a particular Stock Item are entered by the user in a report in Tally. This data needs to be sent to the Web Service which interacts and stores data in the External Database.
The data can be sent to the web service through a Request Report in two ways:
● Using the Request Report as a value for collection attribute Remote Request and referring to the collection
● Using the Request Report as parameter for action HTTP Post through a button
Specifying Request Report in Collection
In Tally a report should be designed to send the request to the web service using the collection attribute Remote Request.
The collection is created as follows:
[Collection : STKItColl]
Remote URL : "http://remoteserver/STKXML.php"
XML Object Path : STKITNAME: 1: ENVELOPE: BODY: 1: DATA: 1
Remote Request : StkItReq, StkPreReq :ASCII
The report "StkItReq" generates the XML format which is sent from Tally to the web service. The pre-request report "StkPreReq" is executed first and the data entered by the user is passed to the request report "StkItReq" . The request report "StkItReq" generates the XML and send s it to the web server in following format.
<ENVELOPE>
<HEADER>
<VERSION>version</VERSION>
<TALLYREQUEST>Export</TALLYREQUEST>
<TYPE>DATA</TYPE>
</HEADER>
<BODY>
<DATA>
<SVSTKITEM>Item 1</ SVSTKITEM >
<BATNAME>B3</BATNAME>
<BATQTY>75</BATQTY>
<BATRATE>100</BATRATE>
<BATAMT>7500</BATAMT>
</DATA>
</BODY>
</ENVELOPE>
The request report is created in the similar fashion as explained in the previous section. The web service is programmed to store the data in the database.
Specifying Request Report with HTTP Post
The button can be added to an existing report which when clicked will execute the HTTP Post action.
In case of action HTTP Post the response received is available in the collection "Parameter Collection". Based on the Success or Failure of the action appropriate message should be displayed in the Error Report and Success Reports.
The Button is defined as explained in the section " Action HTTP Post ".
To restrict the creation of new masters which are used in the XML requests using TDL,, set the value of the global variable SVImportObject to yes .
Example
The following user defined function OverrideExistingItem accepts the item name and creates the new item only when the item is not empty.
[#Import File : All Masters]
On : Import Object : $$IsStockItem:Call: OverrideExistingItem
[Function : OverrideExistingItem]
00 : IF : $$IsEmpty:$Name:StockItem:$Name
10 : Set : SVImportObject : False
20 : Msg Box : "New item " : $Name + " is ignored/not created as the stock item name is empty"
30 : Else :
40 : Set: SVImportObject : True
50 : Msg Box : "New item " : $Name + " is created"
60 : End If