<?php 

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

$vehicleid  =  $_GET['id'];

$sqlBrandtypeQuery = mysqli_query($conn,"SELECT DISTINCT brand_type FROM brand_master WHERE brand_type LIKE 'equipment' OR brand_type LIKE 'transport' and isdelete=1 ");

$sqlBrandnameQuery = mysqli_query($conn,"SELECT DISTINCT brand_name,id FROM brand_master WHERE brand_type LIKE 'equipment' OR brand_type LIKE 'transport' and isdelete=1 ");


$sql = mysqli_query($conn,"select * FROM vehicle_master WHERE id='$vehicleid' ");
 
$row=mysqli_fetch_array($sql,MYSQLI_ASSOC);

$vehicleno  = $row['vehicleno'];
$brandtype  = $row['brandtype'];
$brandname  = $row['brandname'];
$model      = $row['model'];
$purchasedate= $row['purchasedate'];
$openingkm= $row['openingkm']; 
$openinghrs=$row['openinghrs'];
$vehicletype= $row['vehicletype'];
$vownership= $row['vownership'];
$regname= $row['regname'];
$reg_address= $row['reg_address'];
$fastag= $row['fastag'];

$ins_policynumber= $row['ins_policynumber'];
$ins_policyfrom= $row['ins_policyfrom'];
$ins_policyto= $row['ins_policyto'];
$ins_policyremindon= $row['ins_policyremindon'];
$insurancecompany= $row['insurancecompany'];

$fcnumber= $row['fcnumber'];
$fcfrom= $row['fcfrom'];
$fcto= $row['fcto'];
$fcremindon= $row['fcremindon'];
$permitnumber= $row['permitnumber'];
$permitfrom= $row['permitfrom'];
$permitto= $row['permitto'];
$permitremindon= $row['permitremindon'];

$pypermitnumber= $row['pypermitnumber'];
$pypermitfrom= $row['pypermitfrom'];
$pypermitto= $row['pypermitto'];
$pypermitremindon= $row['pypermitremindon'];

$taxnumber= $row['taxnumber'];
$taxfrom= $row['taxfrom'];
$taxto= $row['taxto'];
$taxremindon= $row['taxremindon'];

$pytaxnumber= $row['pytaxnumber'];
$pytaxfrom= $row['pytaxfrom'];
$pytaxto= $row['pytaxto'];
$pytaxremindon= $row['pytaxremindon'];

$companymileage=$row['companymileage'];
$loannumber= $row['loannumber']; 
$loanfrom= $row['loanfrom'];
$loanto= $row['loanto'];
$loanremindon= $row['loanremindon'];
$loan_financier= $row['loan_financier']; 
$loan_amt= $row['loan_amt'];
$loan_interest= $row['loan_interest'];
$loan_tenure= $row['loan_tenure'];
$loan_emiamt= $row['loan_emiamt'];

?>
<!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(){ 
$('#regname').change(function(){  
//alert("ji");
	  var query=$(this).val();
	 
	             $.ajax({  
                     url:"pickregaddress.php",  
                     method:"POST",  
                     data:{query:query},
                     success:function(data)  
                     {  
					      //alert(data);
						  var data2 = data.split("||");
                          $('#reg_address').val("");  
                          $('#reg_address').val(data2[0]);
						  
                         
                         
                     }  
                });  
      }); 
}); 
</script>
</head>
<body>
    <?php require 'menu.php' ?>
