<?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 invoice, dieseldate,vehicleid,vehicleno,driverid,drivername,litres,intakekm,intakehrs FROM internalunfillpro_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');
$vehicleno    = $row['vehicleid'];
$litres       = $row['litres'];
$odometerkm     = $row['intakekm'];
$odometerhours   =$row['intakehrs'];

$driverid     = $row['driverid'];
$drivername   =$row['drivername'];



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

?>
<!DOCTYPE html>
<html>
<head>
    <?php 
      require 'meta.php'; 
      require 'header.php'; 
    ?>
</head>
<body>
  <?php require 'menu.php' ?>
  <div class="container-fluid">
    <h3 class="text-center"><strong>Edit Internal Unfill Diesel Details</strong></h3>
    <form class="form-horizontal" action="inDieselunfillProUpdate.php" method="post" id="inDieselProInvoice">
      <div class=" col-sm-12 row"><br></div>
    
      <div class="col-sm-12 row">
      <div class=" col-sm-2"><label class="control-label">S.No</label></div>
        <div class=" col-sm-3 form-group">
          
           <input class="form-control input-lg" type="text" name="invoice" value="<?php echo $invoice; ?>" readonly >
          <input type="hidden" value=<?php echo $edit_id; ?> name="edit_id">
        </div>
        <div class=" col-sm-2"> <label class="control-label">Date</label></div>
        <div class="col-sm-3 form-group">
        <input class="form-control input-lg datepicker-internalprodate"  type="text" name="internalprodate" autocomplete="off" value="<?php echo $internalprodate; ?>"  readonly>
        
         </div>
        </div>
        
         <div class="col-sm-12 row">
          <div class=" col-sm-2"> <label class="control-label">Stock</label></div>
        <div class="col-sm-3 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</label></div>
       <div class=" col-sm-3 form-group">
         
          <select class="form-control input-lg selectpicker select-trip-vehicle" data-show-subtext="true" data-live-search="true" name="vehicleno">
            <option disabled selected>Please Select Vehicle</option>
            <?php   while($prow = mysqli_fetch_array($sqlVehicleQuery)) { 
              if($vehicleno==$prow['id']) {  
              ?>
                <option value="<?php echo $prow['id'] ?>" <?php if( $prow['id']  == $vehicleno ): ?> selected="selected"<?php endif; ?> > <?php echo $prow['vehicleno']; ?> </option>
            <?php  
            }   } ?>
             <?php   echo $sqlVehicleNo;   ?>
          </select>
        </div>
        
      </div>
      
      <div class="col-sm-12 row">
          
        <div class=" col-sm-2"><label class="control-label">Driver Name</label></div>
       <div class=" col-sm-3 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">Odometer(KM)</label></div>
        <div class="col-sm-3 form-group">
          
         <input class="form-control input-lg" type="text" name="odometerkm" placeholder="Enter odometers" value="<?php echo $odometerkm; ?>"  >
        </div>
      </div>
      
      <div class="col-sm-12 row">
          
        <div class=" col-sm-2"><label class="control-label">Odometer(Hours)</label></div>
       <div class=" col-sm-3 form-group">
         
          <input class="form-control input-lg odometerhours" type="text" name="odometerhours" placeholder="Enter odometers"  value="<?php echo $odometerhours; ?>" >
        </div>
        
        <div class=" col-sm-2"> <label class="control-label">Litres</label></div>
        <div class="col-sm-3 form-group">
          
        <input class="form-control input-lg" type="text" name="eqty" placeholder="Enter Diesel Quality" value="<?php echo $litres; ?>" >
        </div>
      </div>

      <div class=" col-sm-12 row"><br></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'
                    },
                   
                }
            },
            
        }
    });
    

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