<?php
require('../config/dbcon.php');
    $query = "Select timeout from timeout_mst";
    $rs = mysqli_query($connect, $query) or die("Cannot execute query: $query\n");
    while ($row = mysqli_fetch_assoc($rs)) {
    	$timeout = $row['timeout'];
    }
    
    $query = "select screenwidth from width_mst";
    $rs = mysqli_query($connect, $query) or die("Cannot execute query: $query\n");
    while ($row = mysqli_fetch_assoc($rs)) {
    	$width = $row['screenwidth'];
    }
session_start();
if(isset($_SESSION["user"]))
{
 if((time() - $_SESSION['last_time']) > $timeout) // Time in Seconds
 {
 header("location:../login/logout.php");
 }
 else
 {
 $_SESSION['last_time'] = time();
 }
}
else
{
 header('Location:../login/index.php');
}
?>
<?php
    require('../config/dbcon.php');
    $query = "Select * from control_mst where description='PAYMENT'";
    $rs = mysqli_query($connect, $query) or die("Cannot execute query: $query\n");
    while ($row = mysqli_fetch_assoc($rs)) {
    	$srno = $row['srno'];
    }
?>
<html>

<head>
    <title>SSR-Payment</title>
    <link rel = "icon" href = "https:../image/ims.png" type = "image/x-icon">
</head>
<link rel = "icon" href = "https:../image/ims.png" type = "image/x-icon">
<script src='../js/jquery-3.1.1.min.js' type='text/javascript'></script>
<script src='../js/jquery-ui.min.js' type='text/javascript'></script>
<link href="../css/style.css" rel="stylesheet" />
<link href="../css/style1.css" rel="stylesheet" />
<link href='../css/jquery-ui.min.css' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="../css/all.css">
<link href="../css/bootstrap.min.css" rel="stylesheet" />
<link href="../css/font-awesome.min.css" rel="stylesheet" />
<link href="../css/styleg.css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.placeholder.label.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.5/datepicker.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.5/datepicker.css" />
<script src="../js/jquery.maskedinput.js" type="text/javascript"></script>
<style>
    label {
        font-size: 15px;
        top: 11px;
        margin-bottom: .5rem;
        margin-left: 5px;
        font-weight:bold;
        display: inline-transparent;
    }
