<?php 

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

$edit_id  =  $_GET['id'];

$sql = mysqli_query($conn,"SELECT * FROM externalfill_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('Y-m-d');

$supplierid    = $row['supplierid'];
$sname    = $row['sname'];

$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'];
$rate   =$row['rate'];
$amount   =$row['amount'];

$mileage    = $row['mileage'];
$hmileage    = $row['hmileage'];
$remarks       = $row['remarks'];

$payment         = $row['payment'];
	   $received_amt         = $row['received_amt'];
	    $paymenttype         = $row['paymenttype'];


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

?>
<!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);
	
	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);	
}

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>

<style>
	.form-control[readonly]
	{
		background:#B9F5F3
		
	}
	
	</style>
</head>
<body>
  <?php require 'menu.php' ?>
  <div class="container-fluid">
    <h3 class="text-center"><strong>Edit External Filled Diesel Details</strong></h3>
    <form class="form-horizontal" action="exfDieselProUpdate.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 >
          <input type="hidden" name="edit_id" value="<?php echo $edit_id;?>">
        </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-"  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">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">
            <option value="<?php echo $supplierid; ?>"><?php echo $sname; ?></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">
           <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">
          
         <input type="text" class="form-control input-lg"  name="inchargename" value="<?php echo $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 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">
       <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 Diesel Mileage"  required  onBlur="my1()" value="<?php echo $rate;?>">
        </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 Diesel Mileage"  required readonly value="<?php echo $amount;?>">
        </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">
        </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="<?php echo $payment; ?>"><?php echo $payment; ?></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" value="<?php echo $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" >
            <option value="<?php echo $paymenttype; ?>"><?php echo $paymenttype; ?></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 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'
                    }
                }
            },
            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>