<?php
if(basename($_SERVER['PHP_SELF']) == 'scrap.php') 
  $nv=" class='current'";
include'header.php';
$custo='';
$pr=0;


    
		
	if(isset($_POST['back']))
		{
			$custo=$_POST['custo'];
			$code=$_POST['code'];
			$fna=$_POST['fna'];
$doi=mysqli_query($conn, "UPDATE `vehicles` SET `Loading`='1', `Bulk`='0', `Custo`='', `Locate`='', `Gara`='1' WHERE `Number`='$code' ORDER BY `Number` ASC LIMIT 1");
		}
		
	if(isset($_POST['delo']))
		{
			$custo=$_POST['custo'];
			$code=$_POST['code'];
			$fna=$_POST['fna'];
$doi=mysqli_query($conn, "UPDATE `vehicles` SET `Gara`='0' WHERE `Number`='$code' ORDER BY `Number` ASC LIMIT 1");
		}
		
		
	if(isset($_POST['savall']))
		{
	    $lokete=str_replace("'", "`", $_POST['lokete']);
			
			for($t=1; $t<=$_POST['a']; $t++){
			$pla=$_POST["plate$t"];
			$fna=$_POST["fna$t"];
	if($pla){
$doi=mysqli_query($conn, "UPDATE `vehicles` SET `Locate`='', `Custo`='', `Gdate`='$Date', `Gara`='2', `Status`='1' WHERE `Number`='$pla' ORDER BY `Number` ASC LIMIT 1");

	$tgd=mysqli_query($conn, "INSERT INTO `trage` (`Date`, `Time`, `User`, `Plate`, `Action`, `Descri`) VALUES ('$Date', '$Time', '$loge', '$fna', '$addo', 'Added vehicle to scrapped')");	
	
	$seco=mysqli_query($conn, "UPDATE `trips` SET `Offload`='1' WHERE `Vehicle`='$pla' AND `Offload`='0'");
		    }
		        }
		}
		
?>


<script>
$(document).ready(function() {
$('input[type="checkbox"]').change(function(){
var total_checked=  $("input[type='checkbox']:checked").length 
$("#d1").html("Selected Vehicles: <b> " + total_checked );
});
/////////////
var total_checked=  $("input[type='checkbox']:checked").length 
$("#d1").html("Selected Vehicles: <b> " + total_checked );
///////
});


   function check_uncheck_checkbox(isChecked) {
	if(isChecked) {
		$('input[type="checkbox"]').each(function() { 
			this.checked = true; 
		});
	} else {
		$('input[type="checkbox"]').each(function() {
			this.checked = false;
		});
	}
}	
</script>

