<?php 
require_once("config/configDB.php"); 
require "financial_year_calculation.php";
require "userPermission.php";
require "piDieselInvoiceFetchData.php";

$edit_id  =  $_GET['id'];

$sql = mysqli_query($conn,"SELECT * FROM purchase_dieselinvoice WHERE id='$edit_id' ");
 
$row=mysqli_fetch_array($sql,MYSQLI_ASSOC);

$dieselinvoice   = $row['dieselinvoice'];
$tdate_temp     = new DateTime(stripslashes($row['dieseldate']));
$dieseldate 		  = $tdate_temp->format('d-m-Y');
$supplierid    = $row['supplierid'];
$supplierinvoice    = $row['supplierinvoice'];
$amount = $row['amount'];
$vehicleno   = $row['vehicleno'];
$litres   = $row['litres'];
$rate1   = $row['rate1'];


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

$sqlSupplierQuery = mysqli_query($conn,"SELECT id, sname   FROM supplier_master WHERE isdelete=1 and stype='Diesel' ");

?>
<!DOCTYPE html>
<html>
<head>
    <?php 
      require 'meta.php'; 
      require 'header.php'; 
    ?>
    
    <script>
 function my()
  {
	  
	  var liter=parseFloat(document.getElementById("liters1").value);
	 var rate=parseFloat(document.getElementById("rate1").value);
	 
	  
	  document.getElementById("amount").value=parseFloat(liter*rate).toFixed(2);
	  
  }


</script>
</head>
<body>
  <?php require 'menu.php' ?>
  <div class="container-fluid">
    <h3 class="text-center"><strong>Edit Diesel Invoice Details</strong></h3>
    <form class="form-horizontal" action="piDieselInvoiceUpdate.php" method="post" id="piDieselInvoice">
      <div class="col-sm-12 row">
        <div class=" col-sm-1"></div>

        <div class="form-group col-sm-3">
          <label class="control-label">S.No</label>
          <input class="form-control input-lg" type="text" name="dieselinvoice" value="<?php echo $dieselinvoice; ?>" readonly >
          <input type="hidden" value=<?php echo $edit_id; ?> name="edit_id">
        </div>
        
        <div class="form-group col-sm-3">
          <label class="control-label">Date</label>
          <input class="form-control input-lg datepicker-invoicedate"  type="text" name="invoicedate" value="<?php echo $dieseldate; ?>">
        </div>
        
        <div class="form-group col-sm-3">
          <label class="control-label">Available Stock </label>
          <input class="form-control input-lg available-stock" type="text" value="<?php echo $AStock; ?>" readonly>
        </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">Bunk Name </label>
          <select class="form-control input-lg selectpicker select-trip-vehicle" data-show-subtext="true" data-live-search="true" name="supplierdetails">
            <option disabled selected>Please Select Bunk</option>
            <?php   //echo $sqlSupplierName;   ?>
            
            <?php   while($prow = mysqli_fetch_array($sqlSupplierQuery)) { ?>
                <option value="<?php echo $prow['id'] ?>" <?php if( $prow['id']  == $supplierid ): ?> selected="selected"<?php endif; ?> > <?php echo $prow['sname']; ?> </option>
            <?php  }  ?>
          </select> 
        </div>
        
        <div class="form-group col-sm-3">
          <label class="control-label">Supplier Invoice No</label>
          <input class="form-control input-lg" type="text" name="supplierinvoice_no" placeholder="Supplier Invoice Number" value="<?php echo $supplierinvoice; ?>">
        </div>
        <div class="form-group col-sm-3">
          <label class="control-label">Vehicle No(Tanker)</label>
          <input class="form-control input-lg " type="text" name="vehicleno" placeholder="Litres" value="<?php echo $vehicleno; ?>" />
        </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">Litres</label>
          <input class="form-control input-lg litres" type="text" name="litres" id="liters1" placeholder="Litres" value="<?php echo $litres; ?>" onBlur="my()"/>
        </div>


<div class="form-group col-sm-3">
          <label class="control-label">Rate(Per Ltr)</label>
          <input class="form-control input-lg" type="text" name="rate1" id="rate1" placeholder="Purchase rate" required onBlur="my()" value="<?php echo $rate1; ?>">
        </div>

        <div class="form-group col-sm-3">
          <label class="control-label">Invoice Amount</label>
          <input class="form-control input-lg" type="text" name="amount" id="amount" placeholder="Purchase Amount" value="<?php echo $amount; ?>" readonly>
        </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="form-group">        
      <div class="col-sm-12 text-center">
        <button type="submit" class="btn btn-default btn-lg">Update</button>
      </div>
    </div>
    </form>   
  </div>
  <?php require 'footer.php' ?>
 
  <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
  
  <script type="text/javascript" src="piDieselInvoiceScript.js"></script>
<script>
	$(document).ready(function(){
  

        //$('input[name="invoicedate"]').datepicker( "setDate", new Date()); 
       // alert('Incase change the Amount & Litres in Purchase Invoice required for Admin Approval');

    var date_input=$('input[name="invoicedate"]'); //our date input has the name "date"
	  var container=$('form >  .datepicker-invoicedate').length>0 ? $('form > .datepicker-invoicedate').parent() : "body";
	  date_input.datepicker({ format: 'dd-mm-yyyy',container: container,todayHighlight: false,autoclose: true  });
    
    

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