</style>
<body style="min-width: <?php echo $width; ?>; width: auto;">
<div style="min-width: <?php echo $width; ?>; width: auto;">
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary" style="min-width: <?php echo $width; ?>; width: auto; height: 62px; background-color: #007bff; font-size:24px;">
        <input style = "background-color: #007bff; font-size:24px; width:100px; height : 55px; margin-top : px;" type="button" onclick="location.href='../main/index';" value="Home">
        <input style = "background-color: #007bff; font-size:24px; width:100px; height : 55px; margin-top : px;" type="button" onclick="location.href='../payments/payprt';" value="Print">
        <input style = "background-color: #007bff; font-size:24px; width:120px; height : 55px; margin-top : px;" type="button" onclick="location.href='../paymentreprint/index';" value="Re-Print">
        <input style = "background-color: #007bff; font-size:24px; height : 55px; margin-top : px;" type="button" onclick="exportToExcel('tblexportData', 'Export-data')" value="Export to Excel">
        <h1 style="color:white; font-size:24px; margin-top: -40px;" class="text-primary" align="center">Payment</h1>
        <h1 style="color:white; font-size:24px; margin-top : -40px;margin-right :20px;" class="text-primary" id="demo2" align="right"></h1>
    </nav>
	<div class="container" style = "min-width: <?php echo $width; ?>; width: auto;">
	<center>
			<tr>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">payment_number</label>
					<input type="text" id="id" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="<?php echo $srno; ?>"  oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">payment_date</label>
					<input type="text" id="payment_date" class="roundedCategory" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="<?php date_default_timezone_set('Asia/Kolkata'); echo date( 'd-m-Y'); ?>" autocomplete="off" required autofocus>
				</div>
				<div class="col-xs-3">
					<label style="font-size:18px;" class="col-sm-2 control-label">supp_name</label>
					<input type="text" id="supp_name" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-3">
					<label style="font-size:18px;" class="col-sm-2 control-label">supp_place</label>
					<input type="text" id="supp_place" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">srno</label>
					<input type="text" id="srno" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onfocus="this.select();" autocomplete="off" required>
				</div>
			</tr>
		</center>
		<center>
			<tr>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">bill_number</label>
					<input type="text" id="bill_number" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onfocus="this.select();" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">bill_date</label>
					<input type="text" id="bill_date" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">placefrom</label>
					<input type="text" id="placefrom" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">destination</label>
					<input type="text" id="destination" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">inv_number</label>
					<input type="text" id="inv_number" class="roundedCategory" readonly maxlength="15" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">lrno</label>
					<input type="text" id="lrno" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
			</tr>
		</center>
		<center>
			<tr>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">lchno</label>
					<input type="text" id="lchno" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">weight</label>
					<input type="text" id="weight" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">extra</label>
					<input type="text" id="extra" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">balance</label>
					<input type="text" id="balance" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">total_paid</label>
					<input type="text" id="total_paid" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">payment_amount</label>
					<input type="text" id="payment_amount" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">payment_neftref</label>
					<input type="text" id="payment_neftref" class="roundedCategory" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
			</tr>
		</center>
		<center>
			<tr>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">payment_neftdate</label>
					<input type="text" id="payment_neftdate" class="roundedCategory" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">payment_status</label>
					<input type="text" id="payment_status" readonly class="roundedCategory" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" value='CLEARED' oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">rupeesinwords</label>
					<input type="text" id="rupeesinwords" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">loading_date</label>
					<input type="text" id="loading_date" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">truck_number</label>
					<input type="text" id="truck_number" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
					<input type="hidden" id="truck_owner_name" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
					<input type="hidden" id="truck_pan_number" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<button type="button" name="action" id="action" style="width : 290px; height: 35px; margin-top: 30px;  margin-left: 0px;" class="btn btn-primary">Add</button>
				</div>
			</tr>
		</center>
		
	<div style="margin-top : 5px;min-width: <?php echo $width; ?>; width: auto;" align="center">
		<input type="hidden" style="font-size:18px; font-weight:bold;  color: #000066;" name="user_id" id="user_id" />
		<!--button type="button" name="action" id="action" style="width : 300px; height: 35px; margin-top: 32px;  margin-left: -290px;" class="btn btn-primary">Add</button-->
	</div>
	</div>
	<div class="container" style = "min-width: <?php echo $width; ?>; width: auto;">
	    <center>
			<tr>
			    <input style ="margin-left : 0px; width : 100%; height:40px; font-size:20px; font-weight:bold;" name="search_text" id="search_text" type="text" placeholder="search" alt="search">
			<tr>
		</center>
	</div>
	<div style="margin-top : 0px; margin-left : 0px;min-width: <?php echo $width; ?>; width: auto; height:40%; margin-left: 0px; margin-top: 0px; overflow:auto;" id="result" class="table-responsive"  align="center"></div>
	<div style="height: 60px; margin-left:0px; margin-top:0px; font-size:30px;" class="success"></div>
	<div style="height: 60px; margin-left:0px; margin-top:0px; font-size:30px;" class="error"></div>
	</div>
</body>

</html>
<?php
	$date = new DateTime();
	$current_timestamp = $date->getTimestamp();
?>
<script>
jQuery(function($){
    $("#nic").mask("99999-9999999-9");
    $("#payment_date").mask("99-99-9999");
    $("#bill_date").mask("99-99-9999");
    $("#phone").mask("(999) 999-9999");
    $("#ext").mask("(999) 999-9999? Ext.99999");
    $("#mobile").mask("+99 999 999 999");
    $("#percent").mask("99%");
    $("#productkey").mask("a*-999-a999");
    $("#orderno").mask("PO: aaa-999-***");
    $("#date2").mask("99/99/9999", { autoclear: false });
    $("#date3").mask("99/99/9999", { autoclear: false, completed:function(){alert("Completed!");} });
    $("#mobile2").mask("+1 999 999 999");
});
</script>
<script>
    $(document).on('keyup', function(e) {
        if (e.key == "Escape"){
          window.location.href = "../main/index"
        }
    });
