<?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 externalpro_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');
$sname    = $row['sname'];
$vhid    = $row['vehicleid'];
$vehicleno    = $row['vehicleno'];
$driverid    = $row['driverid'];
$drivername    = $row['drivername'];
$litres       = $row['litres'];
$intakekm     = $row['intakekm'];
$intakehrs   =$row['intakehrs'];
$amount=$row['amount'];
$rate=$row['rate'];

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

$sid=$row['supplierid'];



$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>
    function my()
    {
    var eqty=parseFloat(document.getElementById("eqty").value);
	var rate=parseFloat(document.getElementById("rate").value);
	
	document.getElementById("amount").value=parseFloat(eqty*rate).toFixed(2);
    
    
    
    }
	</script>
</head>
<body>
  <?php require 'menu.php' ?>
  <div class="container-fluid">
    <h3 class="text-center"><strong>Edit Internal Production Diesel Details</strong></h3>
    <form class="form-horizontal" action="exDieselProUpdate.php" method="post" id="inDieselProInvoice">
      <div class="col-sm-12 row">
      <div class=" col-sm-1"></div>
        <div class=" col-sm-3 form-group">
          <label class="control-label">S.No</label>
          <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-3 form-group">
          <label class="control-label">Date</label>
          <input class="form-control input-lg datepicker-internalprodate"  type="text" name="internalprodate" autocomplete="off" value="<?php echo $internalprodate; ?>"  readonly>
        </div>
        
        <div class="col-sm-3 form-group">
          <label class="control-label">Supplier</label>
          <select class="form-control input-lg datepicker-internalprodate"  type="text" name=sname><option value="<?php echo $sid; ?>"><?php echo $sname; ?></option>
          
          <?php
		  $sl=mysqli_query($conn,"SELECT *  FROM supplier_master WHERE isdelete=1 and stype='Diesel'");
		  while($rw=mysqli_fetch_array($sl))
		  {
			  
		  ?>
          <option value="<?php echo $rw['id']; ?>"><?php echo $rw['sname']; ?></option>
          <?php
		  }
		  ?>
          </select>
        </div>
        
        <div class=" col-sm-3 form-group">
          <label class="control-label">Vehicle No</label>
          <select class="form-control input-lg selectpicker select-trip-vehicle" data-show-subtext="true" data-live-search="true" name="vhid">
             <option value="<?php echo $vhid ?>"><?php echo $vehicleno ?></option>
            <?php   while($prow = mysqli_fetch_array($sqlVehicleQuery)) { 
             
              ?>
                <option value="<?php echo $prow['id'] ?>"  > <?php echo $prow['vehicleno']; ?> </option>
            <?php  
            }    ?>
          </select> 
        </div>
       
        
      </div>

      <div class=" col-sm-12 row"><br></div>
      <div class=" col-sm-12 row">
        <div class=" col-sm-1"></div>
        
        <div class="col-sm-2 form-group">
          <label class="control-label">Driver Name</label>
           <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 form-group">
          <label class="control-label">Odometer (KM)</label>
          <input class="form-control input-lg" type="text" name="intakekm" placeholder="Enter odometers" value="<?php echo $intakekm; ?>"  >
        </div>
        <div class="col-sm-2 form-group">
          <label class="control-label">Odometer(Hours)</label>
          <input class="form-control input-lg intakehrs" type="text" name="intakehrs" placeholder="Enter odometers"  value="<?php echo $intakehrs; ?>" >
        </div>
        <div class="col-sm-2 form-group">
          <label class="control-label">Litres</label>
          <input class="form-control input-lg" type="text" name="eqty" placeholder="Enter Diesel Quality" value="<?php echo $litres; ?>" id="eqty" >
        </div>
         <div class="col-sm-2 form-group">
          <label class="control-label">Rate</label>
          <input class="form-control input-lg" type="text" name="rate" id="rate" placeholder="Enter Rate"  required onBlur="my()" value="<?php echo $rate; ?>">
        </div>
       
        <div class="col-sm-2 form-group">
          <label class="control-label">Amount</label>
          <input class="form-control input-lg" type="text" name="amount" placeholder="Enter Diesel Quality" value="<?php echo $amount; ?>"  id="amount">
        </div>
       
      </div>
      
      <div class=" col-sm-12 row">
        <div class=" col-sm-1"></div>

        
        <div class="form-group col-sm-3">
          
           <label class="control-label">Payment </label>
            <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="form-group col-sm-3">
          <label class="control-label">Paid&nbsp;Amt</label>
          <input class="form-control input-lg" type="text" name="received_amt" value="<?php echo $received_amt; ?>"  >
        </div>
        
        <div class="form-group col-sm-3">
          <label class="control-label">Payment&nbsp;Mode</label>
          <select class="form-control input-lg selectpicker select-payment-type" data-live-search="true" name="paymenttype" id="supplierdetails">
            <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>
      
      <div class=" col-sm-12 row">
        <div class=" col-sm-1"></div>

        
        <div class="form-group col-sm-9">
          
          <label class="control-label">Remarks</label>
            <textarea class="form-control input-lg " name="remark" ><?php echo $remark; ?></textarea>
       
          
        </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: {
                    
                }
            }
        }
    });
    

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