<?php
if(basename($_SERVER['PHP_SELF']) == 'ductrepo.php') 
  $cm=" class='current'";
include'header.php';
include'connection.php';
$custo=$conde=$condi=$act='';
$dato=$datos=$Date;
$p=0;

// search for report to be displayed
if(isset($_POST['search']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$act=$_POST['act'];
			$p=1;
		}
	
	if($dato==$datos)
			$mpri="ON $dato";
		else
			$mpri="FROM $dato TO $datos";

			if($custo)
				$conde="AND `Plate`='$custo'";

			if($act)
				$condi="AND `Action`='$act'";
?>
<div class="container-fluid main-content">
        <div class="page-title hidden-print">
          <h3 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
         Trip Report
          </h3>
                 </div>
     
        <div class="row">
  <div class="col-lg-2 hidden-print">
   
  <ul class="list-group">
                  
			  <li class="list-group-item">
              <a href="triprepo.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Trip Report
                </p>
              </a></li>  

    <li class="list-group-item active">
	  <a href="ductrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Status Report
                </p>
              </a></li>  

    <li class="list-group-item">
	  <a href="disrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Dispatch Report
                </p>
              </a></li> 

    <li class="list-group-item">
	  <a href="arrirepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Departure Report
                </p>
              </a></li>  

    <li class="list-group-item">
	  <a href="mirepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Mileage Report
                </p>
              </a></li>

    <li class="list-group-item">
	  <a href="custorepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Recovery Report
                </p>
              </a></li> 

    <li class="list-group-item">
	  <a href="currerepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Currency Report
                </p>
              </a></li>   

    <li class="list-group-item">
	  <a href="payreport.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Payment Report
                </p>
              </a></li>    

    <li class="list-group-item">
	  <a href="debtors.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Debtors Report
                </p>
              </a></li>        

    <li class="list-group-item">
	  <a href="trepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Target  Report
                </p>
              </a></li>       

    <li class="list-group-item">
	  <a href="girepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;GPS Report
                </p>
              </a></li>     
                       
            </ul><br><br>
  </div>
                    
           
           
    <form action="" method="post" class="form-horizontal "> 
        <div class="col-lg-10">
                  <div class="row">

				  <div class="col-lg-3"> </div> 
				  
			<div class="col-lg-2"> <select class="form-control" name="act"><option value='' selected='selected'>Select Action</option>
			 <?php
			$doi=mysqli_query($conn, "SELECT `Action` FROM `trage` WHERE `Action`!='' GROUP BY `Action` ORDER BY `Action` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$acti=$roi['Action'];
				if($acti==$act)
					$sle="selected='selected'";
				else
					$sle='';
			echo"<option value='$acti' $sle> $acti </option>";
			}
			?>    
                            </select></div> 
                         
            <div class="col-lg-7 hidden-print"><div class="col-lg-3">
        <select class="form-control" name="custo"><option value='' selected='selected'>Select Vehicle</option>
			 <?php
			$doi=mysqli_query($conn, "SELECT `Plate` FROM `trage` WHERE `Plate`!='' GROUP BY `Plate` ORDER BY `Plate` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$drive=$roi['Plate'];
				if($drive==$custo)
					$sle="selected='selected'";
				else
					$sle='';
			echo"<option value='$drive' $sle> $drive </option>";
			}
			?>    
                            </select>
					   </div>
            <div class="col-lg-3"> 
           <div class="input-group date" data-provide="datepicker">
      <input class="form-control form-center" name="dato" type="text" value="<?php echo $dato ?>" onkeypress='return isNumberKey(event)' required>
	  <span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
			</div></div>


		  <div class="col-lg-3"> 
           <div class="input-group date" data-provide="datepicker">	
      <input class="form-control form-center" name="datos" type="text" value="<?php echo $datos ?>" onkeypress='return isNumberKey(event)' required>
	  <span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
              </div></div>                      
                       
                       <div class="col-lg-2">
                        <button class="btn  btn-primary btn-block" type="submit" name="search"><i class="lnr lnr-magnifier"></i> Search</button>
                   
					  </div>
                         </div> 
                      
                     
                  
            </form> 
             
               
            </div>
             <?php
				if($p)
$do=mysqli_query($conn, "SELECT *FROM `trage` WHERE `Date` BETWEEN '$dato' AND '$datos' $conde $condi ORDER BY `Number` ASC");
	else
$do=mysqli_query($conn, "SELECT *FROM (SELECT *FROM `trage` WHERE `Plate`!='' ORDER BY `Date` DESC LIMIT 15) SUB ORDER BY `Date` ASC");
if($fo=mysqli_num_rows($do)){
					?>
					<div class="divFooter"><center><u><b>DEDUCTION REPORT <?php echo"$mpri"; ?></b></u></center></div>
		 <div class="row">
            <div class="col-lg-12">
             <span> &nbsp;&nbsp; Total Records Found : <b><?php echo" $fo " ?></b></span>
			 <span class="pull-right">
			     &nbsp;&nbsp;<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a></span>
			     
			     <span class="pull-right hidden-print">
		&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="exporttable" class="hidden-print" title='Export to excell' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-line-spacing"></i></a></span>
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">

			   <table class="table table-striped table-hover" id="htmltable">     
                    <thead>
                    <tr role="row"><th width='3%'> No </th>
                    <th> Date </th><th> Time </th>
                    <th> User </th><th> Vehicle&nbsp;ID</th>  
                    <th> Action </th><th width='30%'> Description </th>
                     </tr></thead>
                        <tbody>
					<?php
					$n=1;				
	while($ro=mysqli_fetch_assoc($do)){
$code=$ro['Number'];
$user=$ro['User'];
$amo=$ro['Amount'];
$purpo=$ro['Descri'];
$dte=$ro['Date'];
$tme=$ro['Time'];
$pla=$ro['Plate'];
$act=$ro['Action'];

$stn="style='padding:1px;'";
           
print("<tr><td $stn class='text-right'>$n &nbsp;</td><td $stn> $dte </td>
<td $stn> $tme </td><td $stn> $user </td><td $stn> $pla </td>
<td $stn> $act </td><td $stn> $purpo </td></tr>");
		$n++;				$to+=$amo;            $tp+=$pa;          $tb+=$bal;
						}
	$to=number_format($to);
	$tp=number_format($tp);
	$tb=number_format($tb);
						?>
						
                    </tbody></table>
                                      
                
              </div>
            </div></div>
                  </div>                  
                <span class="pull-right hidden-print">
			 &nbsp;&nbsp;<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a></span>
			 
      
      	<?php
				}
				else{
						echo"<div class='row'>
            <div class='col-lg-12' style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Total Records Found : <b> 0 </b></span>
            <div class='widget-container fluid-height clearfix'>
            <div class='widget-content padded clearfix'>
			<br><br><br><br><br><br>
	<div style='text-align:center; font-size:24px; color:#ff9999'>Report not available on selected date </div><br><br><br><br><br><br>";
					}
			
					?>
   </div></div></div>  
   <?php
   include'footer.php';
   ?>