<div class="container-fluid col-sm-12 col-xs-12">
<h2 class="text-center">Vehicle Details</h2><br>
    <form class="form-horizontal" action="vehicleMasterUpdate.php" method="post" id="vehicleMasterForm">
      
      <div class=" col-sm-12 row">
        <div class=" col-sm-2"></div>  
        <div class="col-sm-4 col-xs-12 form-group">
          <label class="control-label" >vehicle No</label>
          <input type="text" class="form-control input-lg" placeholder="Enter vehicle Number" name="vehicleno" autocomplete="off" required value="<?php echo $vehicleno; ?>">  
          <input type="hidden" value=<?php echo $vehicleid; ?> name="edit_id">
        </div>
        <div class="col-sm-4 col-xs-12 form-group">
          <label class="control-label" >Brand Type</label>
          <select class="form-control input-lg selectpicker brandtype_select " data-live-search="true" name="brandtype">
          <option disabled selected>Please select your option </option>
          <?php  while($prow = mysqli_fetch_array($sqlBrandtypeQuery))  {  ?>
            <option value="<?php echo $prow['brand_type'] ?>" <?php if( $prow['brand_type']  == $brandtype ): ?> selected="selected"<?php endif; ?> > <?php echo $prow['brand_type']; ?> </option>
          <?php  }  ?>
          </select> 
        </div>
      </div>

      <div class=" col-sm-12 row">
        <div class=" col-sm-2"></div>  
        <div class="col-sm-4 col-xs-12 form-group">
          <label class="control-label" >Brand Name</label>
          <select class="form-control input-lg brandname_select selectpicker" data-live-search="true" name="brandname" id="brandname_select">
            <option disabled selected>Please select your option </option>
            <?php  
            $sqlBrandnameQuery = mysqli_query($conn,"SELECT DISTINCT brand_name,id FROM brand_master WHERE brand_type LIKE '$brandtype'  and isdelete=1 ");
            while($prow = mysqli_fetch_array($sqlBrandnameQuery))  {  ?>
            <option value="<?php echo $prow['id'] ?>" <?php if( $prow['id']  == $brandname ): ?> selected="selected"<?php endif; ?> > <?php echo $prow['brand_name']; ?> </option>
            <?php  }  ?>
            
          </select>
        </div>
        <div class="col-sm-4 col-xs-12 form-group">
          <label class="control-label" >Model</label>
          <input type="text" class="form-control input-lg" placeholder="Enter Model" name="model" value="<?php echo $model; ?>" autocomplete="off">
        </div>
      </div>
     
      <div class=" col-sm-12 row">
        <div class=" col-sm-2"></div>  
        <div class="col-sm-4 col-xs-12 form-group">
          <label class="control-label" >Purchase Date</label>
          <input type="text" class="form-control input-lg datepicker-purchase" placeholder="Enter Purchase Date" name="purchasedate" autocomplete="off" value="<?php echo $purchasedate; ?>">
        </div>
        <div class="col-sm-4 col-xs-12 form-group">
          <label class="control-label" >Opening KM</label>
          <input type="text" class="form-control input-lg" placeholder="Enter Model" name="openingkm" autocomplete="off" value="<?php echo $openingkm; ?>">
        </div>
      </div>

      <div class=" col-sm-12 row">
        <div class=" col-sm-2"></div>  
        <div class="col-sm-4 col-xs-12 form-group">
          <label class="control-label" >Vehicle Type</label>
          <select class="form-control input-lg vehicletype_select selectpicker" data-live-search="true" name="vehicletype">
            <option disabled selected>Please select your option</option>
            <option value="new" <?php if( $vehicletype == "new" ): ?> selected="selected"<?php endif; ?> >New</option>
            <option value="used" <?php if( $vehicletype == "used" ): ?> selected="selected"<?php endif; ?> >Used</option>
          </select>
        </div>
        <div class="col-sm-4 col-xs-12 form-group">
          <label class="control-label" >Ownership</label>
          <select class="form-control input-lg ownership_select selectpicker" data-live-search="true" name="ownership">
              <option disabled selected>Please select your option</option>
              <option value="owned"  <?php if( $vownership == "owned" ): ?> selected="selected"<?php endif; ?> >Owned</option>
              <option value="leased" <?php if( $vownership == "leased" ): ?> selected="selected"<?php endif; ?> >Leased</option>
          </select>
        </div>
      </div>
      
      <div class=" col-sm-12 row">
        <div class=" col-sm-2"></div>  
        <div class="col-sm-4 col-xs-12 form-group">
        <label class="control-label" >Reg Name</label>
         <select class="form-control input-lg ownership_select selectpicker" data-live-search="true" name="regname" id="regname">
              <option  selected><?php echo $regname;?></option>
              <?php echo $sqlregname;?>
          </select>
        </div>
        <div class="col-sm-4 col-xs-12 form-group">
          <label class="control-label" >Reg Address</label>
          <input type="text"  class="form-control input-lg" placeholder="Enter Address" name="reg_address" id="reg_address" autocomplete="off" required value="<?php echo $reg_address;?>">
        </div>
      </div>
      
      
<div class=" col-sm-12 row">
        <div class=" col-sm-2"></div>  
        
        <div class="col-sm-4 col-xs-12 form-group">
          <label class="control-label" >Opening Hrs</label>
          <input type="text" class="form-control input-lg" placeholder="Enter Hours" name="openinghrs" autocomplete="off"  value="<?php echo $openinghrs; ?>">
         
        </div> 
        
        <div class="col-sm-4 col-xs-12 form-group">
          <label class="control-label" >Company Assured</label>
          <input type="text" class="form-control input-lg" placeholder="Enter Mileage" name="companymileage" autocomplete="off"  value="<?php echo $companymileage; ?>">
        </div>   
        
        
      </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="vehicleMasterScript.js"></script>

<script>
	$(document).ready(function(){   
  
  
  
  });
</script>
</body>
</html>