<?php 

require_once("config/configDB.php"); 
require "financial_year_calculation.php";
require "userPermission.php";
require "inDieselProFetchData.php";

$edit_id  =  $_GET['id'];

$sql = mysqli_query($conn,"SELECT * FROM internalpro_diesel WHERE id='$edit_id' ");
 
$row=mysqli_fetch_array($sql,MYSQLI_ASSOC);

$invoice   = $row['invoice'];
//$tdate_temp     = new DateTime(stripslashes($row['dieseldate']));
//$internalprodate 		  = $tdate_temp->format('d-m-Y');
$internalprodate 		  =$row['dieseldate'];
$vehicleid    = $row['vehicleid'];
$vehicleno       = $row['vehicleno'];
$driverid     = $row['driverid'];
$drivername   =$row['drivername'];

$inchargeid    = $row['inchargeid'];
$inchargename       = $row['inchargename'];
$previouskms     = $row['previouskms'];
$previoushrs   =$row['previoushrs'];

$preiousqty    = $row['preiousqty'];
$intakekm       = $row['intakekm'];
$intakehrs     = $row['intakehrs'];
$litres   =$row['litres'];
$mileage    = $row['mileage'];
$hmileage    = $row['hmileage'];
$remarks       = $row['remarks'];




$sqlVehicleQuery = mysqli_query($conn,"SELECT id, vehicleno  FROM vehicle_master WHERE isdelete=1  ");

?>
<!DOCTYPE html>
<html>
<head>
    <?php 
      require 'meta.php'; 
      require 'header.php'; 
	  
    ?>
    <style>
	.form-control[readonly]
	{
		background:#B9F5F3
		
	}
	
	</style>
    
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){ 
$('#vehicleid').change(function(){  
//alert("ji");
	  var query=$(this).val();
	 
	             $.ajax({  
                     url:"pickdetails_diesel.php",  
                     method:"POST",  
                     data:{query:query},
                     success:function(data)  
                     {  
					      //alert(data);
						  var data2 = data.split("||");
                          $('#previouskms').val("");  
                          $('#previouskms').val(data2[0]);
						  $('#previoushrs').val("");  
                          $('#previoushrs').val(data2[1]);
						  
						  $('#preiousqty').val("");  
                          $('#preiousqty').val(data2[2]);
						  
                         
                         
                     }  
                });  
      }); 
}); 

function my()
{
var cqty=parseFloat(document.getElementById("eqty").value);

var previouskms=parseFloat(document.getElementById("previouskms").value);

var intakekm=parseFloat(document.getElementById("intakekm").value);
	
	document.getElementById("mileage").value=parseFloat((intakekm-previouskms)/cqty).toFixed(2);
	
}

