<?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">Fuel</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>

								Fuel

							</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 -->



						<div class="row">

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

                            

								<!-- PAGE CONTENT BEGINS -->





<script src="assets/js/jquery.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.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://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>

	

jQuery(function($){

		   

	// simple jQuery validation script

	$('#course').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:13px;color:#FF0000; padding-left:3px;" class="'+ errorcn +'">'+ msg +'</span>')

					.appendTo(parent)

					.fadeIn('fast')

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

				valid = false;

			};

		});

		

		return valid;

		

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

		

	});

	

});	



</script>   

								

										

                                        

<?php



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

{



$id=$_GET['id'];



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

{



$id=$_POST['id'];



$date=$_POST['date'];



$invoiceno = $_POST['invoiceno'];



$vehicleno = $_POST['vehicleno'];



$startingkm=$_POST['startingkm'];



$closingkm=$_POST['closingkm'];



$driver=$_POST['driver'];



$phone=$_POST['phone'];



// now we insert it into the database



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



if($invoiceno)

{ 



$in= "update delivery set date='$date',invoiceno='$invoiceno',vehicleno='$vehicleno',startkm='$startingkm',endkm='$closingkm',driver='$driver',phone='$phone' where ID='$id'";



$in1 = mysqli_query($conn,$in) or die(mysqli_error($conn));



if($in1)

{



 header("location:viewdelivery.php?s=1");



}



}



else

{



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



}





}



else

{



$ex=mysqli_query($conn,"select * from fuel where ID='".$id."'");

$ex1=mysqli_fetch_assoc($ex);



echo'<form id="course" action="viewdelivery.php?id='.$id.'" method="post">



<input type="hidden" name="id" value="'.$id.'" />



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



<tr><td>Date</td><td></td><td><input class="form-control" style="width: 30ch; margin-bottom:10px" type="text" name="date" class="datepicker" id="datepicker" title="*" value="'.date('d-m-Y',strtotime($ex1['date'])).'" autocomplete="off" /required></td></tr>



<tr><td>Vehicle No. <span class="red"></span></td><td></td><td><select class="form-control" style="width: 30ch; margin-bottom:10px" name="vehicleno" id="required" title="*" style="width:220px;"><option value="">Select Vehicle No</option>';



$sel=mysqli_query($conn,"select * from transport order by ID asc");

while($sel1=mysqli_fetch_assoc($sel))

{



$svno="<option value='".$sel1['vehicleno']."'>".$sel1['vehicleno']."</option>";

$svno=str_replace("<option value='".$sel1['vehicleno']."'","<option value='".$sel1['vehicleno']."' selected",$svno);

echo $svno;

	

}



echo'</select></td></tr>



<tr><td>Filling Km <span class="red"></span></td><td></td><td><input class="form-control" style="width: 30ch; margin-bottom:10px" autocomplete="off" type="text" name="fillingkm" id="required" title="*" value="'.$ex1['fillingkm'].'" autocomplete="off" /></td></tr>



<tr><td>Qty <span class="red"></span></td><td></td><td><input class="form-control" style="width: 30ch; margin-bottom:10px" autocomplete="off" type="text" name="qty" id="required" title="*" value="'.$ex1['qty'].'" autocomplete="off" /></td></tr>



<tr><td>Filled By <span class="red"></span></td><td></td><td><input class="form-control" style="width: 30ch; margin-bottom:10px" autocomplete="off" type="text" name="filledby" id="required" title="*" value="'.$ex1['filledby'].'" autocomplete="off" /></td></tr>



<tr><td colspan="3" style="text-align:center; padding-top:7px; "><button style="margin-left: -160px;" type="submit" name="submit" class="btn btn btn-primary">Submit</button></td></tr>



</table>



</form>';



}



}



else

	{

		

	

		

		

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

	{

	 $status=$_GET['s'];

		

		 if($status=='1')

		 {

			 echo'<div class="alert alert-block alert-success">

									<button type="button" class="close" data-dismiss="alert">

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

									</button>

						Values Edited Successfully.

				  </div>';				  

		 }

		 if($status=='7')

		 {

			 echo'<div class="alert alert-block alert-success">

									<button type="button" class="close" data-dismiss="alert">

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

									</button>

						Values Deleted Successfully.

				  </div>';				  

		 }

	}		





echo'<table style="width:99%; margin:11px auto 10px auto;">

                                        

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

                                        <a href="fuel.php"><button class="btn btn-minier btn-info">+ Add Fuel</button></a>

                                        </td>

                                        

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

                                        

                                        <td style="width:30%;">

                                        

                                        </td>

                                        

                                        </tr>

                                        

                                        </table>';



	echo"<table id='dynamic-table' class='table table-striped table-bordered table-hover'>



	<thead><th style='width:7%;'>S.No</th><th style='width:12%;'>Date</th><th style='width:10%;'>Vehicle No.</th>

	<th style='width:10%;'>Filling Km</th><th style='width:10%;'>Qty</th><th style='width:12%;'>Filled By</th><th style='width:10%;'>Edit</th></thead>";



	$getsite3="select * from fuel order by ID asc";

	$getsite4=mysqli_query($conn,$getsite3) or die("Could not get");

	$sno=0;

	while($getsite5=mysqli_fetch_assoc($getsite4))

	{

		$sno=$sno+1;

		

		echo"<tr><td>".$sno."</td><td>".date('d-m-Y',strtotime($getsite5['date']))."</td><td>".$getsite5['vehicleno']."</td>

		<td>".$getsite5['fillingkm']."</td><td>".$getsite5['qty']."</td><td>".$getsite5['filledby']."</td><td>

		

														<div class='hidden-sm hidden-xs btn-group'>";

																

															if($gtp1['type']!='staff')

															{

															echo"<a href='viewfuel.php?id=".$getsite5['ID']."' title='Edit'>

																<i class='ace-icon fa fa-pencil bigger-100 green'></i></a>";

															}

															

														 echo"</div>					  

		</td></tr>";



		}



		echo "</table>";



	}



?>



                                            

                                            							



										<!-- 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();

?>