<?php 

require_once("config/configDB.php"); 
require "financial_year_calculation.php";
require "userPermission.php";
require "exfDieselProFetchData.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:"exfpickdetails_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 my1()
    {
    var eqty=parseFloat(document.getElementById("eqty").value);
	var rate=parseFloat(document.getElementById("rate").value);
	
	document.getElementById("amount").value=parseFloat(eqty*rate).toFixed(2);
    
    
    
    }
	</script>
    
    <script>

function validateForm() {
  var driverid = document.forms["myForm"]["driverid"].value;
   var supplierid = document.forms["myForm"]["supplierid"].value;
   
   var vehicleid = document.forms["myForm"]["vehicleid"].value;
  
  
  if (driverid == "a") {
    alert("Please Select Driver");
    return false;
  }
  
  if (supplierid == "a") {
    alert("Please Select Supplier");
    return false;
  }
  
   if (vehicleid == "a") {
    alert("Please Select Vehicle");
    return false;
  }
  
  
}
</script>
<style>
	.form-control[readonly]
	{
		background:#B9F5F3
		
	}
	
	</style>
</head>
<body>
  <?php require 'menu.php' ?>
  <div class="container-fluid">
    <h3 class="text-center"><strong>External 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="exfDieselProInsert.php" method="post" id="inDieselProInvoice" onSubmit="return checkForm(this);" autocomplete="off">
      <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 >
        </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>
        </div>
        
       
        
      </div>
      
      <div class="col-sm-12 row">
      <div class=" col-sm-2"><label for="inputlg">Supplier </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="supplierid" required>
            <option value="">Select Bunk</option>
            <?php   echo $sqlSupplierName;   ?>
          </select> 
        </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" required>
           <option value="">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" required>
           <option value="">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">
          
        <input type="text" class="form-control input-lg"  name="inchargename" required>
           
        </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>
        </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>
        </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>
        </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">
       <div class=" col-sm-2"><label class="control-label">Rate</label></div>
        <div class=" col-sm-4 form-group">
         
           <input class="form-control input-lg" type="text" name="rate" id="rate" placeholder="Enter Amount/Ltr"  required  onBlur="my1()">
        </div>
        
        
        
        <div class=" col-sm-2"><label class="control-label">Amount</label></div>
        <div class=" col-sm-4 form-group">
         
           <input class="form-control input-lg" type="text" name="amount" id="amount" placeholder="Enter Amount"  required readonly>
        </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"  required 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 Mileage" required  id="hmileage" readonly>
        </div>
        
       
        
      </div>
      
      <div class="col-sm-12 row">
        
         <div class=" col-sm-2"><label class="control-label">Payment </label></div>
        <div class="col-sm-4 form-group">
          
       <select class="form-control input-lg " name="payment" required>
        <option value="">Please Select the Option </option>
       <option value="Cash And Carry">Cash And Carry</option>
       <option value="Accounts">Accounts</option>
       
        </select>
        </div>
        
        <div class=" col-sm-2"><label class="control-label">Paid&nbsp;Amt</label></div>
        <div class="col-sm-4 form-group">
          
      <input class="form-control input-lg" type="text" name="received_amt"  >
        </div>
        
      </div>
      
      
      <div class="col-sm-12 row">
      
      <div class=" col-sm-2"><label class="control-label">Payment Mode</label></div>
        <div class="col-sm-4 form-group">
          
      <select class="form-control input-lg selectpicker select-payment-type" data-live-search="true" name="paymenttype" id="supplierdetails">
            <option disabled selected>Select your Option</option>
            <option value="cash">Cash</option>
            <option value="cheque">Cheque</option>
            <option value="NEFT">NEFT</option>
          
          </select>  
        </div>
        
         <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" name="myButton" 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>

  var checkForm = function(form) {

    //
    // validate form fields
    //

    form.myButton.disabled = true;
    return true;
  };


</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: {
                    
                }
            }
        }
    });
    

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