<?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'];
    }
    $width = $width . "px";
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();
 //echo "<h1 align='center'>Welcome ".$_SESSION["user"]. "</h1>";
 //echo "<h3 align='center'>Automatic Logout after 1 minute of inactive</h3>";
 //echo "<p align='center'><a href='../login/logout.php'>Logout</a></p>";
 //echo "<p align='center'><a href='../main/welcome.php'>Welcome1</a></p>";
 }
}
else
{
 header('Location:../login/index.php');
}
?>
<!doctype html>
<html>
<head>
<title>Purchase</title>
<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 type="text/javascript" src="../js/jquery.maskedinput.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/css/bootstrap-multiselect.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
<style>
    label {
        font-size: 15px;
        top: 15px;
        font-weight: 500;
        display: inline-transparent;
        margin-bottom: .5rem;
    }
</style>
</head>
<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:200px; height : 55px; margin-top : px;" type="button" onclick="location.href='invshow';" value="Re Print Invoice">
        <h1 style="color:white; font-size:24px; margin-top: -40px;" class="text-primary" align="center">Purchase Invoice</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: 100%; height:10px; margin-left: -10px; margin-top: -25px;">
		<form method="post" id="insert_form">
			<div class="row" style="min-width: <?php echo $width; ?>; width: auto; height:10px; margin-left: -10px;">
				<div class="col-xs-3">
					<label><span class="validation-color"></span></label><a href="../supplier/index" style="color:black; font-size:14px; font-weight:bold;" data-toggle="modal" data-target="#myModal" class="pull-left">+ Supplier Name</a>
					<input type="text" id="supplier_name" class="roundedCategory" style="font-size:18px; margin-top: -2px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required autofocus>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Supplier_Code</label>
					<input type="text" id="supplier_code" class="roundedCategory" readonly style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Supp_Place</label>
					<input type="text" id="supplier_place" class="roundedCategory" readonly style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">GST_Number</label>
					<input type="text" id="supplier_gstno" class="roundedCategory" readonly style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Tax_Code</label>
					<input type="text" id="tax_code" class="roundedCategory" readonly style="font-size:18px; width:100%; margin-top: -6px; height: 35px; font-weight:bold; color: #000066;" readonly value="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Transporter_Name</label>
					<input type="text" id="transporter_name" class="roundedCategory" style="font-size:18px; width:100%; margin-top: -6px; height: 35px; font-weight:bold; color: #000066;" value="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-2">
					<label style="font-size:14px;font-weight:bold;">Invoice_No</label>
					<input type="text" id="srno" class="roundedCategory" style="font-size:18px; width:100%; height: 35px; margin-top: -6px; font-weight:bold; color: #000066;" value="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
					<span id="availability"></span>
					<input type="hidden" style="width: 100%;" name="grn_number" id="grn_number" />
				</div>
				<div class="col-xs-2">
					<label style="font-size:14px;font-weight:bold;">Inv_Dt (DD-MM-YYY)</label>
					<input type="text" id="invdt" class="roundedCategory" style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="<?php date_default_timezone_set('Asia/Kolkata'); echo date( 'd-m-Y H:i:s'); ?>" onfocus="GetCustCode(this)" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required autofocus>
					<!--input type="text" id="invdt" class="roundedCategory" style="font-size:18px; margin-top: 8px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="<?php date_default_timezone_set('Asia/Kolkata'); echo date( 'd-m-Y'); ?>" onfocus="GetCustCode(this)" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required autofocus-->
					<input type="hidden" name="invdt1" class="roundedCategory" id="invdt1" style = "font-size:14px; width: 200px; height: 35px;font-weight:bold; color: #000066;"  onfocus="this.select();" style="font-weight: bold; font-size:14px; text-align: center;" value="<?php date_default_timezone_set('Asia/Kolkata'); echo date( 'Y-m-d H:i:s'); ?>" autocomplete = "off" required>
					<input type="hidden" name="grn_date" class="roundedCategory" id="grn_date" style="font-size:14px; height: 35px; font-weight:bold; color: #000066;" onfocus="this.select();" style="font-weight: bold; font-size:14px; text-align: center;" value="<?php date_default_timezone_set('Asia/Kolkata'); echo date('Y-m-d H:i:s'); ?>" autocomplete="off" required>
				</div>
			</div>
			<br><br><br>
			<div class="row" style="min-width: <?php echo $width; ?>; width: auto; height:10px; margin-left: -10px;">
			    <div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Challn_No</label>
					<input type="text" id="challan_no" class="roundedCategory" style="font-size:18px;  margin-top: -6px;width:100%; height: 35px; font-weight:bold; color: #000066;" value="-" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Challn_Dt</label>
					<input type="text" id="challan_date" class="roundedCategory" style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="-" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Po_No</label>
					<input type="text" id="po_no" class="roundedCategory" style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="-" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Po_Date</label>
					<input type="text" id="po_date" class="roundedCategory" style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="-" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Lr_No</label>
					<input type="text" id="lr_no" class="roundedCategory" style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="-" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Lr_Dt</label>
					<input type="text" id="lr_dt" class="roundedCategory" style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="-" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">No_of_Boxes</label>
					<input type="text" id="no_of_parcel" class="roundedCategory" style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="-" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Opening_Balance</label>
					<input type="text" id="opening" class="roundedCategory" readonly style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="-" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Debit_Balance</label>
					<input type="text" id="debit" class="roundedCategory" readonly style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="-" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Credit_Balance</label>
					<input type="text" id="credit" class="roundedCategory" readonly style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="-" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Closing_Balance</label>
					<input type="text" id="clbalance" class="roundedCategory" readonly style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="-" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>
				<div class="col-xs-1">
					<label style="font-size:14px;font-weight:bold;">Rupees In Words</label>
					<input type="text" id="rsinwords" class="roundedCategory" readonly style="font-size:18px; margin-top: -6px; width:100%; height: 35px; font-weight:bold; color: #000066;" value="-" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
				</div>

			</div>
			<!-- Input Text Area Ends for Selecting Supplier Name ...... and Invoice Number -->
			<br><br><br><br>
			<!-- Product Autocomplete with Auto Fill Table Begins-->
			<div class="container" style = "min-width: <?php echo $width; ?>; width: auto; height:110px; margin-left: -12px; margin-top: -40px; overflow:auto;">
				<table style="min-width: <?php echo $width; ?>; width: auto;" border='1' style='border-collapse: collapse;'>
					<thead>
						<tr>
							<th style="text-align: left; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;"><a href="../product/index" style="color:white;" data-toggle="modal" data-target="#myModal" class="pull-right">+ Add New Part Number</a>Part_Number</th>
							<th style="text-align: left; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Description_One</th>
							<th style="text-align: left; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Description_Two</th>
							<th style="text-align: left; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">HSN_Code</th>
							<th style="text-align: righT; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">List</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Disc_Per</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Stk_Qty</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Box_Qty</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Quantity</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">List_Value</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Disc_Amt</th>
							<th style="text-align: center; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Action</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Rate</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Sales_Val</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Sgst_Per</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Sgst_Amt</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Cgst_Per</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Cgst_Amt</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Igst_Per</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Igst_Amt</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Inv_Val</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Cost</th>
							<th style="text-align: right; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Cost_Val</th>
							<th style="text-align: left; background-color:#0066ff; font-size:14px; font-weight:bold; color: white;">Segment</th>
						</tr>
					</thead>
					<tr>
						<input type="hidden" name="new" value="1" />
						<td><input type='text' style="width:300px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: left" id='partno' onfocus="ShowTotal()" onkeyup="myFunction()" onclick="this.select();" autofocus autocomplete="off"></td>
						<td><input type='text' style="width:350px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: left" readonly id='description_one' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:200px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: left" id='description_two' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: left" readonly id='hsn_code' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" id='list' onfocus="this.select();" onkeypress="return isNumberKey(this, event);" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" id='disc_per' onkeypress="return isNumberKey(this, event);" onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right; background-color:#80b3ff;" readonly id='stk_qty' onkeypress="return isNumberKey(this, event);" onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right; background-color:#80b3ff;" readonly id='boxqty' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" id='qty' onfocus="this.select();" onkeypress="return isNumberKey(this, event);" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" readonly id='list_value' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" readonly id='disc_amt' onfocus="this.select();" autocomplete="off"></td>
						<td><input type="button" class="btn btn-success" style="width:100px; font-size:18px; background-color:#0066ff; font-weight:bold; height:35px; text-align: center" id="addnew" value="Add" /></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" readonly id='rate_one' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" readonly id='sales_val' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" readonly id='sgst_per' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" readonly id='sgst_amt' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" readonly id='cgst_per' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" readonly id='cgst_amt' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" readonly id='igst_per' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" readonly id='igst_amt' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" readonly id='inv_val' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" readonly id='cost' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:100px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: right" readonly id='cost_val' onfocus="this.select();" autocomplete="off"></td>
						<td><input type='text' style="width:180px; font-size:18px; height:35px; font-weight:bold; color: #000066; text-align: left" readonly id='segment' onfocus="this.select();" autocomplete="off"></td>
					</tr>
				</table>
			</div>
			<!-- Product Autocomplete with Auto Fill Table Ends-->
			<!-- Product Table Begins-->
			<div class="row" class="container" style="min-width: <?php echo $width; ?>; width: auto; margin-left:0px; margin-top:-20px; font-size:16px; height:200px; overflow:scroll">
				<div style="min-width: <?php echo $width; ?>; width: auto;" id="ProductTable"></div>
			</div>
			<!-- Product Table Ends-->
			<!-- Total Table Begins-->
			<div class="row" class="container" style="width:18.5%; float: right; font-size:16px;">
				<div id="TotalTable"></div>
			</div>
			<!-- Total Table Ends-->
			<!-- Supplier Details and Product Table Begins-->
			<div class="row">
				<div class="col-md-10">
					<div style="min-width: 100%; width: auto; float: left; margin-left: 5px;" class="table-responsive">
						<table style="min-width: 100%; width: auto; float: left; margin-left: 0px; font-family:Tahoma;color:black; font-size:16px; " class="table table-bordered">
							<tbody>
								<tr>
									<input type="button" class="btn btn-info" style="min-width: 99.6%; width: auto; font-size:18px; background-color:#0066ff; height:35px; text-align: center" id="addinv" value="Save_Invoice" />
								<tr>
									<td style="vertical-align: middle;" class="text-right"><strong>Address_One</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="supplier_address_one" type="text"></td>
									<td style="vertical-align: middle;" class="text-right"><strong>Pan_Number</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="supplier_pan_no" type="text"></td>
								</tr>
								<tr>
									<td style="vertical-align: middle;" class="text-right"><strong>Address_Two</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="supplier_address_two" type="text"></td>
									<td style="vertical-align: middle;" class="text-right"><strong>Email_Id</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="supplier_email" type="text"></td>
								</tr>
								<tr>
									<td style="vertical-align: middle;" class="text-right"><strong>Address_Three</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="supplier_address_three" type="text"></td>
									<td style="vertical-align: middle;" class="text-right"><strong>Aadhar_Number</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="supplier_aadhar_no" type="text"></td>
								</tr>
								<tr>
									<td style="vertical-align: middle;" class="text-right"><strong>Pin_Code</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="supplier_pin_code" type="text"></td>
									<td style="vertical-align: middle;" class="text-right"><strong>MOQ</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="moq" type="text"></td>
								</tr>
								<tr>
									<td style="vertical-align: middle;" class="text-right"><strong>Phone_Number</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="supplier_phone" type="text"></td>
									<td style="vertical-align: middle;" class="text-right"><strong>LY_Sales</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="ly_sales" type="text"></td>
								</tr>
								<tr>
									<td style="vertical-align: middle;" class="text-right"><strong>Mobile_Number</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="supplier_mobile" type="text"></td>
									<td style="vertical-align: middle;" class="text-right"><strong>CY_Sales</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="cy_sales" type="text"></td>
								</tr>
								<tr>
									<td style="vertical-align: middle;" class="text-right"><strong>State_Code</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="supplier_st_code" type="text"></td>
									<td style="vertical-align: middle;" class="text-right"><strong>Pending</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="pending" type="text"></td>
								</tr>
								<tr>
									<td style="vertical-align: middle;" class="text-right"><strong>State_Name</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="supplier_st_name" type="text"></td>
									<td style="vertical-align: middle;" class="text-right"><strong>Dispatch</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="dispatch1" type="text"></td>
								</tr>
								<tr>
									<td style="vertical-align: middle;" class="text-right"><strong>Due_Days</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="due_days" type="text"></td>
									<td style="vertical-align: middle;" class="text-right"><strong>Due_Date</strong></td>
									<td style="height:20px;"><input class="roundedCategory" readonly style="font-size:16px; color: #000066; font-weight:bold; width:550px; height:25px; text-align: left" onfocus="this.select();" id="due_date" type="text"></td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>
			<!-- Supplier Details and Product Table Ends-->
		</form>
	</div>
