Case Study II – Creation and Alteration of Vouchers through VB
A Company Global Enterprises needs to design an interface for entering their receipt vouchers and altering the same, if required. At the end of Voucher Entry, the same needs to be posted to TallyPrime.
The following interface has been designed for Receipt Voucher Entry. A Company Global Enterprises needs to design an interface for entering their receipt vouchers and altering the same, if required. At the end of Voucher Entry, the same needs to be posted to TallyPrime.
The following interface has been designed for Receipt Voucher Entry.
On hitting Option Create, it enters a new form designed for Receipt Creation as shown below.
The Masters created in TallyPrime are collected and being displayed for selection by the user. Collections pertaining to Cash or Bank Ledgers and Party Ledgers have been written in a TDL File which must be associated before executing this VB code.
On hitting POST Button, XML fragment get generated and the same is being posted to TallyPrime running in a predefined port.
The VB Code for the same is:
Private Sub Command1_Click()
Dim ComboString1 As String
Dim ComboString2 As String
Dim ComboString3 As String
Dim ComboString11 As String
Dim ComboString21 As String
Dim ComboString31 As String
ComboString11 = Combo1.Text
ComboString21 = Combo2.Text
ComboString31 = Text5.Text
ComboString1 = Combo1.Text
ComboString2 = Combo2.Text
ComboString3 = Text5.Text
If Combo1.Text = “” Or Combo2.Text = “” _ Or Text1.Text = “” Or Text4.Text = “” Then MsgBox “Enters All The information”, _
vbApplicationModal, “Voucher Creation”
Else
date2 = Format(Text1.Text, “dd/mm/yyyy”) Temp = Str$(Text4.Text * -1)
If InStrRev(ComboString11, “&”) Then ComboString1 = Replace(ComboString11, “&”, “” & “”)
End If
If InStrRev(ComboString21, “&”) Then ComboString2 = Replace(ComboString21, “&”, “” & “”)
End If
If InStrRev(ComboString31, “&”) Then ComboString3 = Replace(ComboString31, “&”, “” & “”)
End If
xmlstc = “<ENVELOPE>” + vbCrLf & _ “<HEADER>” + vbCrLf & _
“<VERSION>1</VERSION>” + vbCrLf & _ “<TALLYREQUEST>Import</TALLYREQUEST>” + vbCrLf & _ “<TYPE>Data</TYPE>” + vbCrLf & _ “<ID>Vouchers</ID>” + vbCrLf & _
“</HEADER>” + vbCrLf & _ “<BODY>” + vbCrLf & _
“<DESC>” + vbCrLf & _ “</DESC>” + vbCrLf & _ “<DATA>” + vbCrLf & _
“<TALLYMESSAGE >” + vbCrLf & _
“<VOUCHER VCHTYPE=””Receipt”” ACTION=””Create””>” + vbCrLf& _ “<DATE>” + date2 + “</DATE>” + vbCrLf & _
“<NARRATION>” + ComboString3 + “</NARRATION>” + vbCrLf & _ “<VOUCHERTYPENAME>Receipt</VOUCHERTYPENAME>” + vbCrLf & _ “<EFFECTIVEDATE>” + date2 + “</EFFECTIVEDATE>” + vbCrLf & _
“<ALLLEDGERENTRIES.LIST>” + vbCrLf & _
“<LEDGERNAME>” + ComboString2 + “</LEDGERNAME>” + vbCrLf & _
“<AMOUNT>” + Text4.Text + “</AMOUNT>” + vbCrLf & _ “</ALLLEDGERENTRIES.LIST>” + vbCrLf & _ “<ALLLEDGERENTRIES.LIST>” + vbCrLf
xmlstc = xmlstc + “<LEDGERNAME>” + ComboString1 + “</LEDGERNAME>” + vbCrLf & _ “<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>” + vbCrLf & _ “<AMOUNT>” + Temp + “</AMOUNT>” + vbCrLf & _ “</ALLLEDGERENTRIES.LIST>” + vbCrLf & _
“</VOUCHER>” + vbCrLf & _ “</TALLYMESSAGE>” + vbCrLf & _ “</DATA>” + vbCrLf & _
“</BODY>” + vbCrLf & “</ENVELOPE>” ServerHTTP.Open “POST”, “http://localhost:” + PortNumber ServerHTTP.send xmlstc
‘ Response from Tally – ServerHTTP.responseText responsstr = ServerHTTP.responseText
newstring = InStrRev(responsstr, “<LINEERROR>”) If newstring = 0 Then]
XMLDOM.loadXML (responsstr)
MsgBox “Response String ” + responsstr Set CHILDNODE = _
XMLDOM.selectNodes(“ENVELOPE/BODY/DATA/IMPORTRESULT/LASTVCHID”) MsgBox “Voucher Created with MASTER ID ” +
CHILDNODE(0).Text, ,”Voucher Creation”
Else
MsgBox “Failed to POST”
End If
responsestr = ServerHTTP.responseText Text4.Text = “”
Text5.Text = “”
End If
End Sub
Similar to Master Import, the following VB Code snippet sends the above generated XML Data to TallyPrime which is running at a predefined port.
ServerHTTP.Open “POST”, “http://localhost:” + PortNumber ‘for example: http://localhost:9000
ServerHTTP.send xmlstc
On creating Vouchers in TallyPrime, it sends the Response is parsed and Master ID is displayed as shown above.
The above Screen displays the Receipt Entry created from the external Interface.
The above Interface is designed for Receipt Alteration based on Master ID of all the Vouchers. It lists the Master IDs of all the Receipt Vouchers in the List Box. On selection of a Master ID, it extracts all the Info pertaining to the selected Voucher as shown in the next figure.
The above Interface displays the details of the Voucher pertaining to the selected Master ID. Only Alteration of Amount and Narration have been allowed in the external interface alteration.
Amount has been altered from 12000 to 12600. On hitting Alter, XML Fragment will be generated and sent to Tally running at a predefined port.
XML generated for Altering the above is:
Private Sub Command1_Click ()
Dim ComboString1 As String
Dim ComboString2 As String
Dim ComboString3 As String
Dim ComboString11 As String
Dim ComboString21 As String
Dim ComboString31 As String
ComboString11 = Text2.Text
ComboString21 = Text3.Text
ComboString31 = Text5.Text
ComboString1 = Text2.Text
ComboString2 = Text3.Text
ComboString3 = Text5.Text
If InStrRev(ComboString11, “&”) Then
ComboString1 = Replace(ComboString11, “&”, “” & “”)
End If
If InStrRev(ComboString21, “&”) Then
ComboString2 = Replace(ComboString21, “&”, “” & “”)
End If
If InStrRev(ComboString31, “&”) Then
ComboString3 = Replace(ComboString31, “&”, “” & “”)
End If
date2 = Format(Text1.Text, “dd-mmm-yyyy”) If Text4.Text = “” Then
MsgBox (“Please enter some value”) Text4.SetFocus
Else
Temp = Str$(Text4.Text * -1) xmlstc = _
“<ENVELOPE>” + vbCrLf & _ “<HEADER>” + vbCrLf & _ “<VERSION>1</VERSION>” & _
“<TALLYREQUEST>Import</TALLYREQUEST>” + vbCrLf & _ “<TYPE>Data</TYPE>” + vbCrLf & _ “<ID>Vouchers</ID>” + vbCrLf & _
“</HEADER>” + vbCrLf & _ “<BODY>” + vbCrLf & _ “<DESC>” + vbCrLf & _ “</DESC>” + vbCrLf & _ “<DATA>” + vbCrLf & _
“<TALLYMESSAGE>” + vbCrLf & _
“<VOUCHER DATE=” + “””” + date2 + “””” + “TAGNAME=””MASTER ID”” TAGVALUE=” + “””” + List1.Text + “””” + ” ACTION=””Alter”” VCHTYPE = “”Receipt””>” + vbCrLf & _
xmlstc = xmlstc & _ “<ALLLEDGERENTRIES.LIST>” + vbCrLf & _
“<LEDGERNAME>” + ComboString2 + “</LEDGERNAME>” + vbCrLf & _ “<AMOUNT>” + Text4.Text + “</AMOUNT>” + vbCrLf & _ “</ALLLEDGERENTRIES.LIST>” + vbCrLf & _ “<ALLLEDGERENTRIES.LIST>” + vbCrLf & _
“<LEDGERNAME>” + ComboString1 + “</LEDGERNAME>” + vbCrLf & _ “<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>” + vbCrLf & _ “<AMOUNT>” + Temp + “</AMOUNT>” + vbCrLf & _ “</ALLLEDGERENTRIES.LIST>” + vbCrLf & _
“<NARRATION>” + ComboString3 + “</NARRATION>” + vbCrLf & _ “</VOUCHER>” + vbCrLf & _
“</TALLYMESSAGE>” + vbCrLf & _ “</DATA>” + vbCrLf & _ “</BODY>” + vbCrLf & _ “</ENVELOPE>”
ServerHTTP.Open “POST”, “http://localhost:” + PortNumber ServerHTTP.send xmlstc
responsstr = ServerHTTP.responseText
newstring = InStrRev(responsstr, “<LINEERROR>”) If newstring = 0 Then
MsgBox “Save Successful”, vbOKOnly, “Voucher : “
Else
MsgBox responsstr MsgBox “Failed to POST”
End If
Text1.Text = “”
Text2.Text = “”
Text3.Text = “”
Text4.Text = “”
Text5.Text = “”
Text6.Text = “”
Text7.Text = “”
End If
End Sub
On executing the above code, the Tally Voucher containing the above selected Master ID gets altered with the given Amount and Narration details.
The above TallyPrime Screen displays the Voucher which has been altered from an external interface application.