<?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='SRNO'";
    $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-Loading Register</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 src="../js/jquery.min.js"></script-->
<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='../loadingregister/invprt';" value="Print">
        <input style = "background-color: #007bff; font-size:24px; width:120px; height : 55px; margin-top : px;" type="button" onclick="location.href='../reprint/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">Loading Register</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; margin-top : -25px;">
	<center>
			<tr>
				<div class="col-xs-1">
					<label style="font-size:18px;" class="col-sm-2 control-label">Loading_code</label>
					<input type="text" id="id" class="roundedCategory" tabindex="1" 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">Date_One</label>
					<input type="text" id="date_one" class="roundedCategory1" tabindex="2" 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'); ?>" 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">Party_Name(Search)</label>
					<input type="text" id="party_name" class="roundedCategory" tabindex="3" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onclick="this.select();" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required autofocus>
				</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" tabindex="4" 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">lhcno_/_Package</label>
					<input type="text" id="lchno" class="roundedCategory" tabindex="5" 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">LR_Number</label>
					<input type="text" id="lrno" class="roundedCategory" tabindex="6" 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">Truck_Number(Search)</label>
					<input type="text" id="truck_number" class="roundedCategory" tabindex="7" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onclick="this.select();" 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_PAN</label>
					<input type="text" id="truck_pan_number" class="roundedCategory" tabindex="8" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onclick="this.select();" 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">From</label>
					<input type="text" id="placefrom" readonly class="roundedCategory" tabindex="9" 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">Destination</label>
					<input type="text" id="destination" class="roundedCategory" tabindex="10" 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">Supp_Name(Search)</label>
					<input type="text" id="supp_name" class="roundedCategory" tabindex="11" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onclick="this.select();" 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" tabindex="12" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onkeypress="return isNumberKey(this, event);" 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">Booking_Rate</label>
					<input type="text" id="booking_rate" class="roundedCategory" tabindex="13" style="font-size:18px; width:100%; height: 35px; font-weight:bold; background :  lightblue; color: #000066;" onkeypress="return isNumberKey(this, event);" onfocus="this.select();" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:18px;" class="col-sm-2 control-label">Lorry_Freight</label>
					<input type="text" id="lorry_freight" class="roundedCategory" tabindex="14" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onkeypress="return isNumberKey(this, event);" 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">Advance</label>
					<input type="text" id="advance" class="roundedCategory" tabindex="15" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onkeypress="return isNumberKey(this, event);" 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">Cash_Advance</label>
					<input type="text" id="cash_advance" class="roundedCategory" tabindex="16" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onkeypress="return isNumberKey(this, event);" 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">Diesel</label>
					<input type="text" id="diesel" class="roundedCategory" tabindex="17" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onkeypress="return isNumberKey(this, event);" 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">Neft_Amount</label>
					<input type="text" id="neft_amount" class="roundedCategory" tabindex="18" readonly maxlength="15" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onkeypress="return isNumberKey(this, event);" 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">Neft_Date</label>
					<input type="text" id="neft_date" class="roundedCategory1" tabindex="19" 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">Others</label>
					<input type="text" id="others" class="roundedCategory" tabindex="20" style="font-size:18px; width:100%; height: 35px; font-weight:bold; background : lightblue; color: #000066;" onkeypress="return isNumberKey(this, event);" 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_Charges</label>
					<input type="text" id="extra" class="roundedCategory" tabindex="21" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onkeypress="return isNumberKey(this, event);" 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" tabindex="22" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onkeypress="return isNumberKey(this, event);" 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" tabindex="23" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onkeypress="return isNumberKey(this, event);" 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">Bal_Paid_Date</label>
					<input type="text" id="bal_paid_date" class="roundedCategory1" tabindex="24" 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">Delivery_Date</label>
					<input type="text" id="delivery_date" class="roundedCategory1" tabindex="25" 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">Acc_Rec_Date</label>
					<input type="text" id="acc_rec_date" class="roundedCategory1" tabindex="26" 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">Driver_Name</label>
					<input type="text" id="driver_name" class="roundedCategory" tabindex="27" 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">Driver_Mob_No</label>
					<input type="text" id="driver_mob_no" class="roundedCategory" tabindex="28" 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">Mamul_Charge</label>
					<input type="text" id="mamul_charges" class="roundedCategory" tabindex="29" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onkeypress="return isNumberKey(this, event);" 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">Profit</label>
					<input type="text" id="profit" readonly class="roundedCategory" tabindex="30" style="font-size:18px; width:100%; height: 35px; font-weight:bold; background :  yellow ; color: #000066;" onkeypress="return isNumberKey(this, event);" 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">Remarks</label>
					<input type="text" id="remarks" class="roundedCategory" tabindex="31" 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">Status(Search)</label>
					<input type="text" id="status_one" class="roundedCategory" tabindex="32" style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;" onclick="this.select();" value="PENDING" 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">Bill_Date</label>
					<input type="text" id="bill_date" class="roundedCategory1" tabindex="33" 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-4">
					<label style="font-size:18px;" class="col-sm-2 control-label">Rupeen_In_Words</label>
					<input type="text" id="rupeesinwords" class="roundedCategory1" tabindex="34" 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>
		<button type="button" name="action" id="action" style="width : 280px; height: 38px; margin-top : 30px; margin-left : 20px;" class="btn btn-primary">Add</button>
	    <div style="margin-top : 20px;min-width: <?php echo $width; ?>; width: auto;" align="center">
	</div>
	</div>
	<div class="container" style = "min-width: <?php echo $width; ?>; width: auto; margin-top : -30px;">
	    <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 : -30px; margin-left : 0px;min-width: <?php echo $width; ?>; width: auto; height:30%; 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>
	<input type="hidden" id="party_address_one" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="party_address_two" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="party_place" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="party_contact_person" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="party_phone_number" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="party_mobile_number" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="party_gst_number" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="party_pan_number" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="party_aadhar_number" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="party_payment_terms" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="party_goods" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="party_remarks" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="truck_owner_name" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="truck_address_one" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="truck_address_two" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="truck_place" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="truck_mobile_number" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="truck_bank_name" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="truck_bank_acc_number" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="truck_bank_branch" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="truck_ifsc_code" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="truck_aadhar_no" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="truck_remarks" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="supp_address_one" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="supp_address_two" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="supp_place" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="supp_contact_person" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="supp_mobile_number" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="supp_pan_number" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="supp_bank_name" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="supp_bank_acc_number" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="supp_bank_branch" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="supp_ifsc_code" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="supp_supp_aadhar_no" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="supp_remarks" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="unloading_charges" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
	<input type="hidden" id="totalval" class="roundedCategory" readonly style="font-size:18px; width:100%; height: 35px; font-weight:bold; color: #000066;">
