<?php 

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

?>
<!DOCTYPE html>
<html>
<head>
    <?php 
      require 'meta.php'; 
      require 'header.php'; 
    ?>
    <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);

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

var intakehrs=parseFloat(document.getElementById("intakehrs").value);
	
	document.getElementById("mileage").value=parseFloat((intakekm-previouskms)/cqty).toFixed(2);
	
	document.getElementById("hmileage").value=parseFloat((intakehrs-previoushrs)/cqty).toFixed(2);
	
}
</script>

<script>

function validateForm() {
  var driverid = document.forms["myForm"]["driverid"].value;
   var inchargeid = document.forms["myForm"]["inchargeid"].value;
  
  
  if (driverid == "a") {
    alert("Please Select Driver");
    return false;
  }
  
  if (inchargeid == "a") {
    alert("Please Select Incharge");
    return false;
  }
  
  
}
</script>
</head>
<body>
  <?php require 'menu.php' ?>
  <div class="container-fluid">
    <h3 class="text-center"><strong>Internal  Diesel Filling Details</strong></h3>
    <div class=" col-sm-12 row"><br></div>
    <div class=" col-sm-12 row"><br></div>
    <form class="form-horizontal" action="inDieselProInsert.php" method="post" id="inDieselProInvoice" onSubmit="return validateForm()" name="myForm">
      <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_count; ?>" readonly style="background:#B9F5F3  ;">
        </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 style="background:#B9F5F3  ;">
        </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 style="background:#B9F5F3  ;">
        </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 disabled selected value="a">Please Select Vehicle</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" id="driverid">
           <option disabled selected>Please Select Driver</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" id="inchargeid">
           <option disabled selected value="a">Please Select Incharge</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 readonly style="background:#B9F5F3  ;">
        </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" readonly style="background:#B9F5F3  ;">
        </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" readonly style="background:#B9F5F3  ;">
        </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" id="intakekm" placeholder="Enter odometers" required>
        </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" id="intakehrs" placeholder="Enter odometers" required >
        </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  id="eqty" onBlur="my()">
        </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" id="mileage" placeholder="Enter Diesel Mileage"  readonly style="background:#B9F5F3  ;" >
        </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 Mileage" required  id="hmileage" readonly  style="background:#B9F5F3  ;">
        </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 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-internalprodate').length>0 ? $('form > .datepicker-internalprodate').parent() : "body";
		date_input.datepicker({
			  format: 'dd-mm-yyyy',
        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'
                    }
                }
            },
            internalprodate: {
                message: 'The invoice date is not valid',
                validators: {
                    notEmpty: {
                        message: 'The invoice date 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>