</script>
<script>
	$(document).keydown(function(objEvent) {
		if (objEvent.keyCode == 9) {
			objEvent.preventDefault();
		}
	})
	flag_time = true;
	timer = '';
	setInterval(function(){phpJavascriptClock();},1000);
	
	function phpJavascriptClock()
	{
		if ( flag_time ) {
		timer = <?php echo $current_timestamp;?>*1000;
		}
		var d = new Date(timer);
		months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
		
		month_array = new Array('January', 'Febuary', 'March', 'April', 'May', 'June', 'July', 'Augest', 'September', 'October', 'November', 'December');
		
		day_array = new Array( 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
		
		currentYear = d.getFullYear();
		month = d.getMonth();
		var currentMonth = months[month];
		var currentMonth1 = month_array[month];
		var currentDate = d.getDate();
		currentDate = currentDate < 10 ? '0'+currentDate : currentDate;
		
		var day = d.getDay();
		current_day = day_array[day];
		var hours = d.getHours();
		var minutes = d.getMinutes();
		var seconds = d.getSeconds();
		
		var ampm = hours >= 12 ? 'PM' : 'AM';
		hours = hours % 12;
		hours = hours ? hours : 12; // the hour ’0′ should be ’12′
		minutes = minutes < 10 ? '0'+minutes : minutes;
		seconds = seconds < 10 ? '0'+seconds : seconds;
		var strTime = hours + ':' + minutes+ ':' + seconds + ' ' + ampm;
		timer = timer + 1000;
		document.getElementById("demo2").innerHTML='Date : ' + currentDate+'-' +(month+1)+'-' +currentYear + ' Time : ' + strTime ;
		flag_time = false;
	}

</script>
<script>
    function GetPartyCode(x) {
       $.ajax({
          url: 'getpartycode',
          data: "",
          dataType: 'json',
          success: function(data){
    		$('#id').val(data.srno);		
          } 
        });
    }
	$(document).ready(function() {
		load_data();
        GetPartyCode();
		function load_data(query) {
			$.ajax({
				url: "search.php",
				method: "post",
				data: {
					query: query
				},
				success: function(data) {
					$('#result').html(data);
					$('#user_id').val('');
					//$('#payment_number').val('');
					//$('#payment_date').val('');
					$('#supp_name').val('');
					$('#supp_place').val('');
					$('#srno').val('');
					$('#bill_number').val('');
					$('#bill_date').val('');
					$('#placefrom').val('');
					$('#destination').val('');
					$('#inv_number').val('');
					$('#lrno').val('');
					$('#lchno').val('');
					$('#weight').val('');
					$('#extra').val('');
					$('#balance').val('');
					$('#total_paid').val('');
					$('#payment_amount').val('');
					$('#payment_neftref').val('');
					$('#payment_neftdate').val('');
					$('#payment_status').val('CLEARED');
					$('#rupeesinwords').val('');
					$('#loading_date').val('');
					$('#truck_number').val('');
					$('#truck_owner_name').val('');
					$('#truck_pan_number').val('');
					$('#action').text("Add");
				}
			});
		}
		function load_data1(query){
			$.ajax({
				url:"search.php",
				method:"post",
				data:{query:query},
				success:function(data)
				{
					$('#result').html(data);				
				}
			});
		}
		$('#search_text').keyup(function() {
			var search = $(this).val();
			if (search !== '') {
				load_data1(search);
			} else {
				load_data();
				GetPartyCode();
			}
		});
		$('#action').click(function() {
			var id = $('#id').val();
			var payment_number = $('#id').val();
			var payment_date = $('#payment_date').val();
			var supp_name = $('#supp_name').val();
			var supp_place = $('#supp_place').val();
			var srno = $('#srno').val();
			var bill_number = $('#bill_number').val();
			var bill_date = $('#bill_date').val();
			var placefrom = $('#placefrom').val();
			var destination = $('#destination').val();
			var inv_number = $('#inv_number').val();
			var lrno = $('#lrno').val();
			var lchno = $('#lchno').val();
			var weight = $('#weight').val();
			var extra = $('#extra').val();
			var balance = $('#balance').val();
			var total_paid = $('#total_paid').val();
			var payment_amount = $('#payment_amount').val();
			var payment_neftref = $('#payment_neftref').val();
			var payment_neftdate = $('#payment_neftdate').val();
			var payment_status = $('#payment_status').val();
			var rupeesinwords = $('#rupeesinwords').val();
			var loading_date = $('#loading_date').val();
			var truck_number = $('#truck_number').val();
			var truck_owner_name = $('#truck_owner_name').val();
			var truck_pan_number = $('#truck_pan_number').val();
			var action = $('#action').text();
			//$actiontext = $('#action').text();
			if (id != '' && payment_date != '' && supp_name != '' && supp_place != '' && srno != '' && bill_number != '' && bill_date != '' && placefrom != '' && destination != '' && inv_number != '' && lrno != '' && lchno != '' && weight != '' && extra != '' && balance != '' && total_paid != '' && payment_amount != '' && payment_neftref != '' && payment_neftdate != '' && payment_status != '' && rupeesinwords != '' && truck_number != '') {
				$.ajax({
					url: "action.php",
					method: "POST",
					data: {
						payment_number : payment_number,
						payment_date : payment_date,
						supp_name : supp_name,
						supp_place : supp_place,
						srno : srno,
						bill_number : bill_number,
						bill_date : bill_date,
						placefrom : placefrom,
						destination : destination,
						inv_number : inv_number,
						lrno : lrno,
						lchno : lchno,
						weight : weight,
						extra : extra,
						balance : balance,
						total_paid : total_paid,
						payment_amount : payment_amount,
						payment_neftref : payment_neftref,
						payment_neftdate : payment_neftdate,
						payment_status : payment_status,
						rupeesinwords : rupeesinwords,
						loading_date : loading_date,
						truck_number : truck_number,
						truck_owner_name : truck_owner_name,
						truck_pan_number : truck_pan_number,
						id: id,
						action: action
					},
					success: function(data) {
						$('.success').show(1000).html("Record Saved Successfully.").delay(1000).fadeOut(1000);
						load_data();
						GetPartyCode();
					}
				});
			} else {
				$('.success').show(1000).html("All Fields are Required").delay(1000).fadeOut(1000);
			}
		});

		$(document).on('click', '.update', function() {
			var id = $(this).attr("id");
			$.ajax({
				url: "fetch.php",
				method: "POST",
				data: {
					id: id
				},
				dataType: "json",
				success: function(data) {
					//$('#action').text("Update");
					$('#srno').val(data.srno);
					$('#supp_name').val(data.supp_name);
					$('#supp_place').val(data.supp_place);
					$('#bill_number').val(data.bill_number);
					$('#bill_date').val(data.bill_date);
					$('#placefrom').val(data.placefrom);
					$('#destination').val(data.destination);
					$('#inv_number').val(data.inv_number);
					$('#lrno').val(data.lrno);
					$('#lchno').val(data.lchno);
					$('#weight').val(data.weight);
					$('#extra').val(data.extra);
					$('#balance').val(data.balance);
					$('#total_paid').val(data.total_paid);
					$('#payment_amount').val(data.payment_amount);
					convertNumberToWords();
					$('#loading_date').val(data.loading_date);
					$('#truck_number').val(data.truck_number);
					$('#truck_owner_name').val(data.truck_owner_name);
					$('#truck_pan_number').val(data.truck_pan_number);
					//$('#rupeesinwords').val(data.rupeesinwords);
					$('#payment_date').text("<?php date_default_timezone_set('Asia/Kolkata'); echo date( 'd-m-Y'); ?>");
					$('#payment_date').focus();
				}
			})
		});
		$(document).on('click', '.delete', function() {
			var id = $(this).attr("id");
			if (confirm("Are you sure you want to remove this data?")) {
				var action = "Delete";
				$.ajax({
					url: "action.php",
					method: "POST",
					data: {
						id: id,
						action: action
					},
					success: function(data) {
						$('.success').show(1000).html("Record Deleted Successfully.").delay(1000).fadeOut(1000);
						load_data();
					}
				})
			} else {
				return false;
			}
		});
		$(document).ready(function() {
			$('input').on('keypress', function(e) {
				if (e.which == 13) {
					switch ($(this).attr('id')) {
						case 'payment_date':
							if (!document.getElementById("payment_date").value.length == 0) {
								$('#payment_neftref').focus();
								e.preventDefault();
								break;
							}
						case 'payment_neftref':
							if (!document.getElementById("payment_neftref").value.length == 0) {
								$('#payment_neftdate').focus();
								e.preventDefault();
								break;
							}
						case 'payment_neftdate':
							if (!document.getElementById("payment_neftdate").value.length == 0) {
								$('#action').focus();
								e.preventDefault();
								break;
							}
					}
				}
			});
		});
	});
</script>
<script>
function convertNumberToWords() {
	var amount = document.getElementById("payment_amount").value
    var words = new Array();
    words[0] = '';
    words[1] = 'One';
    words[2] = 'Two';
    words[3] = 'Three';
    words[4] = 'Four';
    words[5] = 'Five';
    words[6] = 'Six';
    words[7] = 'Seven';
    words[8] = 'Eight';
    words[9] = 'Nine';
    words[10] = 'Ten';
    words[11] = 'Eleven';
    words[12] = 'Twelve';
    words[13] = 'Thirteen';
    words[14] = 'Fourteen';
    words[15] = 'Fifteen';
    words[16] = 'Sixteen';
    words[17] = 'Seventeen';
    words[18] = 'Eighteen';
    words[19] = 'Nineteen';
    words[20] = 'Twenty';
    words[30] = 'Thirty';
    words[40] = 'Forty';
    words[50] = 'Fifty';
    words[60] = 'Sixty';
    words[70] = 'Seventy';
    words[80] = 'Eighty';
    words[90] = 'Ninety';
    amount = amount.toString();
    var atemp = amount.split(".");
    var number = atemp[0].split(",").join("");
    var n_length = number.length;
    var words_string = "";
    if (n_length <= 9) {
        var n_array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
        var received_n_array = new Array();
        for (var i = 0; i < n_length; i++) {
            received_n_array[i] = number.substr(i, 1);
        }
        for (var i = 9 - n_length, j = 0; i < 9; i++, j++) {
            n_array[i] = received_n_array[j];
        }
        for (var i = 0, j = 1; i < 9; i++, j++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                if (n_array[i] == 1) {
                    n_array[j] = 10 + parseInt(n_array[j]);
                    n_array[i] = 0;
                }
            }
        }
        value = "";
        for (var i = 0; i < 9; i++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                value = n_array[i] * 10;
            } else {
                value = n_array[i];
            }
            if (value != 0) {
                words_string += words[value] + " ";
            }
            if ((i == 1 && value != 0) || (i == 0 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Crores ";
            }
            if ((i == 3 && value != 0) || (i == 2 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Lakhs ";
            }
            if ((i == 5 && value != 0) || (i == 4 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Thousand ";
            }
            if (i == 6 && value != 0 && (n_array[i + 1] != 0 && n_array[i + 2] != 0)) {
                words_string += "Hundred and ";
            } else if (i == 6 && value != 0) {
                words_string += "Hundred ";
            }
        }
        words_string = words_string.split("  ").join(" ");
		document.getElementById('rupeesinwords').value = words_string;
    }
    return words_string;
	document.getElementById('rupeesinwords').value = words_string;
}
</Script>
<script type="text/javascript">
	function exportToExcel(tableID, filename = '') {
		var downloadurl;
		var dataFileType = 'application/vnd.ms-excel';
		var tableSelect = document.getElementById(tableID);
		var tableHTMLData = tableSelect.outerHTML.replace(/ /g, '%20');
		filename = filename ? filename + '.xls' : 'export_excel_data.xls';
		downloadurl = document.createElement("a");
		document.body.appendChild(downloadurl);
		if (navigator.msSaveOrOpenBlob) {
			var blob = new Blob(['\ufeff', tableHTMLData], {
				type: dataFileType
			});
			navigator.msSaveOrOpenBlob(blob, filename);
		} else {
			downloadurl.href = 'data:' + dataFileType + ', ' + tableHTMLData;
			downloadurl.download = filename;
			downloadurl.click();
		}
	}
</script>