</div>
<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 type="text/javascript">
    $(function() {
		$('#invdt').mask('99-99-9999 99:99:99');
    });
</script>
<script>
    $(document).on('keyup', function(e) {
        if (e.key == "Escape"){
          window.location.href = "../main/index"
        }
    });
</script>
<script>
    /*
    $(document).ready(function () {
        $('#invdt').datepicker({
            autoclose: true,
            format:  'dd-mm-yyyy',
        });
    });
    */
</script> 
<?php
$date = new DateTime();
$current_timestamp = $date->getTimestamp();
?>
<script>
	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 type='text/javascript'>
		$(document).keydown(function(objEvent) {		
		if (objEvent.keyCode == 9) {  //tab pressed
			objEvent.preventDefault(); // stops its action
		}		
		$("#invdt").blur(function(){
		var invdt = $(this).val().trim();
		document.getElementById('invdt1').value = document.getElementById('invdt').value;
		if(invdt != ''){
			$.ajax({
				url: 'checkdt',
				type: 'post',
				data: {invdt:invdt},
				success: function(response){
					$("#invdt1").val(response);
					var duedays = document.getElementById('due_days').value;			
					var tt = document.getElementById('invdt1').value;
					const date = new Date(document.getElementById('invdt1').value);
					var futureDate = new Date(date.setDate(date.getDate() + parseInt(duedays))).toLocaleDateString();
					var newfuturedate = futureDate.split('/');
					var newFuDate = newfuturedate[1] + '/' + newfuturedate[0].slice(-2) + '/' + newfuturedate[2];
					document.getElementById('due_date').value = newFuDate;
				}
			});
		}else{
			
		}
	});
	});
		$("#srno").blur(function(){
			var invnoavl = $(this).val().trim();
			var supplier_code = $('#supplier_code').val().trim();
			if(invnoavl != ''){
				$.ajax({
					url: 'check',
					type: 'post',
					data: {invnoavl:invnoavl,supplier_code:supplier_code},
					success: function(response){
						if(response == 'Invoice Number already Available'){
							$('#srno').focus();
							$("#uname_response").html(response);
						}else{
							$('#invdt').focus();
							$("#uname_response").html("");
						}
					}
				});
			}else{
				$("#uname_response").html("");
			}
		});
		// Supplier Autocomplete With Auto Fill
		$(function() {
			$("#supplier_name").autocomplete({
				source: function(request, response) {
					$.ajax({
						url: "fetchsupplier",
						type: 'post',
						dataType: "json",
						data: {
							search: request.term
						},
						success: function(data) {
							response(data);
						}
					});
				},
				select: function(event, ui) {
					$('#supplier_name').val(ui.item.label);
					$('#supplier_code').val(ui.item.value);
					$('#supplier_place').val(ui.item.supplier_place);
					$('#supplier_gstno').val(ui.item.supplier_gstno);
					$('#tax_code').val(ui.item.tax_code);
					$('#transporter_name').val(ui.item.transporter_name);
					$('#srno').val(ui.item.srno);
					$('#grn_number').val(ui.item.grn_number);
					//$('#grn_date').val(ui.item.grn_date);
					$('#opening').val(ui.item.opening);
					$('#debit').val(ui.item.debit);
					$('#credit').val(ui.item.credit);
					$('#clbalance').val(ui.item.clbalance);
					$('#supplier_address_one').val(ui.item.supplier_address_one);
					$('#supplier_address_two').val(ui.item.supplier_address_two);
					$('#supplier_address_three').val(ui.item.supplier_address_three);
					$('#supplier_pin_code').val(ui.item.supplier_pin_code);
					$('#supplier_phone').val(ui.item.supplier_phone);
					$('#supplier_mobile').val(ui.item.supplier_mobile);
					$('#supplier_st_code').val(ui.item.supplier_st_code);
					$('#supplier_st_name').val(ui.item.supplier_st_name);
					$('#supplier_pan_no').val(ui.item.supplier_pan_no);
					$('#supplier_email').val(ui.item.supplier_email);
					$('#supplier_aadhar_no').val(ui.item.supplier_aadhar_no);
					$('#due_days').val(ui.item.due_days);
					var duedays = document.getElementById('due_days').value;			
					var tt = document.getElementById('invdt1').value;
					const date = new Date(document.getElementById('invdt1').value);
					var futureDate = new Date(date.setDate(date.getDate() + parseInt(duedays))).toLocaleDateString();
					var newfuturedate = futureDate.split('/');
					var newFuDate = newfuturedate[1] + '/' + newfuturedate[0].slice(-2) + '/' + newfuturedate[2];
					document.getElementById('due_date').value = newFuDate;
					document.getElementById("srno").focus();//venkat
					updatesuppcode();
					return false;
				}
			});
		});

		$('#srno').blur(function(){
		 var username = $(this).val();
		 $supplier_code = $('#supplier_code').val();
		 $.ajax({
		  url:'check',
		  method:"POST",
		  data:{user_name:username,supplier_code: $supplier_code},
		  success:function(data)
		  {
		   if(data != '0')
		   {
			//$('#availability').html('<span class="text-danger">Invoice Number Already Available</span>');
			//$('#register').attr("disabled", true);			
			document.getElementById('srno').focus();
		   }
		   else
		   {
			//$('#availability').html('<span class="text-success">Invoice Number Available</span>');
			//$('#register').attr("disabled", false);
		   }
		  }
		 })
	  });
  
		function updatesuppcode() {
			var supplier_code = document.getElementById('supplier_code').value
			$.ajax({
				url: "updatesuppcode",
				type: 'post',
				dataType: "json",
				data: {
					supplier_code: supplier_code,
				},
				success: function() {

				}
			});
		}
		// Product Autocomplete With Auto Fill
		$(function() {
			$("#partno").autocomplete({
				source: function(request, response) {
					$.ajax({
						url: "fetchproduct",
						type: 'post',
						dataType: "json",
						data: {
							search: request.term
						},
						success: function(data) {
							response(data);
						}
					});
				},
				select: function(event, ui) {
					$('#partno').val(ui.item.label);
					$('#description_one').val(ui.item.value);
					$('#description_two').val(ui.item.description_two);
					$('#hsn_code').val(ui.item.hsn_code);
					$('#list').val(ui.item.list);
					$('#cost').val(ui.item.cost);
					$('#segment').val(ui.item.segment);
					$('#stk_qty').val(ui.item.stk_qty);
					$('#boxqty').val(ui.item.boxqty);
					$('#disc_per').val(ui.item.disc_per);
					$('#moq').val(ui.item.moq);
					$('#ly_sales').val(ui.item.ly_sales);
					$('#cy_sales').val(ui.item.cy_sales);
					$('#pending').val(ui.item.pending);
					$('#dispatch1').val(ui.item.dispatch1);
					document.getElementById('qty').value = "";
					var ss = document.getElementById('tax_code').value;
					if (ss == 'GST-B2B') {
						$('#sgst_per').val(ui.item.sgst_per);
						$('#cgst_per').val(ui.item.cgst_per);
						document.getElementById('igst_per').value = '0.00';
					}
					if (ss == 'GST-B2C') {
						$('#sgst_per').val(ui.item.sgst_per);
						$('#cgst_per').val(ui.item.cgst_per);
						document.getElementById('igst_per').value = '0.00';
					}
					if (ss == 'I-GST') {
						$('#igst_per').val(ui.item.igst_per);
						document.getElementById('sgst_per').value = '0.00';
						document.getElementById('cgst_per').value = '0.00';
					}
					document.getElementById("list").focus();
					return false;
				}
			});
		});
		// INPUT TEXT BOX KEYPRESS(ENTER) EVENT
		$(document).ready(function() {			
			$('input').on('keypress', function(e) {
				if (e.which == 13) {
					switch ($(this).attr('id')) {
						case 'partno':
							$('#list').focus();
							e.preventDefault();
							break;
						case 'srno':
							$('#invdt').focus();
							e.preventDefault();
							break;							
						case 'invdt':
							$('#partno').focus();
							e.preventDefault();
							break;
						case 'list':
							$('#disc_per').focus();
							e.preventDefault();
							break;
						case 'disc_per':
							$('#qty').focus();
							e.preventDefault();
							break;
						case 'qty':
							var qty = document.getElementById('qty').value;
							var list = document.getElementById('list').value;
							var disc_per = document.getElementById('disc_per').value;
							var cost = document.getElementById('cost').value;
							var listval = (qty * list);
							var discamt = (listval * disc_per) / 100;
							var rate_one = (list * disc_per) / 100;
							var salesval = (listval - discamt);
							var sgst_per = document.getElementById('sgst_per').value;
							var cgst_per = document.getElementById('cgst_per').value;
							var igst_per = document.getElementById('igst_per').value;
							var sgst_amt = (salesval * sgst_per) / 100;
							var cgst_amt = (salesval * cgst_per) / 100;
							var igst_amt = (salesval * igst_per) / 100;
							var costval = (cost * qty);
							document.getElementById('list_value').value = listval.toFixed(2);
							document.getElementById('disc_amt').value = discamt.toFixed(2);
							document.getElementById('rate_one').value = rate_one.toFixed(2);
							document.getElementById('sales_val').value = salesval.toFixed(2);
							document.getElementById('sgst_amt').value = sgst_amt.toFixed(2);
							document.getElementById('cgst_amt').value = cgst_amt.toFixed(2);
							document.getElementById('igst_amt').value = igst_amt.toFixed(2);
							var invval = salesval + sgst_amt + cgst_amt + igst_amt;
							document.getElementById('inv_val').value = invval.toFixed(2);
							document.getElementById('cost_val').value = costval.toFixed(2);
							$('#addnew').focus();
							e.preventDefault();
							break;
					}
				}
			});
		});
		//INSERT INTO INVTEMP_MST TABLE BEGINS
		$(document).ready(function() {
			ShowProduct();
			$(document).on('click', '#addnew', function() {
				if ($('#partno').val() == "" || $('#description_one').val() == "" || $('#description_two').val() == "" || $('#hsn_code').val() == "" || $('#list').val() == "" || $('#disc_per').val() == "" || $('#qty').val() == "") {
					alert('Please input data first');
				} else {
					$partno = $('#partno').val();
					$description_one = $('#description_one').val();
					$description_two = $('#description_two').val();
					$hsn_code = $('#hsn_code').val();
					$qty = $('#qty').val();
					$list = $('#list').val();
					$segment = $('#segment').val();
					$disc_per = $('#disc_per').val();
					$disc_amt = $('#disc_amt').val();
					$list_value = $('#list_value').val();
					$rate_one = $('#rate_one').val();
					$sales_val = $('#sales_val').val();
					$sgst_per = $('#sgst_per').val();
					$sgst_amt = $('#sgst_amt').val();
					$cgst_per = $('#cgst_per').val();
					$cgst_amt = $('#cgst_amt').val();
					$igst_per = $('#igst_per').val();
					$igst_amt = $('#igst_amt').val();
					$inv_val = $('#inv_val').val();
					$cost = $('#cost').val();
					$cost_val = $('#cost_val').val();
					$.ajax({
						type: "POST",
						url: "addnew",
						data: {
							partno: $partno,
							description_one: $description_one,
							description_two: $description_two,
							hsn_code: $hsn_code,
							qty: $qty,
							list: $list,
							segment: $segment,
							disc_per: $disc_per,
							disc_amt: $disc_amt,
							list_value: $list_value,
							rate_one: $rate_one,
							sales_val: $sales_val,
							sgst_per: $sgst_per,
							sgst_amt: $sgst_amt,
							cgst_per: $cgst_per,
							cgst_amt: $cgst_amt,
							igst_per: $igst_per,
							igst_amt: $igst_amt,
							inv_val: $inv_val,
							cost: $cost,
							cost_val: $cost_val,
							add: 1,
						},
						success: function() {
							ShowProduct();
							document.getElementById('partno').value = "";
							document.getElementById('description_one').value = "";
							document.getElementById('description_two').value = "";
							document.getElementById('hsn_code').value = "";
							document.getElementById('qty').value = "";
							document.getElementById('list').value = "";
							document.getElementById('segment').value = "";
							document.getElementById('disc_per').value = "";
							document.getElementById('disc_amt').value = "";
							document.getElementById('list_value').value = "";
							document.getElementById('rate_one').value = "";
							document.getElementById('sales_val').value = "";
							document.getElementById('sgst_per').value = "";
							document.getElementById('sgst_amt').value = "";
							document.getElementById('cgst_per').value = "";
							document.getElementById('cgst_amt').value = "";
							document.getElementById('igst_per').value = "";
							document.getElementById('igst_amt').value = "";
							document.getElementById('inv_val').value = "";
							document.getElementById('cost').value = "";
							document.getElementById('cost_val').value = "";
							document.getElementById('stk_qty').value = "";
							document.getElementById('boxqty').value = "";
							document.getElementById('moq').value = "";
							document.getElementById('ly_sales').value = "";
							document.getElementById('cy_sales').value = "";
							document.getElementById('pending').value = "";
							document.getElementById('dispatch1').value = "";
							document.getElementById("partno").focus();
						}
					});
				}
			});
		});
		//INSERT INTO INV_MST TABLE BEGINS
		$(document).ready(function() {
			//ShowProduct();
			$(document).on('click', '#addinv', function() {
				if ($('#supplier_name').val() == "" || $('#supplier_code').val() == "" || $('#srno').val() == "" || $('#invdt').val() == "") {
					alert('Please input data first');
				} else {
					$srno = $('#srno').val();
					$invdt = $('#invdt').val();
					$tax_code = $('#tax_code').val();
					$supplier_code = $('#supplier_code').val();
					$supplier_name = $('#supplier_name').val();
					$supplier_address_one = $('#supplier_address_one').val();
					$supplier_address_two = $('#supplier_address_two').val();
					$supplier_address_three = $('#supplier_address_three').val();
					$supplier_place = $('#supplier_place').val();
					$supplier_pin_code = $('#supplier_pin_code').val();
					$supplier_phone = $('#supplier_phone').val();
					$supplier_mobile = $('#supplier_mobile').val();
					$supplier_email = $('#supplier_email').val();
					$supplier_gstno = $('#supplier_gstno').val();
					$supplier_pan_no = $('#supplier_pan_no').val();
					$supplier_aadhar_no = $('#supplier_aadhar_no').val();
					$supplier_st_code = $('#supplier_st_code').val();
					$supplier_st_name = $('#supplier_st_name').val();
					$po_no = $('#po_no').val();
					$po_date = $('#po_date').val();
					$challan_no = $('#challan_no').val();
					$challan_date = $('#challan_date').val();
					$lr_no = $('#lr_no').val();
					$lr_dt = $('#lr_dt').val();
					$transporter_name = $('#transporter_name').val();
					$no_of_parcel = $('#no_of_parcel').val();
					$due_days = $('#due_days').val();
					$due_date = $('#due_date').val();
					$rsinwords = $('#rsinwords').val(); //
					$total_qty = $('#total_qty').val();
					$total_disc_amt = $('#total_disc_amt').val();
					$total_list_value = $('#total_list_value').val();
					$total_sales_val = $('#total_sales_val').val();
					$total_sgstamt = $('#total_sgstamt').val();
					$total_cgstamt = $('#total_cgstamt').val();
					$total_igstamt = $('#total_igstamt').val();
					$total_val = $('#total_val').val();
					$roundoff = $('#roundoff').val();
					$total_inv_val = $('#total_inv_val').val();
					$total_cost = $('#total_cost').val();
					$grn_number = $('#grn_number').val();
					$grn_date = $('#grn_date').val();
					$.ajax({
						type: "POST",
						url: "saveinvoice",
						data: {
							srno: $srno,
							invdt: $invdt,
							tax_code: $tax_code,
							supplier_name: $supplier_name,
							supplier_code: $supplier_code,
							supplier_address_one: $supplier_address_one,
							supplier_address_two: $supplier_address_two,
							supplier_address_three: $supplier_address_three,
							supplier_place: $supplier_place,
							supplier_pin_code: $supplier_pin_code,
							supplier_phone: $supplier_phone,
							supplier_mobile: $supplier_mobile,
							supplier_email: $supplier_email,
							supplier_gstno: $supplier_gstno,
							supplier_pan_no: $supplier_pan_no,
							supplier_aadhar_no: $supplier_aadhar_no,
							supplier_st_code: $supplier_st_code,
							supplier_st_name: $supplier_st_name,
							po_no: $po_no,
							po_date: $po_date,
							challan_no: $challan_no,
							challan_date: $challan_date,
							lr_no: $lr_no,
							lr_dt: $lr_dt,
							transporter_name: $transporter_name,
							no_of_parcel: $no_of_parcel,
							due_days: $due_days,
							due_date: $due_date,
							rsinwords: $rsinwords, //
							total_qty: $total_qty,
							total_disc_amt: $total_disc_amt,
							total_list_value: $total_list_value,
							total_sales_val: $total_sales_val,
							total_sgstamt: $total_sgstamt,
							total_cgstamt: $total_cgstamt,
							total_igstamt: $total_igstamt,
							total_val: $total_val,
							roundoff: $roundoff,
							total_inv_val: $total_inv_val,
							total_cost: $total_cost,
							grn_number: $grn_number,
							grn_date: $grn_date,
							addinv: 1,
						},
						success: function() {
							ShowProduct();
							document.getElementById('supplier_name').value = "";
							document.getElementById('supplier_code').value = "";
							document.getElementById('supplier_address_one').value = "";
							document.getElementById('supplier_address_two').value = "";
							document.getElementById('supplier_address_three').value = "";
							document.getElementById('supplier_place').value = "";
							document.getElementById('supplier_pin_code').value = "";
							document.getElementById('supplier_phone').value = "";
							document.getElementById('supplier_mobile').value = "";
							document.getElementById('supplier_email').value = "";
							document.getElementById('supplier_gstno').value = "";
							document.getElementById('supplier_pan_no').value = "";
							document.getElementById('supplier_aadhar_no').value = "";
							document.getElementById('supplier_st_code').value = "";
							document.getElementById('supplier_st_name').value = "";
							document.getElementById('po_no').value = "-";
							document.getElementById('po_date').value = "-";
							document.getElementById('challan_no').value = "-";
							document.getElementById('challan_date').value = "-";
							document.getElementById('lr_no').value = "-";
							document.getElementById('lr_dt').value = "-";
							document.getElementById('transporter_name').value = "-";
							document.getElementById('no_of_parcel').value = "-";
							document.getElementById('due_days').value = "";
							document.getElementById('due_date').value = "";
							document.getElementById('rsinwords').value = "";
							document.getElementById('tax_code').value = "";
							document.getElementById('opening').value = "";
							document.getElementById('debit').value = "";
							document.getElementById('credit').value = "";
							document.getElementById('clbalance').value = "";
							document.getElementById('srno').value = "";
							document.getElementById('total_qty').value = "";
							document.getElementById('total_disc_amt').value = "";
							document.getElementById('total_list_value').value = "";
							document.getElementById('total_sales_val').value = "";
							document.getElementById('total_sgstamt').value = "";
							document.getElementById('total_cgstamt').value = "";
							document.getElementById('total_igstamt').value = "";
							document.getElementById('total_val').value = "";
							document.getElementById('roundoff').value = "";
							document.getElementById('total_inv_val').value = "";
							document.getElementById('total_cost').value = "";
							document.getElementById('supplier_name').focus();
							window.location = 'invprt';
							//var product_id=1;
							//window.location.replace("invprt?id=" + product_id);
							//window.location.replace("invreprint?grn_number=" + $srno);
							//window.location.replace("href="invreprint? grn_number='.$srno.'");
						}
					});
				}
			});
		});
		//Delete Product Begins
		$(document).ready(function() {
			$(document).on('click', '.delete', function() {
				var partno = $(this).data('partno');
				//alert(partno);
				$.ajax({
					type: "POST",
					url: "delete_ajax",
					data: {
						partno: partno,
						delpost: 1,
					},
					success: function() {
						alert('Deleted Sucessfully');
						ShowProduct();
					}
				});
			});
		});

		//Delete Product Ends
		$(document).ready(function() {
			ShowProduct();
		});
		//Populate Product Table Begins
		function ShowProduct() {
			var supplier_code = $(this).data('supplier_code');
			$.ajax({
				url: 'showproduct',
				type: 'POST',
				async: false,
				data: {
					show: 1
				},
				success: function(response) {
					$('#ProductTable').html(response);
					ShowTotal();
				}
			});
		}
		//Populate Product Table Begins
		//Populate Total Table Begins
		function ShowTotal() {
			$.ajax({
				url: 'showtotal',
				type: 'POST',
				async: false,
				data: {
					show: 1
				},
				success: function(response) {
					$('#TotalTable').html(response);
					convertNumberToWords();
				}
			});
		}

		function myFunction() {
			var x = document.getElementById("partno");
			if (x.length == 0) {
				x.value = x.value.toUpperCase();
			}
		}
		//Populate Total Table Ends
		// Convert Number To Words Begins
		function convertNumberToWords() {
			var amount = document.getElementById('total_inv_val').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('rsinwords').value = words_string;
			}
			return words_string;
			document.getElementById('rsinwords').value = words_string;
		}
		// Convert Number To Words Ends
	</Script>
</body>
</html>