<?PHP

ob_start();

session_start();

include 'connect.php';

if(isset($_SESSION['adminemail']))

{

$user=$_SESSION['adminemail'];



$gtp=mysqli_query($conn,"select * from admin where username='$user'");

$gtp1=mysqli_fetch_assoc($gtp);



include 'top.php';

?>






<div id="page-wrapper" >
          <div id="page-inner">
<div class="main-content">

				<div class="main-content-inner">

					<div class="breadcrumbs ace-save-state" id="breadcrumbs">

						<ul class="breadcrumb">

							<li>

								<i class="ace-icon fa fa-home home-icon"></i>

								<a href="#">Home</a>

							</li>

							<li class="active">Advance Voucher</li>

						</ul><!-- /.breadcrumb -->

					</div>



					<div class="page-content">			



						<div class="page-header">



<?php



$aca=mysqli_query($conn,"select * from financial where user='$user' order by ID desc");

$aca1=mysqli_fetch_assoc($aca);



$financial=$aca1['financial'];



?>                        

                        

							<table style="width:100%;">

                        

                        <tr><td style="width:50%;">

                        

							<h1>

								Advance Voucher

							</h1>

                            

                            </td>

                            

                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">

                            

                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $financial; ?>

                            

                            </td></tr></table>

                            

						</div><!-- /.page-header -->

<br />



						<div class="row">

							<div class="col-xs-12">

                            

								<!-- PAGE CONTENT BEGINS -->

                                

<script src="assets/js/jquery.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css">
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
  <script>
    $(function() {
      // Initialize the datepicker
      $("#datepicker").datepicker({
        format: "mm/dd/yyyy",
        autoclose: true,
        todayHighlight: true
      });

      // Adjust the positioning of the datepicker dropdown
      $("#datepicker").on("show", function(e) {
        var inputOffset = $(this).offset();
        var inputHeight = $(this).outerHeight();
        var datepickerDropdown = $(".datepicker-dropdown");

        datepickerDropdown.css({
          top: inputOffset.top + inputHeight + 10,
          left: inputOffset.left
        });
      });
    });
  </script>
<script type='text/javascript'>

$(document).ready(function() {



$(".year").change(function(){

var employee=$('.employee').val();

var month=$('.month').val();

var year=$('.year').val();

var dataString = 'empid='+ employee +'&month='+ month +'&year='+ year;

 //alert(dataString);

    $.ajax

({

type: "GET",

url: "getsal.php",

data: dataString,

cache: false,

success: function( html )

{

	//alert(html);

	var bal=$(html).filter('#bal').text();

	var bal1=$(html).filter('#bal1').text();

	var salary=$(html).filter('#salary').text();

	var advance=$(html).filter('#advance').text();

	

	$('.salary').val(salary);

	$('.advance').val(advance);

	$('.balance').val(bal);

	$('.bal1').val(bal1);

		

}

});

});	



});



</script>



<script>

	

jQuery(function($){

		   

	// simple jQuery validation script

	$('#register').submit(function(){

		

		var valid = true;

		var errormsg = 'This field is required!';

		var errorcn = 'error';

		

		$('.' + errorcn, this).remove();			

		

		$('#required', this).each(function(){

			var parent = $(this).parent();

			if( $(this).val() == '' ){

				var msg = $(this).attr('title');

				msg = (msg != '') ? msg : errormsg;

				$('<span style="font-size:11px;color:#ff0000;" class="'+ errorcn +'">'+ msg +'</span>')

					.appendTo(parent)

					.fadeIn('fast')

					.click(function(){ $(this).remove(); });

				valid = false;

			};

		});

		

		var amt=$('.amount').val()*1;

		var amnt=$('.bal1').val()*1;

		

		if(amt>amnt)

		{

		alert('Enter Amount Between 0 to '+amnt);

		valid = false;

		}

		

		

		return valid;

		

		$('button:submit').prop('disabled', true);

		

	});

	

});	



</script>

        

<?php        





if (isset($_POST['submit'])) { 



$id=$_POST['id'];

$date=$_POST['date'];

$employee=$_POST['employee'];

$amount=$_POST['amount'];

$remarks=$_POST['remarks'];

$month=$_POST['month'];

$year=$_POST['year'];



$date=date('Y-m-d',strtotime($date));



$in=mysqli_query($conn,"insert into advance(ID,date,empid,amount,remarks,month,year) values('$id','$date','$employee','$amount','$remarks','$month','$year')");



if($in)

{

header("location:viewadvance.php?id=".$id."&s=1");

}

else

{

header("location:advance.php?s=2");

}



}



 else

 {	



	if(isset($_GET['s']))

	{

		

	 $status=$_GET['s'];

	 

		 if($status=='1')

		 {

           echo'<div class="alert alert-success alert-dismissable" style="width:80%; margin:auto;">

                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

                <span style="text-align:left;">Values Added Successfully.</span>

                </div><br />';

		}

		elseif($status=='2')

		 {

           echo'<div class="alert alert-error alert-dismissable" style="width:80%; margin:auto;">

                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

                <span style="text-align:left;">Values not inserted.</span>

                </div><br />';

		}

		

	}





$get=mysqli_query($conn,"select MAX(ID) as ID from advance");

$get1=mysqli_fetch_assoc($get);

$newid=$get1['ID']+1;



?>



<form id="register" action="advance.php" method="post">



<table width="70%" style="margin:auto; line-height:35px;">



<tr><td width="32%">Date <span class="red"></span></td><td width="11"></td><td>



<input  type="hidden" name="id" value="<?php echo $newid; ?>" />



<input class="form-control" style="width:30ch; margin-bottom:10px;" autocomplete="off" type="text"  name="date" id="datepicker" title="Enter Date" value="<?php echo date('d-m-Y'); ?>" /required></td></tr>



<tr><td width="32%">Employee <span class="red"></span></td><td width="11"></td><td><select  class="form-control" style="width:30ch; margin-bottom:10px;" name="employee" style="width:220px;" class="employee" id="required" title="Select Employee" style="text-transform:uppercase;"><option value="">Select Employee</option>



<?php



$em=mysqli_query($conn,"select * from employee where status='' order by ID asc");

while($em1=mysqli_fetch_assoc($em))

{



echo"<option value='".$em1['empid']."'>".$em1['name']."</option>";



}



?>



</select></td></tr>



<tr><td width="32%">Month <span class="red"></span></td><td width="11"></td><td><select class="form-control" style="width:30ch; margin-bottom:10px;" name="month" style="width:220px;" class="month" id="required" title="Select Month" style="text-transform:uppercase;"><option value="">Select Month</option>

<option value="01">January</option><option value="02">February</option><option value="03">March</option>

<option value="04">April</option><option value="05">May</option><option value="06">June</option>

<option value="07">July</option><option value="08">August</option><option value="09">September</option>

<option value="10">October</option><option value="11">November</option><option value="12">December</option>

</select></td></tr>



<tr><td width="32%">Year <span class="red"></span></td><td width="11"></td><td><select class="form-control" style="width:30ch; margin-bottom:10px;" name="year" style="width:220px;" class="year" id="required" title="Select Year" style="text-transform:uppercase;"><option value="">Select Year</option>



<?php



$sy=2020;

$ey=date("Y");



while($sy<=$ey)

{

	

	echo"<option value='".$sy."'>".$sy."</option>";

	

	$sy=$sy+1;

	

}



?>



</select></td></tr>



<tr><td width="32%">Salary <span class="red"></span></td><td width="11"></td><td><input class="form-control" style="width:30ch; margin-bottom:10px;" autocomplete="off" type="text" class="salary" name="salary" readonly="true" /></td></tr>



<tr><td width="32%">Advance <span class="red"></span></td><td width="11"></td><td><input class="form-control" style="width:30ch; margin-bottom:10px;" autocomplete="off" type="text" class="advance" name="advance" readonly="true" /></td></tr>



<tr><td width="32%">Balance <span class="red"></span></td><td width="11"></td><td>

<input type="hidden" class="bal1" name="bal1" />

<input class="form-control" style="width:30ch; margin-bottom:10px;" autocomplete="off" type="text" class="balance" name="balance" readonly="true" /></td></tr>



<tr><td width="32%">Amount <span class="red"></span></td><td width="11"></td><td><input class="form-control" style="width:30ch; margin-bottom:10px;" autocomplete="off" type="text" class="amount" name="amount" id="required" title="Enter Amount" /></td></tr>



<tr><td width="32%">Remarks <span class="red"></span></td><td width="11"></td><td><textarea class="form-control" style="width:30ch; margin-bottom:10px; height:75px;" name="remarks" style="width:220px; "></textarea></td></tr>



</table>



<center><button type="submit" value="submit" name="submit" class="btn btn btn-primary">Submit</button></center>



 </form>



 <?php



 }



 ?> 



								<!-- PAGE CONTENT ENDS -->

							</div><!-- /.col -->

						</div><!-- /.row -->

					



</div><!-- /.page-content -->

				</div>

			</div><!-- /.main-content -->
			</div><!-- /.main-content -->
			</div><!-- /.main-content -->





<?php



include 'bottom.php';

}

else

{



 header("location:login.php");

}



ob_flush();



?>