Sunday 24 September 2017

Geo Locations API: Javascript

Below is the basic code to demonstrate plotting location on google maps:

<style>
#map {
height: 500px;
width: 100%;
}
</style>

<!--API Reference start-->
<!--Note that this is Geolocation API Reference without key-->
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<!--API Reference end-->

<!--Interface start-->
<button onclick="getLocation()">Get My Location on Google Maps</button>
<div id="map">This is where the map will be displayed.</div>
<!--Interface end-->

<script>
var lat, lng;
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, fail, options);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
lat = position.coords.latitude;
lng = position.coords.longitude;
var mylocation = {lat: lat, lng: lng};
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 12,
center: mylocation
});
var marker = new google.maps.Marker({
position: mylocation,
map: map
});
}
function fail(error) {
var errorType = {
0:"Unknown Error",
1:"Permission denied by the user",
2:"Position of the user not available",
3:"Request timed out"
};
var errMsg = errorType[error.code];
if(error.code == 0 || error.code == 2) {
errMsg = errMsg + " - " + error.message;
}
alert(errMsg);
}
var options = {
enableHighAccuracy: true,
timeout: Infinity,
maximumAge: 0
};

</script>

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