</body>
</html>
<?php
	$date = new DateTime();
	$current_timestamp = $date->getTimestamp();
?>
<script>
jQuery(function($){
    $("#nic").mask("99999-9999999-9");
    $("#date_one").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 type="text/javascript">
    function isNumberKey(txt, evt) {
        var charCode = (evt.which) ? evt.which : evt.keyCode;
        if (charCode == 46) {
            if (txt.value.indexOf('.') === -1) {
              return true;
            } else {
              return false;
            }
        } else {
        if (charCode > 31 &&
            (charCode < 48 || charCode > 57))
            return false;
        }
        return true;
    }
</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);
					$('#date_one').val("<?php date_default_timezone_set('Asia/Kolkata'); echo date( 'd-m-Y'); ?>");
					$('#party_name').val('');
					$('#party_address_one').val('');
					$('#party_address_two').val('');
					$('#party_place').val('');
					$('#party_contact_person').val('');
					$('#party_phone_number').val('');
					$('#party_mobile_number').val('');
					$('#party_gst_number').val('');
					$('#party_pan_number').val('');
					$('#party_aadhar_number').val('');
					$('#party_payment_terms').val('');
					$('#party_goods').val('');
					$('#party_remarks').val('');
					$('#inv_number').val('');
					$('#lchno').val('');
					$('#lrno').val('');
					$('#truck_number').val('');
					$('#truck_owner_name').val('');
					$('#truck_address_one').val('');
					$('#truck_address_two').val('');
					$('#truck_place').val('');
					$('#truck_mobile_number').val('');
					$('#truck_pan_number').val('');
					$('#truck_bank_name').val('');
					$('#truck_bank_acc_number').val('');
					$('#truck_bank_branch').val('');
					$('#truck_ifsc_code').val('');
					$('#truck_aadhar_no').val('');
					$('#truck_remarks').val('');
					$('#placefrom').val('');
					$('#destination').val('');
					$('#supp_name').val('');
					$('#supp_address_one').val('');
					$('#supp_address_two').val('');
					$('#supp_place').val('');
					$('#supp_contact_person').val('');
					$('#supp_mobile_number').val('');
					$('#supp_pan_number').val('');
					$('#supp_bank_name').val('');
					$('#supp_bank_acc_number').val('');
					$('#supp_bank_branch').val('');
					$('#supp_ifsc_code').val('');
					$('#supp_supp_aadhar_no').val('');
					$('#supp_remarks').val('');
					$('#weight').val('');
					$('#booking_rate').val('');
					$('#lorry_freight').val('');
					$('#advance').val('');
					$('#cash_advance').val('');
					$('#diesel').val('');
					$('#neft_amount').val('');
					$('#neft_date').val('');
					$('#unloading_charges').val('0.00');
					$('#others').val('');
					$('#extra').val('');
					$('#balance').val('');
					$('#total_paid').val('');
					$('#bal_paid_date').val('');
					$('#delivery_date').val('');
					$('#acc_rec_date').val('');
					$('#driver_name').val('');
					$('#driver_mob_no').val('');
					$('#mamul_charges').val('');
					$('#profit').val('');
					$('#remarks').val('');
					$('#status_one').val('PENDING');
					$('#bill_date').val("<?php date_default_timezone_set('Asia/Kolkata'); echo date( 'd-m-Y'); ?>");
					$('#rupeesinwords').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();
			}
		});
		$(function() {
			$("#party_name").autocomplete({
				source: function(request, response) {
					$.ajax({
						url: "fetchparty.php",
						type: 'post',
						dataType: "json",
						data: {
							search: request.term
						},
						success: function(data) {
							response(data);
						}
					});
				},
				select: function(event, ui) {
					$('#party_name').val(ui.item.label);
					$('#placefrom').val(ui.item.party_address_two);
					$('#party_address_one').val(ui.item.party_address_one);
					$('#party_address_two').val(ui.item.party_address_two);
					$('#party_place').val(ui.item.party_place);
					$('#party_contact_person').val(ui.item.party_contact_person);
					$('#party_phone_number').val(ui.item.party_phone_number);
					$('#party_mobile_number').val(ui.item.party_mobile_number);
					$('#party_gst_number').val(ui.item.party_gst_number);
					$('#party_pan_number').val(ui.item.party_pan_number);
					$('#party_aadhar_number').val(ui.item.party_aadhar_number);
					$('#party_payment_terms').val(ui.item.party_payment_terms);
					$('#party_goods').val(ui.item.party_goods);
					$('#party_remarks').val(ui.item.party_remarks);
					document.getElementById("party_name").focus();
					return false;
				}
			});
		});
		$(function() {
			$("#supp_name").autocomplete({
				source: function(request, response) {
					$.ajax({
						url: "fetchsupplier.php",
						type: 'post',
						dataType: "json",
						data: {
							search: request.term
						},
						success: function(data) {
							response(data);
						}
					});
				},
				select: function(event, ui) {
					$('#supp_name').val(ui.item.label);
					$('#supp_address_one').val(ui.item.supp_address_one);
					$('#supp_address_two').val(ui.item.supp_address_two);
					$('#supp_place').val(ui.item.supp_place);
					$('#supp_contact_person').val(ui.item.supp_contact_person);
					$('#supp_mobile_number').val(ui.item.supp_mobile_number);
					$('#supp_pan_number').val(ui.item.supp_pan_number);
					$('#supp_bank_name').val(ui.item.supp_bank_name);
					$('#supp_bank_acc_number').val(ui.item.supp_bank_acc_number);
					$('#supp_bank_branch').val(ui.item.supp_bank_branch);
					$('#supp_ifsc_code').val(ui.item.supp_ifsc_code);
					$('#supp_supp_aadhar_no').val(ui.item.supp_supp_aadhar_no);
					$('#supp_remarks').val(ui.item.supp_remarks);
					document.getElementById("supp_name").focus();
					return false;
				}
			});
		});
		$(function() {
			$("#truck_number").autocomplete({
				source: function(request, response) {
					$.ajax({
						url: "fetchtruck.php",
						type: 'post',
						dataType: "json",
						data: {
							search: request.term
						},
						success: function(data) {
							response(data);
						}
					});
				},
				select: function(event, ui) {
					$('#truck_number').val(ui.item.label);
					$('#truck_owner_name').val(ui.item.truck_owner_name);
					$('#truck_address_one').val(ui.item.truck_address_one);
					$('#truck_address_two').val(ui.item.truck_address_two);
					$('#truck_place').val(ui.item.truck_place);
					$('#truck_mobile_number').val(ui.item.truck_mobile_number);
					$('#truck_pan_number').val(ui.item.truck_pan_number);
					$('#truck_bank_name').val(ui.item.truck_bank_name);
					$('#truck_bank_acc_number').val(ui.item.truck_bank_acc_number);
					$('#truck_bank_branch').val(ui.item.truck_bank_branch);
					$('#truck_ifsc_code').val(ui.item.truck_ifsc_code);
					$('#truck_aadhar_no').val(ui.item.truck_aadhar_no);
					$('#truck_remarks').val(ui.item.truck_remarks);
					document.getElementById("truck_number").focus();
					return false;
				}
			});
		});
		$(function() {
			$("#status_one").autocomplete({
				source: function(request, response) {
					$.ajax({
						url: "fetchstatus.php",
						type: 'post',
						dataType: "json",
						data: {
							search: request.term
						},
						success: function(data) {
							response(data);
						}
					});
				},
				select: function(event, ui) {
				    $('#status_one').val(ui.item.description);
					document.getElementById("status_one").focus();
					return false;
				}
			});
		});
		$('#action').click(function() {
			var id = $('#id').val();
			var date_one = $('#date_one').val();
			var party_name = $('#party_name').val();
			var party_address_one = $('#party_address_one').val();
			var party_address_two = $('#party_address_two').val();
			var party_place = $('#party_place').val();
			var party_contact_person = $('#party_contact_person').val();
			var party_phone_number = $('#party_phone_number').val();
			var party_mobile_number = $('#party_mobile_number').val();
			var party_gst_number = $('#party_gst_number').val();
			var party_pan_number = $('#party_pan_number').val();
			var party_aadhar_number = $('#party_aadhar_number').val();
			var party_payment_terms = $('#party_payment_terms').val();
			var party_goods = $('#party_goods').val();
			var party_remarks = $('#party_remarks').val();
			var inv_number = $('#inv_number').val();
			var lchno = $('#lchno').val();
			var lrno = $('#lrno').val();
			var truck_number = $('#truck_number').val();
			var truck_owner_name = $('#truck_owner_name').val();
			var truck_address_one = $('#truck_address_one').val();
			var truck_address_two = $('#truck_address_two').val();
			var truck_place = $('#truck_place').val();
			var truck_mobile_number = $('#truck_mobile_number').val();
			var truck_pan_number = $('#truck_pan_number').val();
			var truck_bank_name = $('#truck_bank_name').val();
			var truck_bank_acc_number = $('#truck_bank_acc_number').val();
			var truck_bank_branch = $('#truck_bank_branch').val();
			var truck_ifsc_code = $('#truck_ifsc_code').val();
			var truck_aadhar_no = $('#truck_aadhar_no').val();
			var truck_remarks = $('#truck_remarks').val();
			var destination = $('#destination').val();
			var supp_name = $('#supp_name').val();
			var supp_address_one = $('#supp_address_one').val();
			var supp_address_two = $('#supp_address_two').val();
			var supp_place = $('#supp_place').val();
			var supp_contact_person = $('#supp_contact_person').val();
			var supp_mobile_number = $('#supp_mobile_number').val();
			var supp_pan_number = $('#supp_pan_number').val();
			var supp_bank_name = $('#supp_bank_name').val();
			var supp_bank_acc_number = $('#supp_bank_acc_number').val();
			var supp_bank_branch = $('#supp_bank_branch').val();
			var supp_ifsc_code = $('#supp_ifsc_code').val();
			var supp_supp_aadhar_no = $('#supp_supp_aadhar_no').val();
			var supp_remarks = $('#supp_remarks').val();
			var weight = $('#weight').val();
			var booking_rate = $('#booking_rate').val();
			var lorry_freight = $('#lorry_freight').val();
			var advance = $('#advance').val();
			var cash_advance = $('#cash_advance').val();
			var diesel = $('#diesel').val();
			var neft_amount = $('#neft_amount').val();
			var neft_date = $('#neft_date').val();
			var unloading_charges = $('#unloading_charges').val();
			var others = $('#others').val();
			var extra = $('#extra').val();
			var balance = $('#balance').val();
			var total_paid = $('#total_paid').val();
			var bal_paid_date = $('#bal_paid_date').val();
			var delivery_date = $('#delivery_date').val();
			var acc_rec_date = $('#acc_rec_date').val();
			var profit = $('#profit').val();
			var driver_name = $('#driver_name').val();
			var driver_mob_no = $('#driver_mob_no').val();
			var remarks = $('#remarks').val();
			var status_one = $('#status_one').val();
			var bill_date = $('#bill_date').val();
			var placefrom = $('#placefrom').val();
			var rupeesinwords = $('#rupeesinwords').val();
			var mamul_charges = $('#mamul_charges').val();
			var action = $('#action').text();
			if (date_one != '' && party_name != '' && inv_number != '' && lchno != '' && lrno != '' && truck_number != '' && truck_pan_number != '' && placefrom != '' && destination != '' && supp_name != '' && weight != '' && booking_rate != '' && lorry_freight != '' && advance != '' && cash_advance != '' && diesel != '' && neft_amount != '' && neft_date != '' && others != '' && extra != '' && balance != '' && total_paid != '' && bal_paid_date != '' && delivery_date != '' && acc_rec_date != '' && driver_name != '' && driver_mob_no != '' && mamul_charges != '' && profit != '' && remarks != '' && status_one != '' && bill_date != '' && rupeesinwords != '') {
				$.ajax({
					url: "action.php",
					method: "POST",
					data: {
					    id: id,
						date_one : date_one,
						party_name : party_name,
						party_address_one : party_address_one,
						party_address_two : party_address_two,
						party_place : party_place,
						party_contact_person : party_contact_person,
						party_phone_number : party_phone_number,
						party_mobile_number : party_mobile_number,
						party_gst_number : party_gst_number,
						party_pan_number : party_pan_number,
						party_aadhar_number : party_aadhar_number,
						party_payment_terms : party_payment_terms,
						party_goods : party_goods,
						party_remarks : party_remarks,
						inv_number : inv_number,
						lchno : lchno,
						lrno : lrno,
						truck_number : truck_number,
						truck_owner_name : truck_owner_name,
						truck_address_one : truck_address_one,
						truck_address_two : truck_address_two,
						truck_place : truck_place,
						truck_mobile_number : truck_mobile_number,
						truck_pan_number : truck_pan_number,
						truck_bank_name : truck_bank_name,
						truck_bank_acc_number : truck_bank_acc_number,
						truck_bank_branch : truck_bank_branch,
						truck_ifsc_code : truck_ifsc_code,
						truck_aadhar_no : truck_aadhar_no,
						truck_remarks : truck_remarks,
						placefrom : placefrom,
						destination : destination,
						supp_name : supp_name,
						supp_address_one : supp_address_one,
						supp_address_two : supp_address_two,
						supp_place : supp_place,
						supp_contact_person : supp_contact_person,
						supp_mobile_number : supp_mobile_number,
						supp_pan_number : supp_pan_number,
						supp_bank_name : supp_bank_name,
						supp_bank_acc_number : supp_bank_acc_number,
						supp_bank_branch : supp_bank_branch,
						supp_ifsc_code : supp_ifsc_code,
						supp_supp_aadhar_no : supp_supp_aadhar_no,
						supp_remarks : supp_remarks,
						weight : weight,
						booking_rate : booking_rate,
						lorry_freight : lorry_freight,
						advance : advance,
						cash_advance : cash_advance,
						diesel : diesel,
						neft_amount : neft_amount,
						neft_date : neft_date,
						unloading_charges : unloading_charges,
						others : others,
						extra : extra,
						balance : balance,
						total_paid : total_paid,
						bal_paid_date : bal_paid_date,
						delivery_date : delivery_date,
						acc_rec_date : acc_rec_date,
						driver_name : driver_name,
						driver_mob_no : driver_mob_no,
						mamul_charges : mamul_charges,
						profit : profit,
						remarks : remarks,
						status_one : status_one,
						bill_date : bill_date,
						rupeesinwords : rupeesinwords,
						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");
					$('#id').val(data.id);
					$('#date_one').val(data.date_one);
					$('#party_name').val(data.party_name);
					$('#party_address_one').val(data.party_address_one);
					$('#party_address_two').val(data.party_address_two);
					$('#party_place').val(data.party_place);
					$('#party_contact_person').val(data.party_contact_person);
					$('#party_phone_number').val(data.party_phone_number);
					$('#party_mobile_number').val(data.party_mobile_number);
					$('#party_gst_number').val(data.party_gst_number);
					$('#party_pan_number').val(data.party_pan_number);
					$('#party_aadhar_number').val(data.party_aadhar_number);
					$('#party_payment_terms').val(data.party_payment_terms);
					$('#party_goods').val(data.party_goods);
					$('#party_remarks').val(data.party_remarks);
					$('#inv_number').val(data.inv_number);
					$('#lchno').val(data.lchno);
					$('#lrno').val(data.lrno);
					$('#truck_number').val(data.truck_number);
					$('#truck_owner_name').val(data.truck_owner_name);
					$('#truck_address_one').val(data.truck_address_one);
					$('#truck_address_two').val(data.truck_address_two);
					$('#truck_place').val(data.truck_place);
					$('#truck_mobile_number').val(data.truck_mobile_number);
					$('#truck_pan_number').val(data.truck_pan_number);
					$('#truck_bank_name').val(data.truck_bank_name);
					$('#truck_bank_acc_number').val(data.truck_bank_acc_number);
					$('#truck_bank_branch').val(data.truck_bank_branch);
					$('#truck_ifsc_code').val(data.truck_ifsc_code);
					$('#truck_aadhar_no').val(data.truck_aadhar_no);
					$('#truck_remarks').val(data.truck_remarks);
					$('#placefrom').val(data.placefrom);
					$('#destination').val(data.destination);
					$('#supp_name').val(data.supp_name);
					$('#supp_address_one').val(data.supp_address_one);
					$('#supp_address_two').val(data.supp_address_two);
					$('#supp_place').val(data.supp_place);
					$('#supp_contact_person').val(data.supp_contact_person);
					$('#supp_mobile_number').val(data.supp_mobile_number);
					$('#supp_pan_number').val(data.supp_pan_number);
					$('#supp_bank_name').val(data.supp_bank_name);
					$('#supp_bank_acc_number').val(data.supp_bank_acc_number);
					$('#supp_bank_branch').val(data.supp_bank_branch);
					$('#supp_ifsc_code').val(data.supp_ifsc_code);
					$('#supp_supp_aadhar_no').val(data.supp_supp_aadhar_no);
					$('#supp_remarks').val(data.supp_remarks);
					$('#weight').val(data.weight);
					$('#booking_rate').val(data.booking_rate);
					$('#lorry_freight').val(data.lorry_freight);
					$('#advance').val(data.advance);
					$('#cash_advance').val(data.cash_advance);
					$('#diesel').val(data.diesel);
					$('#neft_amount').val(data.neft_amount);
					$('#neft_date').val(data.neft_date);
					$('#unloading_charges').val(data.unloading_charges);
					$('#others').val(data.others);
					$('#extra').val(data.extra);
					$('#balance').val(data.balance);
					$('#total_paid').val(data.total_paid);
					$('#bal_paid_date').val(data.bal_paid_date);
					$('#delivery_date').val(data.delivery_date);
					$('#acc_rec_date').val(data.acc_rec_date);
					$('#driver_name').val(data.driver_name);
					$('#driver_mob_no').val(data.driver_mob_no);
					$('#mamul_charges').val(data.mamul_charges);
					$('#profit').val(data.profit);
					$('#remarks').val(data.remarks);
					$('#status_one').val(data.status_one);
					$('#bill_date').val(data.bill_date);
					$('#rupeesinwords').val(data.rupeesinwords);
				}
			})
		});
		$(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 'date_one':
							if (!document.getElementById("date_one").value.length == 0) {
								$('#party_name').focus();
								e.preventDefault();
								break;
							}
						case 'party_name':
						    var element = document.getElementById('party_name');
                            if (element !== null && element.value !== '') {
								$('#inv_number').focus();
								e.preventDefault();
								break;
							}
						case 'inv_number':
							if (!document.getElementById("inv_number").value.length == 0) {
								$('#lchno').focus();
								e.preventDefault();
								break;
							}
						case 'lchno':
							if (!document.getElementById("lchno").value.length == 0) {
								$('#lrno').focus();
								e.preventDefault();
								break;
							}
						case 'lrno':
							if (!document.getElementById("lrno").value.length == 0) {
								$('#truck_number').focus();
								e.preventDefault();
								break;
							}
						case 'truck_number':
							if (!document.getElementById("truck_number").value.length == 0) {
								$('#destination').focus();
								e.preventDefault();
								break;
							}
						case 'destination':
							if (!document.getElementById("destination").value.length == 0) {
								$('#supp_name').focus();
								e.preventDefault();
								break;
							}
						case 'supp_name':
							if (!document.getElementById("supp_name").value.length == 0) {
								$('#weight').focus();
								e.preventDefault();
								break;
							}
						case 'weight':
							if (!document.getElementById("weight").value.length == 0) {
								$('#booking_rate').focus();
								e.preventDefault();
								break;
							}
						case 'booking_rate':
							if (!document.getElementById("booking_rate").value.length == 0) {
								$('#lorry_freight').focus();
								
								e.preventDefault();
								break;
							}
						case 'lorry_freight':
							if (!document.getElementById("lorry_freight").value.length == 0) {
								$('#advance').focus();
								e.preventDefault();
								break;
							}
						case 'advance':
							if (!document.getElementById("advance").value.length == 0) {
								$('#cash_advance').focus();
								e.preventDefault();
								break;
							}
						case 'cash_advance':
							if (!document.getElementById("cash_advance").value.length == 0) {
								$('#diesel').focus();
								e.preventDefault();
								break;
							}
						case 'diesel':
							if (!document.getElementById("diesel").value.length == 0) {
							    //Advance-Cash_Advance-Diesel = Neft_Amount
							    var advance1 = Number(document.getElementById("advance").value);
                    			var cash_advance1 = Number(document.getElementById("cash_advance").value);
                    			var diesel1 = Number(document.getElementById("diesel").value);
                    			var neft_amount1 = advance1 -  + cash_advance1 - diesel1;
			                    document.getElementById("neft_amount").value = neft_amount1.toFixed(2);
								$('#neft_date').focus();
								e.preventDefault();
								break;
							}
						case 'neft_date':
							if (!document.getElementById("neft_date").value.length == 0) {
								$('#others').focus();
								e.preventDefault();
								break;
							}
						case 'others':
							if (!document.getElementById("others").value.length == 0) {
							    //Lorry_Freight-Advance + Others = Balance
							    var lorry_freight1 = Number(document.getElementById("lorry_freight").value);
                    			var advance1 = Number(document.getElementById("advance").value);
                    			var others1 = Number(document.getElementById("others").value);
                    			var bookc1 = Number(document.getElementById("booking_rate").value);
                    			var others1 = Number(document.getElementById("others").value);
                    			var tot = bookc1 + others1;
                    			document.getElementById("totalval").value = tot.toFixed(2);
			                    convertNumberToWords();
								$('#extra').focus();
								e.preventDefault();
								break;
							}
						case 'extra':
							if (!document.getElementById("extra").value.length == 0) {
							    //Lorry_Freight-Advance + Others = Balance
							    var lorry_freight1 = Number(document.getElementById("lorry_freight").value);
                    			var advance1 = Number(document.getElementById("advance").value);
                    			var others1 = Number(document.getElementById("others").value);
                    			var balance1 = lorry_freight1 -  + advance1 + others1;
								$('#balance').focus();
								e.preventDefault();
								break;
							}
						case 'balance':
							if (!document.getElementById("balance").value.length == 0) {
							    //Extra_Charges+ Balance = Total_Paid
							    var extra1 = Number(document.getElementById("extra").value);
                    			var balance1 = Number(document.getElementById("balance").value);
                    			var total_paid1 = extra1 + balance1;
			                    document.getElementById("total_paid").value = total_paid1.toFixed(2);
								$('#total_paid').focus();
								e.preventDefault();
								break;
							}
						case 'total_paid':
							if (!document.getElementById("total_paid").value.length == 0) {
								$('#bal_paid_date').focus();
								e.preventDefault();
								break;
							}
						case 'bal_paid_date':
							if (!document.getElementById("bal_paid_date").value.length == 0) {
								$('#delivery_date').focus();
								e.preventDefault();
								break;
							}
						case 'delivery_date':
							if (!document.getElementById("delivery_date").value.length == 0) {
								$('#acc_rec_date').focus();
								e.preventDefault();
								break;
							}
						case 'acc_rec_date':
							if (!document.getElementById("acc_rec_date").value.length == 0) {
								$('#driver_name').focus();
								e.preventDefault();
								break;
							}
						case 'driver_name':
							if (!document.getElementById("driver_name").value.length == 0) {
								$('#driver_mob_no').focus();
								e.preventDefault();
								break;
							}
						case 'driver_mob_no':
							if (!document.getElementById("driver_mob_no").value.length == 0) {
								$('#mamul_charges').focus();
								e.preventDefault();
								break;
							}
						case 'mamul_charges':
							if (!document.getElementById("mamul_charges").value.length == 0) {
							    //Booking_Rate - Lorry_Freight + Mamul_Charge = Profit
							    var booking_rate1 = Number(document.getElementById("booking_rate").value);
                    			var lorry_freight1 = Number(document.getElementById("lorry_freight").value);
                    			var mamul_charges1 = Number(document.getElementById("mamul_charges").value);
                    			var profit1 = booking_rate1 - lorry_freight1 + mamul_charges1;
			                    document.getElementById("profit").value = profit1.toFixed(2);
								$('#remarks').focus();
								e.preventDefault();
								break;
							}
						case 'remarks':
							if (!document.getElementById("remarks").value.length == 0) {
								$('#status_one').focus();
								e.preventDefault();
								break;
							}
						case 'status_one':
							if (!document.getElementById("status_one").value.length == 0) {
								$('#bill_date').focus();
								e.preventDefault();
								break;
							}
						case 'bill_date':
							if (!document.getElementById("bill_date").value.length == 0) {
								$('#rupeesinwords').focus();
								e.preventDefault();
								break;
							}
						case 'rupeesinwords':
							if (!document.getElementById("rupeesinwords").value.length == 0) {
								$('#action').focus();
								e.preventDefault();
								break;
							}
					}
				}
			});
		});
		
	});
