<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">  
</head>
	<body>
	<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='http://fonts.googleapis.com/css?family=Open+Sans:400,300,800' rel='stylesheet' type='text/css'-->
<link href="../css/font-awesome.min.css" rel="stylesheet" />
<link href="../css/styleg.css" rel="stylesheet" />
<!--script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script-->
<!--script src="../js/jquery.min.js"></script-->
<script type="text/javascript" src="../js/jquery.placeholder.label.js"></script>
	<style>
		input {
			width: 100%;
			display: block;
			border: 1px solid #ccc;
			padding: 10px;
			outline: none;
			font-size: 16px;	
			border-radius: 30px;
			margin: 2px;
			border-color: #4158d0;
		}
		label {
			color: #4158d0;
		}
		div.inline {
			width: 100%;
			display: table;
		}

		div.inline div {
			display: table-cell;
		}

		div.inline div:nth-child(n+3) {
			padding-left: 10px;
		}
		.flexi{
			display:flex;
			flex-flow:row;
		}
	</style>
	<div style="width: 1920px; margin-left: 0px; margin-right: 0px; margin-top: -0px;">
    	<nav class="navbar navbar-expand-lg navbar-dark bg-primary" style="width: 1920px; 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 : -55px; margin-left : 105px;" type="button" onclick="location.href='invshow';" value="Re Print Invoice">
            <input style = "background-color: #007bff; font-size:24px; width:200px; height : 55px; margin-top : -57px; margin-left : 308px;" type="button" onclick="location.href='../product/index';" value="Add Product">
            <input style = "background-color: #007bff; font-size:24px; width:200px; height : 55px; margin-top : -57px; margin-left : 510px;" type="button" onclick="location.href='../supplier/index';" value="Add Supplier">
            <h1 style="color:white; font-size:24px; margin-top: -40px;" class="text-primary" align="center">Purchase</h1>
            <h1 style="color:white; font-size:24px; margin-top : -40px;margin-right :20px;" class="text-primary" id="demo2" align="right"></h1>
        </nav>
    </div>
		<form method="post" id="insert_form">
		<div style="width: 1920px; margin-left: 12px; margin-right: 0px; margin-top: -10px;" class="flexi">
			<div >
				<label style="width: 400px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="customer_name"><b>Customer_Name</b><span class="required"></span></label>
				<input type="text" style="width: 400px; height: 40px; margin-left: 5px; margin-right: 0px; margin-top: -3px;" id="customer_name" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required autofocus/>
			</div>
			<div>
				<label style="width: 150px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="customer_code"><b>Customer_Code</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 5px; margin-right: 0px; margin-top: -3px;" id="customer_code" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 140px; height: 0px; margin-left:10px; margin-right: 0px; margin-top: 0px;" for="cust_place"><b>Cust_Place</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="cust_place" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 140px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="cust_gstno"><b>Cust_Gstno</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="cust_gstno" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 140px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="tax_code"><b>Tax_Code</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="tax_code" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 140px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="transporter_name"><b>Transporter_Name</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="transporter_name" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 160px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="srno"><b>Invoice_No</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="srno" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
				<span id="availability"></span>
				<input type="hidden" name="inv_number" id="inv_number"/>
			</div>
			<div>
				<label style="width: 170px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="invdt"><b>Inv_Dt</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="invdt" placeholder="" ="this.value = this.value.toUpperCase()" autocomplete="off" required/>
				<input type="hidden" name="invdt1" class="form-control inputstl" id="invdt1" style = "font-size:14px; 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>
		<div style="width: 1920px; margin-left: 8px; margin-right: 0px; margin-top: 10px;" class="flexi">			
			<div >
				<label style="width: 190px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="challan_no"><b>Challn_No</b><span class="required"></span></label>
				<input type="text" style="width: 190px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="challan_no" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 200px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="challan_date"><b>Challn_Dt</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="challan_date" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 200px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="po_no"><b>Po_No</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="po_no" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 200px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="po_date"><b>Po_Date</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="po_date" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 200px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="lr_no"><b>Lr_No</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="lr_no" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 200px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="lr_dt"><b>Lr_Dt</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="lr_dt" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 200px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="no_of_parcel"><b>No_of_Boxes</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="no_of_parcel" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 200px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="opening"><b>Opening_Balance</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="opening" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 200px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="debit"><b>Debit_Balance</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="debit" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
		</div>
		<div style="width: 1920px; margin-left: 8px; margin-right: 0px; margin-top: 10px;" class="flexi">			
			<div >
				<label style="width: 190px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="credit"><b>Credit_Balance</b><span class="required"></span></label>
				<input type="text" style="width: 190px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="credit" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 200px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="clbalance"><b>Closing_Balance</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="clbalance" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
			<div>
				<label style="width: 200px; height: 0px; margin-left: 10px; margin-right: 0px; margin-top: 0px;" for="rsinwords"><b>Rupees_In_Words</b><span class="required"></span></label>
				<input type="text" style="width: 200px; height: 40px; margin-left: 10px; margin-right: 0px; margin-top: -3px;" id="rsinwords" placeholder="" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required/>
			</div>
		</div>
		</form>
	</body>
</html>
<?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();		
		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>