function my2()
{
	
	var cqty1=parseFloat(document.getElementById("eqty").value);
var previoushrs=parseFloat(document.getElementById("previoushrs").value);

var intakehrs=parseFloat(document.getElementById("intakehrs").value);
	
	
	
	document.getElementById("hmileage").value=parseFloat((intakehrs-previoushrs)/cqty1).toFixed(2);	
}
</script>
</head>
<body>
  <?php require 'menu.php' ?>
  <div class="container-fluid">
    <h3 class="text-center"><strong>Edit Internal  Diesel Filling Details</strong></h3>
    <form class="form-horizontal" action="inDieselProUpdate.php" method="post" id="inDieselProInvoice">
      <div class="col-sm-12 row">
      <div class=" col-sm-2"><label class="control-label">S.No</label></div>
        <div class=" col-sm-4 form-group">
         
          <input class="form-control input-lg" type="text" name="invoice" value="<?php echo $invoice; ?>" readonly >
        </div>
        
        
        
         <div class=" col-sm-2"><label class="control-label">Date</label></div>
        <div class="col-sm-4 form-group">
          
          <input class="form-control input-lg datepicker-internalprodate"  type="text" name="internalprodate" autocomplete="off" readonly value="<?php echo $internalprodate; ?>">
        </div>
        
       
        
      </div>
      
      <div class="col-sm-12 row">
      <div class=" col-sm-2"><label for="inputlg">Stock </label></div>
        <div class=" col-sm-4 form-group">
         
          <input class="form-control input-lg" type="text" value="<?php echo number_format($AStock,2,'.',''); ?>" readonly>
        </div>
        
        
        
         <div class=" col-sm-2"><label class="control-label">Vehicle No/Equipment No</label></div>
        <div class="col-sm-4 form-group">
          
          <select class="form-control input-lg selectpicker select-trip-vehicle" data-show-subtext="true" data-live-search="true" name="vehicleid" id="vehicleid">
           <option value="<?php echo $vehicleid; ?>"><?php echo $vehicleno;?></option>
            <?php   echo $sqlVehicleNo;   ?>
          </select> 
        </div>
        
       
        
      </div>
      
      
      
      <div class="col-sm-12 row">
      <div class=" col-sm-2"> <label class="control-label">Driver/Operator Name</label></div>
        <div class=" col-sm-4 form-group">
         
          <select class="form-control input-lg selectpicker select-trip-vehicle" data-show-subtext="true" data-live-search="true" name="driverid">
           <option value="<?php echo $driverid; ?>"><?php echo $drivername;?></option>
            <?php   echo $sqldrivername;   ?>
          </select>
        </div>
        
        
        
         <div class=" col-sm-2"><label class="control-label">Incharge Name</label></div>
        <div class="col-sm-4 form-group">
          
        <select class="form-control input-lg selectpicker select-trip-vehicle" data-show-subtext="true" data-live-search="true" name="inchargeid">
           <option value="<?php echo $inchargeid; ?>"><?php echo $inchargename; ?></option>
            <?php   echo $sqlinchargename;   ?>
          </select>
        </div>
        
       
        
      </div>
      
      <div class="col-sm-12 row">
      <div class=" col-sm-2"><label class="control-label">Opening Kms</label></div>
        <div class=" col-sm-4 form-group">
         
          <input class="form-control input-lg" type="text" name="previouskms" id="previouskms"  required value="<?php echo $previouskms; ?>" onBlur="my()" readonly>
        </div>
        
        
        
         <div class=" col-sm-2"><label class="control-label">Opening Hrs</label></div>
        <div class="col-sm-4 form-group">
          
       <input class="form-control input-lg odometerhours" type="text" name="previoushrs" placeholder="Enter odometers" required  id="previoushrs" value="<?php echo $previoushrs; ?>" onBlur="my2()" readonly>
        </div>
        
       
        
      </div>
      
      
      <div class="col-sm-12 row">
      <div class=" col-sm-2"><label class="control-label">Previous Fill qty</label></div>
        <div class=" col-sm-4 form-group">
         
           <input class="form-control input-lg" type="text" name="preiousqty" placeholder="Enter Diesel Quality"  required id="preiousqty" value="<?php echo $preiousqty; ?>" readonly>
        </div>
        
        
        
         <div class=" col-sm-2"><label class="control-label">Closing Kms</label></div>
        <div class="col-sm-4 form-group">
          
       <input class="form-control input-lg odometerkm"  type="text" name="intakekm" placeholder="Enter odometers" required value="<?php echo $intakekm; ?>" id="intakekm" onBlur="my()">
        </div>
        
       
        
      </div>
      
      
      <div class="col-sm-12 row">
      <div class=" col-sm-2"><label class="control-label">Closing Hrs</label></div>
        <div class=" col-sm-4 form-group">
         
           <input class="form-control input-lg odometerhours" type="text" name="intakehrs" placeholder="Enter odometers" required value="<?php echo $intakehrs; ?>" id="intakehrs" onBlur="my2()">
        </div>
        
        
        
         <div class=" col-sm-2"><label class="control-label">Current Filling Qty</label></div>
        <div class="col-sm-4 form-group">
          
      <input class="form-control input-lg odometerhours" type="text" name="eqty" placeholder="Enter Qty" required value="<?php echo $litres; ?>" id="eqty" onBlur="my();my2()">
        </div>
        
       
        
      </div>

      <div class="col-sm-12 row" style="display:none;">
      <div class=" col-sm-2"><label class="control-label">Mileage</label></div>
        <div class=" col-sm-4 form-group">
         
           <input class="form-control input-lg" type="text" name="mileage" placeholder="Enter Diesel Quality"  required value="<?php echo $mileage; ?>" id="mileage" readonly >
        </div>
        
        
        
         <div class=" col-sm-2"><label class="control-label">Mileage For Hrs</label></div>
        <div class="col-sm-4 form-group">
          
      <input class="form-control input-lg odometerhours" type="text" name="hmileage" placeholder="Enter Qty" required value="<?php echo $hmileage; ?>" id="hmileage" readonly>
        </div>
        
       
        
      </div>
      
      
      <div class="col-sm-12 row">
           
        
        
         <div class=" col-sm-2"><label class="control-label">Remarks</label></div>
        <div class="col-sm-4 form-group">
          
      <input class="form-control input-lg odometerhours" type="text" name="remarks" placeholder="Enter Qty"  value="<?php echo $remarks; ?>">
        </div>
        
       
        
      </div>
      
      
      
      <div class=" col-sm-12 row"><br></div>

    <div class="form-group">        
      <div class="col-sm-12 text-center">
        <button type="submit" class="btn btn-default btn-lg">Save</button>
      </div>
    </div>
    </form>   
  </div>
  <?php require 'footer.php' ?>
 
  <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
  
  <script type="text/javascript" src="inDieselProScript.js"></script>
<script>
	$(document).ready(function(){
	   var date_input=$('input[name="internalprodate"]'); //our date input has the name "date"
	var container=$('form >  .datepicker-delivery_date').length>0 ? $('form > .datepicker-delivery_date').parent() : "body";
	date_input.datepicker({ format: 'yyyy-mm-dd',container: container,todayHighlight: true,autoclose: true  });
    //$('input[name="internalprodate"]').datepicker( "setDate", new Date());      
    $('#inDieselProInvoice').bootstrapValidator({
        // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
          invoice: {
                message: 'The invoice number is not valid',
                validators: {
                    notEmpty: {
                        message: 'The invoice number is required and cannot be empty'
                    }
                }
            },
           
          vehicleno: {
                message: 'The vehicle number is not valid',
                validators: {
                    notEmpty: {
                        message: 'The vehicle number is required and cannot be empty'
                    }
                }
            },
            eqty: {
                message: 'The litres is not valid',
                validators: {
                    notEmpty: {
                        message: 'The litres is required and cannot be empty'
                    },
                    
                }
            },
            odometer: {
                message: 'The odometer is not valid',
                validators: {
                    regexp: {
                        regexp: /^[0-9]+$/,
                        message: 'The supplier invoice amount can only consist of number'
                    }
                }
            }
        }
    });
    

	});
</script>
</body>
</html>