<div class="container-fluid main-content">
        <div class="page-title hidden-xs hidden-print">
          <h2 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
         Vehicles
          </h2>
                 </div>
     
        <div class="row">
  <div class="col-lg-2 hidden-print">
   
   <ul class="list-group">

	   <li class="list-group-item">
              <a href="locate.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Allocated Vehicles
                </p>
              </a></li> 
                  
			  <li class="list-group-item">
              <a href="ment.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Repair & Services
                </p>
              </a></li>

    <li class="list-group-item active">
	  <a href="mainsto.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;List of Vehicles
                </p>
              </a></li>
                       
            </ul><br><br>

			<li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="createa.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Create Customers
                </p>
              </a></li>	
              
            <li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="dispatch.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Create Vehicle Trip
                </p>
              </a></li>	
              
            <li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="addinco.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Additional Services
                </p>
              </a></li>	
			 
                <?php
              if($_SESSION['Cpo']){
                  ?>
			  <li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
              <a href="purcha.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Purchase Orders
                </p>
              </a></li>
              <?php
              }
              if($_SESSION['Cpi']){
                  ?>
            <li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="profo.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Create Proforma
                </p>
              </a></li>	
              <?php
              }
              ?>
              
            <li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="payslip.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Payment Vouchers
                </p>
              </a></li>	
              
            <li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="conterepo.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Container Dispatch
                </p>
              </a></li>	
              
            <li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="ddlist.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Mileage Deduction
                </p>
              </a></li>	
  </div>
                    
          <?php
          if($_SESSION['Avt']=='1'){
          // *************** Relocate vehicles **********************
	    echo"<div class='modal fade' id='Modaldis' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true'>
  <div class='modal-dialog' role='document' style='width:70%;'>
  <div class='modal-content'><div class='modal-header text-left'>
        <h5 class='modal-title' id='exampleModalLabel'>VEHICLES IN PARKING 
        <span class='pull-right'>  </span></h5>

      </div><form action='' method='post'>
      <div class='modal-body text-left'><div class='row'>

    <div class='col-md-12 text-left' style='height:380px; overflow-x:auto;'>";
        
        $a=1;
    $dos=mysqli_query($conn, "SELECT `Number`, `Plate`, `Locate`, `Gara` FROM `vehicles` WHERE `Status`='0' AND `Trip`='1' AND `Loading`='1' AND (`Locate`='' OR `Locate`='GARAGE') ORDER BY `Plate` ASC");
		while($ros=mysqli_fetch_assoc($dos)){
			$numb=$ros['Number'];
			$plate=$ros['Plate'];
			$bd=$ros['Locate'];
			if($bd)
			$bor="border:1px solid red;";
			elseif($ros['Gara'])
			$bor="border:1px solid blue;";
			else
			$bor="";
	echo"<label class='btn btn-default active' for='my$a' style='width:110px; $bor' title='$bd' data-toggle='tooltip' data-placement='top'>
	<input type='hidden' name='fna$a' value='$plate'>
          <input id='my$a' type='checkbox' value='$numb' name='plate$a' style='border:0px; height:12px;'> $plate </label>";
                 $a++;
		}
    
    echo"<div class='row'><hr></div>";
    
    
    $dos=mysqli_query($conn, "SELECT `Number`, `Plate`, `Locate`, `Gara` FROM `vehicles` WHERE `Status`='0' AND `Driver`='' ORDER BY `Plate` ASC");
		while($ros=mysqli_fetch_assoc($dos)){
			$numb=$ros['Number'];
			$plate=$ros['Plate'];
			$bd=$ros['Locate'];
			$bor="border:1px solid blue;";
	echo"<label class='btn btn-default active' for='my$a' style='width:110px; $bor' title='$bd' data-toggle='tooltip' data-placement='top'>
	<input type='hidden' name='fna$a' value='$plate'>
          <input id='my$a' type='checkbox' value='$numb' name='plate$a' style='border:0px; height:12px;'> $plate </label>";
                 $a++;
		}
    
    echo"</div></div></div><div class='row'> </div>
	    
	   <input type='hidden' name='a' value='$a'>	
	<div class='modal-header' style='padding-top:15px; height:50px;'>
	
	<div class='col-md-4' style='padding-left:40px;'>
	<input type='checkbox' name='checkall' id='checkall' style='height:22px; width:24px; margin-top:0px;' onClick='check_uncheck_checkbox(this.checked);'> &nbsp; <button type='button' class='btn btn-secondary' id='d1'></button></div>
    
    <div class='col-md-4'>
    <select class='form-control' name='lokete' style='height:30px;' required>
    <option value=''> SELECT ACTION </option>
    <option value='SCRAPPED'> SCRAPPED&JUNKED </option></select></div>
    
        <div class='col-md-4 text-right'>
	<button type='button' class='btn btn-xs btn-danger' data-dismiss='modal' style='width:80px; height:28px;'> CANCEL </button>
        <button type='submit' name='savall' class='btn btn-xs btn-success' style='width:80px; height:28px;'> SAVE </button></div>
        </div></form>
    </div></div>
    </div>";
          }
    ?>
    
        <div class="col-lg-10">
    <div class="row"><div class="col-lg-4" style="margin-left:40px;">
           <div class="col-lg-5 hidden-print"> <button class="btn  btn-warning btn-block" type="button" data-toggle='modal' data-target='#Modaldis'> ADD VEHICLE </button> </div>
           
           <div class="col-lg-7 hidden-print"> </div>
						
        </div>  
           
           
           
           
        <div class="col-lg-7">   
           <div class="col-lg-4"> </div>              
                       
            <div class="col-lg-5 hidden-xs hidden-print"> 
      <input class="form-control"  name="custo" type="text" id="searchu" autofocus="autofocus" disabled>
			</div>                      
                       
                       <div class="col-lg-3 hidden-xs hidden-print">
                        <button class="btn  btn-primary btn-block" type="submit" name="search" disabled><i class="lnr lnr-magnifier"></i> Search</button>
                   
					  </div>
                         
                      
                     
                  
            </form> </div>
             
               
            </div>
             <div class="row">
            <div class="col-lg-12" style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; </span>
             <?php
             if($pr){
                 echo"<span class='pull-right text-right'>
             <a href='#' onclick='return window.print()' class='hidden-print' title='Print' data-toggle='tooltip' data-placement='top'><i class='lnr lnr-printer'></i></a>&nbsp;&nbsp;&nbsp;</span>";
             }
             ?>
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">
               
                                
					<?php
	            $b=1;
            echo"<div class='panel panel-default' style='border:1px solid powderblue;'><div class='panel-heading' style='background-color:powderblue; padding-left:30px; font-weight:bold;'> SCRAPPED/JUNKED VEHICLES </div>";
		
		echo"<div class='panel-body' style='padding:0px;'>
			 <table class='table table-striped table-hover'>     
            <tr role='row'><th class='hidden-xs'> No </th>
                        <th><div align='center'> DATE </th>
                        <th><div align='center'> TRUCK&nbsp;ID </th>
                        <th><div align='center'> TRAILER&nbsp;ID </th>
                       <th><div align='center'> COMING&nbsp;FROM </th>
						 <th><div align='center'> CHASSIS&nbsp;No </th>
					   <th><div align='center'> OFFLOAD </th>
						 <th><div align='center'> TRIPS </th>
						 <th class='hidden-print' width='10px'> # </th>
                     </tr><tbody>";

		
	$do=mysqli_query($conn, "SELECT *FROM `vehicles` WHERE `Status`='1' AND `Locate`='' AND `Gara`='2' ORDER BY `Gdate` ASC LIMIT 450");	
	            $n=1;				$to=0;
		while($ro=mysqli_fetch_assoc($do)){
			$code=$ro['Number'];
			$make=$ro['Make'];
			$mode=$ro['Chassis1'];
			$chassis=$ro['Chassis2'];
			$year=$ro['Year'];
			$gte=$ro['Gdate'];
			if($gte=='0000-00-00')
			    $gte="";
			$off=$ro['Doff'];
			if($off=='0000-00-00')
			    $off="";

			$fuel=$ro['Fuel'];
			$vid=$ro['Plate'];
			$source=$ro['Chassis1'];
			$tre=$ro['Trailer'];
			
	$seti=mysqli_query($conn, "SELECT `Number`, `Location`, `Destination` FROM `trips` WHERE `Vehicle`='$code' AND `Status`='0' ORDER BY `Number` DESC LIMIT 1");
			    $reti=mysqli_fetch_assoc($seti);
			    $trino=$reti['Number'];
			    $deso=$reti['Destination'];
			    $loce=$reti['Location'];
			    
			    
	$ati=mysqli_query($conn, "SELECT `Number` FROM `trips` WHERE `Vehicle`='$code' AND `Status`='0' ORDER BY `Number` DESC");
			    $pcl=mysqli_num_rows($ati);
		        
					$stn="style='padding:0px;'";
					
	if($_SESSION['Cancel']){
	    echo"<div class='modal fade' id='exampleModal$b' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true' style='top:220px;'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content'><div class='modal-header'>
        <h5 class='modal-title' id='exampleModalLabel'>REMOVE CONFIRMATION
        <label class='pull-right'> $vid </label></h5>

      </div>
      <div class='modal-body' style='height:150px;'>
        <h5 style='color:#ff0033'>Are you sure you want to remove this vehicle?</h5><br><form method='post' action=''><input type='hidden' name='code' value='$code'><input type='hidden' name='custo' value='$custo'><input type='hidden' name='fna' value='$vid'>
        
        <div class='col-lg-6 text-center'>
        <button type='submit' name='back' class='btn btn-sm btn-success' style='width:220px;'> BACK IN ACTION </button> </div>
        
        <div class='col-lg-6 text-center'>
        <button type='submit' name='delo' class='btn btn-sm btn-warning' style='width:220px;'> DELETE PERMANENTLY </button> </div>
      </form><br><br><hr></div>
      <div class='modal-footer' style='margin-top:-10px; height:50px; padding-top:5px; border:0px solid blue;'>
        <button type='button' class='btn btn-sm btn-default' data-dismiss='modal' style='width:120px;'> CANCEL </button>
      </div></form>
    </div>
  </div>
</div>";
}
		 
		print("<tr><td class='hidden-xs' $stn><div align='right'>$n&nbsp;&nbsp;</td><td $stn><div align='center'> $gte </td><td $stn><div align='center'> $vid </td>
		<td $stn><div align='center'> $tre </td><td $stn> $deso / $loce </td>
		<td $stn> $source </td><td CLASS='text-center' $stn> $off </td>
			  <td $stn><div align='center'> $pcl </td>
	<td class='hidden-print' align='right' style='width:10px; padding:0px 5px 0px 0px;'><div title='Remove' data-toggle='tooltip' data-placement='top'><button type='button' class='btn btn-xs btn-link text-danger hidden-print' style='height:18px; padding:0px; margin:0px;' data-placement='top' data-toggle='modal' data-target='#exampleModal$b'><i class='lnr lnr-trash'></i></button></div></td></tr>");
							$n++;                   $b++;
						}
			echo" </tbody>
                  </table>
        <div class='clearfix'></div>
            </div>
                
        </div>";
    
		?>
            
            </div></div>
                </div>
                  
            
             <?php
             if($pr){
                 echo"<span class='pull-right text-right'>
             <a href='#' onclick='return window.print()' class='hidden-print' title='Print' data-toggle='tooltip' data-placement='top'><i class='lnr lnr-printer'></i></a> &nbsp;&nbsp;&nbsp;&nbsp; </span>";
             }
             ?>
      
   </div></div></div>  
   <?php
   include'footer.php';
   ?>
