<?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";
    //$width = '2000';
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');
}
?>
<html>
<head>
	<title>Order</title>
</head>
<script type="text/javascript">
	function preventBack() {
		window.history.forward();
	}
	setTimeout("preventBack()", 0);
	window.onunload = function() {
		null
	};
</script>
<title>Order</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>
<style>
    label {
        font-size: 15px;
        top: 11px;
        margin-bottom: .5rem;
        margin-left: 5px;
        font-weight:bold;
        display: inline-transparent;
    }
</style>
<style>
    tr{cursor: pointer; transition: all .25s ease-in-out}
    .selected{background-color: red; font-weight: bold; color: blue;}
</style>
    <body style="min-width: <?php echo $width; ?>; width: auto;">
        <div style="min-width: <?php echo $width; ?>; width: auto;">
        <form method="POST" action="update">
            <nav class="navbar navbar-expand-lg navbar-dark bg-primary" style="min-width: <?php echo $width; ?>; width: auto; margin-top: -20px; 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='showorder';" value="Print Order">
                <h1 style="color:white; font-size:24px; margin-top: -40px;" class="text-primary" align="center">Supplier Order</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-left: 0px; margin-top: -20px;">
        	<center>
			<tr>
			    <?php
			        $curr_month = date('m');
			        if($curr_month >= 4 && $curr_month <= 12){
                		$year = date('y') . '-' . date('y', strtotime("+1 year"));
                	} else{
                		$year = date("y",strtotime("-1 year")) . '-' . date("y");
                	}
    			    $query1 = mysqli_query($connect, "select srno from control_mst  where description = '" ."ORDER". "'") or die(mysqli_error());
    				while($fetch1 = mysqli_fetch_array($query1)){
    				$order_number = 'ORD- '.$fetch1['srno'].'  '.'('.$year.')';
				    $srno = $fetch1['srno']; 
        			?>
			        <div class="col-xs-2">
    					<label style="font-size:18px;" class=" col-sm-2 control-label">order_number</label>
    					<input type="text" id="order_number1" class="roundedCategory" style="font-size:18px; width:100%; height: 40px; font-weight:bold; color: #000066;" value="<?php echo $order_number?>" onfocus="GetCustCode(this)" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
    					<input type="hidden" name="order_number" id="order_number" value="<?php echo $order_number?>" />
    					<input type="hidden" name="srno" id="srno" value="<?php echo $srno?>" />
    				</div>
    				<div class="col-xs-2">
    					<label style="font-size:18px;" class=" col-sm-2 control-label">order_date</label>
    					<input type="text" id="order_date" name="order_date" class="roundedCategory" style="font-size:18px; margin-top: -0px; width:100%; height: 40px; 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>
    				</div>
        			<?php
    				}
    			?>
    				<div class="col-xs-3">
    					<label style="font-size:18px;" class=" col-sm-2 control-label">supplier_name</label>
    					<input type="text" id="supplier_name" name="supplier_name" class="roundedCategory" style="font-size:18px; width:100%; height: 40px; font-weight:bold; color: #000066;" value="" onfocus="GetCustCode(this)" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
    				</div>
    				<div class="col-xs-1">
    					<label style="font-size:18px;" class=" col-sm-2 control-label">supplier_code</label>
    					<input type="text" id="supplier_code" name="supplier_code" class="roundedCategory" style="font-size:18px; width:100%; height: 40px; font-weight:bold; color: #000066;" value="" onfocus="GetCustCode(this)" 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">supplier_place</label>
    					<input type="text" id="supplier_place" name="supplier_place" class="roundedCategory" style="font-size:18px; width:100%; height: 40px; font-weight:bold; color: #000066;" value="" onfocus="GetCustCode(this)" 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">supplier_gstno</label>
    					<input type="text" id="supplier_gstno" name="supplier_gstno" class="roundedCategory" style="font-size:18px; width:100%; height: 40px; font-weight:bold; color: #000066;" value="" onfocus="GetCustCode(this)" oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
    				</div>
			</tr>
		    </center>
		    <br><br><br><br>
            	<center>
                	<div class="table-responsive" style="min-width: <?php echo $width; ?>; width: auto; margin-left : 0px; overflow:auto; height: 60%;">
                	<table id="myTable" style="font-size:18px; min-width: <?php echo $width; ?>; width: auto;">
                		<tr>
                			<th style = "text-align: left">partno</th>
                        	<th style = "text-align: left">description_one</th>
                        	<th style = "text-align: right">list</th>
                        	<th style = "text-align: right">stk_qty</th>
                        	<th style = "text-align: right">ly_sales</th>
                        	<th style = "text-align: right">cy_sales</th>
                        	<th style = "text-align: right">pending</th>
                        	<th style = "text-align: right">dispatch1</th>
                        	<th style = "text-align: right">moq</th>
                        	<th style = "text-align: right">order_qty</th>
                        	<th style = "text-align: right">boxqty</th>
                        	<th style = "text-align: right">disc_per</th>
                        	<th style = "text-align: right">disc_amt</th>
                        	<th style = "text-align: right">cost</th>
                        	<th style = "text-align: left">segment</th>
                        	<th style = "text-align: left">hsn_code</th>
                		</tr>
                		<tbody>
                			<?php
                			$query = mysqli_query($connect, "select * from item_mst order by partno ASC") or die(mysqli_error());
    						while($fetch = mysqli_fetch_array($query)){
    					?>
    					<tr>
    					    <input type="hidden" value="<?php echo $fetch['partno']?>" name="mem_id[]">
    					    <td style = "width:150px; text-align: left"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: left"  readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: left" value="<?php echo $fetch['partno']?>" name="partno[]" class='partno'/></td>
                        	<td style = "width:300px; text-align: left"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: left" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: left" value="<?php echo $fetch['description_one']?>" name="description_one[]" class='description_one'/></td>
                        	<td style = "width:70px; text-align: right"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: right" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: right" value="<?php echo $fetch['list']?>" name="list[]" class='list'/></td>
                        	<td style = "width:70px; text-align: right"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: right" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: right" value="<?php echo $fetch['stk_qty']?>" name="stk_qty[]" class='stk_qty'/></td>
                        	<td style = "width:70px; text-align: right"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: right" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: right" value="<?php echo $fetch['ly_sales']?>" name="ly_sales[]" class='ly_sales'/></td>
                        	<td style = "width:70px; text-align: right"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: right" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: right" value="<?php echo $fetch['cy_sales']?>" name="cy_sales[]" class='cy_sales'/></td>
                        	<td style = "width:70px; text-align: right"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: right" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: right" value="<?php echo $fetch['pending']?>" name="pending[]" class='pending'/></td>
                        	<td style = "width:70px; text-align: right"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: right" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: right" value="<?php echo $fetch['dispatch1']?>" name="dispatch1[]" class='dispatch1'/></td>
                        	<td style = "width:70px; text-align: right"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: right" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: right" value="<?php echo $fetch['moq']?>" name="moq[]" class='moq'/></td>
                        	<td style = "width:70px; text-align: right"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: right" onfocus="myFunction(this.id)" type="text" onkeypress="return isNumberKey(this, event);" autocomplete="off" style="font-size:18px; font-weight:bold; text-align: right" value="<?php echo ''?>" name="order_qty[]" class='order_qty'/></td>
                        	<td style = "width:70px; text-align: right"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: right" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: right" value="<?php echo $fetch['boxqty']?>" name="boxqty[]" class='boxqty'/></td>
                        	<td style = "width:70px; text-align: right"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: right" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: right" value="<?php echo $fetch['disc_per']?>" name="disc_per[]" class='disc_per'/></td>
                        	<td style = "width:70px; text-align: right"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: right" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: right" value="<?php echo $fetch['disc_amt']?>" name="disc_amt[]" class='disc_amt'/></td>
                        	<td style = "width:70px; text-align: right"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: right" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: right" value="<?php echo $fetch['cost']?>" name="cost[]" class='cost'/></td>
                        	<td style = "width:150px; text-align: left"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: left" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: left" value="<?php echo $fetch['segment']?>" name="segment[]" class='segment'/></td>
                        	<td style = "width:150px; text-align: left"><input style = "width:100%; font-size:15px; font-weight:bold; text-align: left" readonly onfocus="this.select();" type="text" autocomplete="off" tabindex="-1" style="font-size:18px; font-weight:bold; text-align: left" value="<?php echo $fetch['hsn_code']?>" name="hsn_code[]" class='hsn_code'/></td>
    					</tr>
    					<?php
    						}
    					?>
                		</tbody>
                	</table>
                	</div>
                	<br>
                	<td><button style="width: 150px; height: 40px;" type="submit" class="btn btn-primary" id="submit">Save</button></td>
            	</center>
        	</div>
        </form>
        </div>
    </body>
