<!DOCTYPE html>
<?php
require_once('../Db/dbconfig.php');
@$name=$_GET['username'];
?>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.4/css/jquery.dataTables.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://kit.fontawesome.com/c17eae44a3.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script>
<style type="text/css">
@media only screen and (max-height: 700px) {
	.child{
	  width:1000px;
	  float:left;
	  font-size:15px;
	  font-family:arial;
	  padding:10px;
	  cursor: pointer;
	}
}
select.rou{
 border: 1px solid #ccc;
  -moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;

-moz-box-shadow: 2px 2px 3px #666;
-webkit-box-shadow: 2px 2px 3px #666;
box-shadow: 2px 2px 3px #666;
font-size: 18px;
padding: 4px 7px;
outline: 0;
-webkit-appearance: none;
}
#round{
 border: 1px solid #ccc;
 -moz-border-radius: 10px;
 -webkit-border-radius: 10px;
 border-radius: 10px;
	
 -moz-box-shadow: 2px 2px 3px #666;
 -webkit-box-shadow: 2px 2px 3px #666;
 box-shadow: 2px 2px 3px #666;
 font-size: 15px;
 padding: 4px 7px;
 outline: 0;
 -webkit-appearance: none;
}
</style>
</head>
<body>
<div class="card">
	<div class="page-header">
      <h3 class="page-title"  >
        <span class="page-title-icon bg-gradient-primary text-white mr-2">
        <i class="far fa-chart-bar fa-xs" style="color: black"></i>
        </span><b>Reports</b></h3>
	</div>
	<div class="card-body child" style="overflow: auto;">
		<form id="reportForm">
		<div class="form-group">
    <label style="width:100px;" for="dat"><b>From Date:</b></label>
	
    <input style="width:250px;" class="rounded" type="date" id="frmdat" name="frmdat"  required>
	</div>
	<div class="form-group">
    <label style="width:100px;" for="dat"><b>To Date:</b></label>
	
    <input style="width:250px;" class="rounded" type="date" id="todat" name="todat"  required>
	</div>
	<div class="form-group">
	  <label class="radio-inline">
    <input type="radio" name="optradio" value="1" checked>&nbsp;Department Wise
    </label>
    <label class="radio-inline">
    <input type="radio" name="optradio" value="0" >&nbsp;Item Category Wise
    </label>        
	</div>
	<div class="form-group" id="dptDiv">
	      <label style="width:100px;" for="no"><b>Department:</b></label>
	      <select style="width:170px;" id="dpt" name="dpt" class="rou" required>
	        <?php 
	        
					$sql1="select * from department where id in (1,2,5)";
					
					$res=mysqli_query($con,$sql1);
				while($row1 = mysqli_fetch_array($res))
				{
		        	
			?>
			<option value="<?php echo $row1['id']; ?>"><?php echo $row1['depart']; ?></option> 
			<?php
	        	
				}
			?>
			<option value="pur">Purchase</option> 
			<option value="export">Export</option> 
	        </select>
			        
		</div>
		<div class="form-group" style="display: none;" id="itemcatDiv">
	      <label style="width:100px;" for="no"><b>Item Category:</b></label>
	      <select style="width:170px;" id="itemcat" name="itemcat" class="rou">
	        <?php 
	        
					$sql1="select * from product";
					
					$res=mysqli_query($con,$sql1);
				while($row1 = mysqli_fetch_array($res))
				{
		        	
			?>
			<option value="<?php echo $row1['id']; ?>"><?php echo $row1['item']; ?></option> 
			<?php
	        	
				}
			?>
			</select>
			<button type="button" class="btn btn-primary" style="display: none" id="othrdept" data-toggle="tooltip" data-placement="bottom" title="Add Other Department" ><i class="ace-icon fa fa-plus bigger-130"></i></button>
        
		</div>
		<div class="form-group">
	      <label style="width:100px;" for="no"><b>Report Type:</b></label>
	      <select style="width:70px;" id="filetype" class="rou" required>
	      <option value="1">Pdf</option> 
				<option value="2">Excel</option> 
			   </select>
			<button type="button" class="btn btn-primary" style="display: none" id="othrdept" data-toggle="tooltip" data-placement="bottom" title="Add Other Department" ><i class="ace-icon fa fa-plus bigger-130"></i></button>
        
		</div>
		<button type="submit" name="reportBtn" id="reportBtn" class="p-1 mb-1 bg-primary text-white rounded">Submit</button>
	</form>
	</div>
</div>

</body>

<script type="text/javascript">
	var table;
	$(document).ready(function(){
	
	$("#reportForm").submit(function(e) {
		//prevent Default functionality
    e.preventDefault();

    console.log('dpt',$('#dpt').val());
    var radioval = $('input[type=radio][name=optradio]:checked').val();
    
    if(radioval == '1'){
	    //do your own request an handle the results
	    if($('#filetype').val() == '1'){
	   	 window.open('../controller/pdfgenerator.php?itemcat=0&dptId='+$('#dpt').val()+'&frmdt='+$('#frmdat').val()+'&todt='+$('#todat').val(),'_blank');   	
	   	}else{
	   		window.open('../controller/xlgenerator.php?itemcat=0&dptId='+$('#dpt').val()+'&frmdt='+$('#frmdat').val()+'&todt='+$('#todat').val(),'_blank');   	
	   	}
   	}else{
   		if($('#filetype').val() == '1'){
	   	 window.open('../controller/pdfgenerator.php?dptId=0&frmdt='+$('#frmdat').val()+'&todt='+$('#todat').val()+'&itemcat='+$('#itemcat').val(),'_blank');   	
	   	}else{
	   		window.open('../controller/xlgenerator.php?dptId=0&frmdt='+$('#frmdat').val()+'&todt='+$('#todat').val()+'&itemcat='+$('#itemcat').val(),'_blank');   	
	   	}
   	}

	});

	$('input[type=radio][name=optradio]').change(function() {
	    if (this.value == '1') {
	        document.getElementById('dptDiv').style.display ="block";
	        document.getElementById('dpt').required =true;
	        document.getElementById('itemcatDiv').style.display ="none";
	        document.getElementById('itemcat').required =false;
	    }
	    else if (this.value == '0') {
	        document.getElementById('itemcatDiv').style.display ="block";
	        document.getElementById('itemcat').required =true;
	        document.getElementById('dptDiv').style.display ="none";
	        document.getElementById('dpt').required =false;
	    }
	});
		
});


</script>
</html>