</script>
<script>
    $("#diesel").change(function(){ 
        var advance1 = Number(document.getElementById("advance").value);
    	var cash_advance1 = Number(document.getElementById("cash_advance").value);
    	var diesel1 = Number(document.getElementById("diesel").value);
    	var neft_amount1 = advance1 -  + cash_advance1 - diesel1;
        document.getElementById("neft_amount").value = neft_amount1.toFixed(2);
    	$('#neft_date').focus();
    });
    
    $("#balance").change(function(){ 
        var extra1 = Number(document.getElementById("extra").value);
		var balance1 = Number(document.getElementById("balance").value);
		var total_paid1 = extra1 + balance1;
        document.getElementById("total_paid").value = total_paid1.toFixed(2);
		$('#total_paid').focus();
    });
    
    $("#mamul_charges").change(function(){ 
        var booking_rate1 = Number(document.getElementById("booking_rate").value);
		var lorry_freight1 = Number(document.getElementById("lorry_freight").value);
		var mamul_charges1 = Number(document.getElementById("mamul_charges").value);
		var profit1 = booking_rate1 - lorry_freight1 + mamul_charges1;
        document.getElementById("profit").value = profit1.toFixed(2);
		$('#remarks').focus();
    });
    $("#others").change(function(){ 
        var lorry_freight1 = Number(document.getElementById("lorry_freight").value);
		var advance1 = Number(document.getElementById("advance").value);
		var others1 = Number(document.getElementById("others").value);
		var bookc1 = Number(document.getElementById("booking_rate").value);
		var others1 = Number(document.getElementById("others").value);
		var tot = bookc1 + others1;
		document.getElementById("totalval").value = tot.toFixed(2);
        convertNumberToWords();
		$('#extra').focus();
    });
</script>
<script>
function convertNumberToWords() {
	var amount = document.getElementById("totalval").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>