</html>
<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>
    function selectedRow(){
        var index,
        table = document.getElementById("myTable");
        for(var i = 1; i < table.rows.length; i++)
        {
            table.rows[i].oninput = function()
            {
                 // remove the background from the previous selected row
                if(typeof index !== "undefined"){
                   table.rows[index].classList.toggle("selected");
                }
                console.log(typeof index);
                // get the selected row index
                index = this.rowIndex;
                // add class selected to the row
                this.classList.toggle("selected");
                console.log(typeof index);
            };
            table.rows[i].onclick = function()
            {
                 // remove the background from the previous selected row
                if(typeof index !== "undefined"){
                   table.rows[index].classList.toggle("selected");
                }
                console.log(typeof index);
                // get the selected row index
                index = this.rowIndex;
                // add class selected to the row
                this.classList.toggle("selected");
                console.log(typeof index);
            };
        }
    }
    selectedRow();
</script>
<script>
	$(document).ready(function() {
	    $(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);//label
				    $('#supplier_code').val(ui.item.value);//supplier_place
				    $('#supplier_place').val(ui.item.supplier_place);//
				    $('#supplier_gstno').val(ui.item.supplier_gstno);//supplier_place
					document.getElementById("supplier_place").focus();
					return false;
				}
			});
		});
	});
</script>
<script>
$(document).keydown(function(objEvent) {
	if (objEvent.keyCode == 13) {
		objEvent.preventDefault();
	}
})
</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>
